How do I add index settings to haystack with elastic backend, like this guy has added in the question?
django-haystack autocomplete returns too wide results
My ngram search is returning all the docs. When I rebuild my index the mapping is automatically taken from the model.
I found an answer. This link can help in creating custom elastic search settings : https://wellfire.co/learn/custom-haystack-elasticsearch-backend/
You have to inherit ElasticsearchSearchBackend to make a new CustomElasticsearchBackend and set the custom elasticsearch settings dict in the init of that class.
There can be a lot more that can be done using the same idea. Like making the build_schema function to work differently. Also the Fields of haystack like CharField, NgramField, EdgeNgramField can be inherited to make custom fields to work for you.
Related
I've configured elastic search within my django project. The next step is to apply some filtering options of those searches. The content of each search is Cars, so I'd like to be able to filter on Model, Price, Petrol/Diesel etc.
Any thoughts on how to achieve this?
Thanks,
EDIT: I'm using Haystack.
I'm using aldryn-search on my Django CMS site. One of my custom plugins has a ManyToMany field to Django groups, to indicate which user groups may see the plugin (and of course the child plugins). I'm considering this field in the render() method of the plugin.
This works fine on the page, but I can't find a way to prevent the regarding plugins from being indexed by the search (which is Elastic Search). Any idea?
So to exclude the plugin from being searched completely.
You can set search_fulltext = False in your plugin class or plugin model.
To exclude the plugin only from users who do not have access to it is a bit more work but is not too complex.
You would have to create a dedicated index class for this plugin and deactivate it from cms page search as shown below.
Then in the dedicated plugin index class, add a MultiValueField to hold a list of user ids that can see this plugin, note that you'll have to make sure to only index plugins that have a page attached to them plugins.filter(placeholder__page__isnull=False) and also only plugins whose page is published and public.
After finishing the index class/logic, if using solr, then update schema to reflect new field.
Rebuild the index.
Here's an example on how the query could look like:
if request.user.is_authenticated():
SearchQueryset().models(PluginClass).filter(allowed_user_ids=request.user.pk)
Let me know how it goes :)
I have a CMS running on Django 1.4 and the database is Postgresql 9.1. I have a lot of content in the CMS and the issue I am facing right now is that the Django Admin search takes forever to retrieve the results. I would like to know if there are options to optimize this behavior of Django Admin search. I know that Django uses LIKE query on Postgresql for doing lookups. I know that Postgresql 9.1 has the GIN and GIST Index which could help to speed up this behavior of Django. I can also modify this search behavior to make it fast and compromise a little on the quality of search results. I would like to know the most optimum approach to optimize this search behavior of Django?
You might want to use the Django Debug toolbar to check which SQL queries are actually slow.
We found that Django admin's implicit use of UPPER resulted in Postgres ignoring all the existing indices. If that's the problem you could create an index on the uppercase representation of your data.
If you do not want to alter Django, profile the search query and add appropriate GIN and GIST indexes. Otherwise, you may want to look at integrating something like Haystack to power the search a bit faster and without tying up your database.
Helpful Links
http://www.rossp.org/blog/2009/jan/28/django-postgresql-fulltext/
I am using SOLR with NUTCH
I have successfully configure both and Solr is giving me the desired results
Now i want to integrate this in my Django project
Can anyone suggest me how to do it ...
it depends on what you need:
IF YOUR SOLR INSTANCE IS BOUND TO THE DJANGO'S MODEL
you probably are looking for django-haystack: it's pretty easy to setup and to use inside your django views, but it's not suited for huge amount of data
IF YOU'RE USING SOLR WITHOUT ANY RELATION TO DJANGO MODELS
this means that your results are retrieved as pure array, and you just need a python interface to solr. you have some choices
pysolr
solrpy
sunburnt (i'm using this)
you have to try them out and find out which one satisfies you more (check their websites too, to see if the project is mantained. also, stumble into their source code, to check if there's all you need). being a python interface implies that you have to do a little bit more of work inside your views
i hope this can help you
I want to build a gmail style search app for my site with configurable operators and entities. For example, gmail lets you type from: and then searches your email records by the from attribute. I want to do the same, but with e.g. ticket milestones or product descriptions, etc.
Any suggestions on how to get started? Should I try to leverage an existing project like django-haystack? Or should I try rolling my own, using more basic django features?
This would be fairly easy to implement in haystack - SearchQuerySets have a filter method much the same as django's querysets which you could use to filter on your custom parameters. Have a look at the searchqueryset docs for more.
To actually build the app, I'd write a custom SearchForm which parses parameter:value parts out of the query value, uses them to filter or search on the relevant attribute, and then uses any remaining keywords to search as per normal on the filtered searchqueryset (using SearchQuerySet.auto_query)