Filtering with elastic-search and django - django

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.

Related

Advanced search in Django

I am working on a social blogging site using Django and I need to create an advanced search bar with filters like location and authors. I do have a basic one working as of now. Can someone help me with the concept on how to add filters to it. couldn't find much related stuff with django. Thanks
Assuming you want to retrieve data from a database, using the Django ORM, you can use the filter method of the Queryset class.
That said, we can't help you more without a context, how you expect the filters to behave, the models behind the scene, or anything more than "how to conceive an advanced search in Django"...

Add index settings to elastic search

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.

How to make a dropdown menu to search in different models in django

I am new to django and I made a search engine , I want to add a dropdown menu in the template where user can choose the model to search in. What to write in the template and what to write in views.py is there is any need for forms.py ????
thanks for help
There are 2 solutions.
You can hardcode your models and filter statements on them directly into your Django view. This is ok if queries are not complex and there is not a lot of models.
Or you need an abstraction - a search layer over your Django models. There is a lot of different search engines: solr, sphinx, elastic search. In your case this can be for example Sphinx Search with django-sphnix plugin - it can aggregate different data sources and make them available for search.

Django Admin Limiting results based on URL

I'm working a conference registration page. The system can allow multiple conferences to be registered for and used.
I'm using the admin to manage the conferences, but I need a way in the admin system to view only the people registered for a given conference. I know I can use list filters, but I was wondering if I can somehow use the URL.
For example, is it possible to do something like this? /admin/appname/modelname/SomeConference and only have that show the instances of that model associated with that confernece?
This is what filters are specifically for.
If you look at what happens when you activate a filter in the Admin, it just updates the URI to include a lookup value:
http://example.com/admin/core/model/?model_id__exact=1
So "technically", yes, there's a way to do this just using a URL.
Because that's how filters work in the first place.

Implementing filters in django for e-commerce website

I am implementing an e-commerce website using django. The product catalog will be big (hundreds of products). I would like to know how I should implement product filters in search.
E.g. let's say I put up about 30 products initially. The user might want to filter the search based on some product attributes like color, size, category, etc.
Is there any feature in django that enables building such features? If not, how should I go about it? Is querying the database everytime the user picks an attribute, the only approach?
Thanks.
I think you are looking for a faceted search.
Haystack should be the django app you are looking for.
Furthermore you could take a look at django-filter