Advanced Xapian features

Djapian takes advantage of some of the advanced Xapian features in easy and convenient ways. For example, we can use the Xapian spell checker simply by chaining a method call to the end of our search operation:

results = product_indexer.search("cranberri sauce").spell_correction()

This will instruct Xapian to try and correct out spelling errors in the query string. To find out what Xapian decided to use, call get_corrected_query_string on the results object:

>>> results.get_corrected_query_string()
cranberry sauce

Xapian also supports word stemming, as we discussed in the section on Sphinx. This normalizes word variations to a single form in attempt to improve search results. Activating the Xapian stemming function using Djapian is extremely easy, just add a DJAPIAN_STEMMING_LANG setting to your project settings file and set it to the language of your choice. For English, use:

DJAPIAN_STEMMING_LANG = "en"

As you can see, Djapian does an excellent job of integrating with the Xapian open source search engine library. It offers yet another powerful tool for adding search to any Django project.

We should also note that the Xapian search engine can also be used with Haystack and all of the discussion of Haystack in previous sections applies, whether the backend uses Whoosh or Xapian. Xapian's advantage over Whoosh is primarily that it's written in C++ instead of Python. This means, generally, that it should be some degree faster. This sort of metric, however, is dependent on a lot of factors and should not discourage you from working with Whoosh or other Python search engines.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset