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)
Related
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"...
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.
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.
For a project I implemented Haystack but now I was wondering what the pros and cons are of using Haystack over the ORM. For my project I need to find books by their title and isbn. I guess Haystack is more useful if you have to do full text searches or am I missing something?
Haystack is certainly better for full text search, and also provides a bunch of other benefits that you won't get using the ORM. Here are some from the Haystack site:
Spelling suggestions
Faceting
More like this
Highlighting
Search term boosting
Besides that, you should use Haystack over the ORM if you expect a high volume of searches, since you'll offload all that work from the DB (which should be focused on writing and retrieving your data).
http://haystacksearch.org/
The main advantage to use haystack over the ORM is performance. LIKE requests are just going to kill you database if you have 100 concurrent users searching. If you have MYSQL of course you can still use its full text capability, but it will still be slower than Xapian or Solr.
Plus you will have additional features such as fuzzy searching that user loves a lot.
It does comes with the extra work of setting up solr and maintaining it, so:
if your website is going to be small forever, like for small company intranet, don't bother and user ORM.
if you plan for the big bad Web, go Haystack.
And not forget to mention that doing a basic haystack setup isn't really much more work than doing a search view using Django's ORM.
Haystack is a module that enables easier search integrations for your django application
you can create something similiar to a ModelForm, called ModelIndex, in this new class you will be able to declare the searchable fields of your models and other settings
It has little to do with Django ORM (the orm is used to comunicate with your databases)
of course you can have the orm query your db models with the search pattern specified, but Haystack is a better choice for setting up a search engine easily on your website, so... if you have to enable complex searches on your site, just go with Haystack
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