Ok, so here is what I did to find out if there is a problem in Whoosh or Haystack. I opened the django shell and searched for a term that didn't appear in search searches in Search Hackstack SearchQuery:
./manage.py shell $>> import whoosh $>> from whoosh.query import * $>> from whoosh.index import open_dir $>> ix = open_dir('/home/somedir/my_project/haystack/whoosh/') $>> ix.schema <Schema: ['branch', 'category', 'coordinator', 'date_event', 'designation','details', 'django_ct', 'django_id'> 'name', 'organisation', 'overview','text', 'title']> $>> searcher = ix.searcher() $>> res = searcher.search(Term('text',u'akshit')) $>> print res <Top 1 Results for Term('text', 'akshit') runtime=0.000741004943848> $>> print res['0']['name'] u'Akshit Khurana'
So, you see, Whoosh indexes all the data correctly. So now I'm trying the SearchQuery API
./manage.py shell $>> from haystack.query import SearchQuerySet $>> sqs = SearchQuerySet().filter(content='akshit') $>> sqs $>> []
So, I understand that I have to check the whoosh_backend.py file of the haystack library to see what happens. Open - haystack.backends.whoosh_backend around line number 345
'''Uncomment these two lines because the raw_results set becomes empty after the filter call for some queries'' if narrowed_results: raw_results.filter(narrowed_results)
to
#if narrowed_results: #raw_results.filter(narrowed_results)
And then it works. SearchQueryAPI returns exactly one result for a test query, as expected. Internet browsing works, but I would like to know that the problem with haystack is here.
source share