Django: Haystack or ORM - django

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

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"...

How to setup rethinkdb with django?

I have followed various posts and tutorials but couldn't find anything that is relevant. I found a ORM for rethinkdb "https://github.com/dparlevliet/rwrapper" but don't know how to use it?
I am new to to django and python.
It depends on what you want to do.
There is no way to simple replacement of Django's ORM with RethinkDB now. However, working with RethinkDB driver is simple enough, and similar to how you would use Django ORM.
The nearest thing is indeed rwrapper, you can try starting with this tutorial.
If you don't need to use Model classes, then you just need to find a place to connect to database (or use some sort of Singleton or Factory to connect to the database), and then just import rethinkdb as r and r.connect() and then just write queries with ReQL.
If you need realtime data, then Django is not suitable for that at all. You can consider mixing Django with Tornado
Django doesn't support RethinkDB at the moment and I don't think there's any plan for it as well.
Django developers don't add new stuff to the code base just because it's something new and might be cool. It should be really well mature and a high needs for it. So, I don't think you'll be hearing anything about RethinkDB from Django devs anytime soon.
This project might be something interesting:
https://github.com/thejsj/django-and-rethinkdb
In order to use any database with Django, the adapter should completely be a Django DB Backend in order to work with:
Models
Admin
Forms
Various Class Based Forms
Session
Auth
etc...
In others words, as long as the db backend doesn't support all the django database operations is not something that you wanna use.

Django Admin Search optimization

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/

Django Integration with SOLR and NUTCH

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

Django - It is possible to use Haystack with custom SQL directly

I'm in the process of choosing a Framework for a new project. I have basically the database schema developed(I have this schema running in other PHP webapps already).
In this project I will need to basically search the database schema with Solr. The database schema is a little bit complex to define models in Django, so I think the only option I have is to execute SQL directly... my doubt is about Haystack/Solr... It is possible to query Haystack/Solr when I have no Django Models defined?
PS: I'm new to Django, I have never userd Haystack.
Haystack is pretty tightly coupled to the Django ORM. If you're not using Django models, I don't think Haystack is suitable. I've only used Haystack briefly, so I might wrong.
From the Haystack docs:
When should I not be using Haystack?
Non-Model-based data. If you just want to index random data (flat files, alternate sources, etc.), Haystack isn’t a good solution. Haystack is very Model-based and doesn’t work well outside of that use case.
I never used haystack, but you can always perform raw sql queries.
Have a look on documentation:
https://docs.djangoproject.com/en/dev/topics/db/sql/#executing-custom-sql-directly