2👍
I’ve had the same problem the past couple of days (nice timing). I decided to start where you left off and see if I couldn’t isolate the cause a bit better.
The narrowed results are (at least partially) generated by a query of the models which are registered to the site (L298 and on). For my code, the query it generates is…
django_ct:(barnaby.tag OR barnaby.userprofile)
…which gives a resultset with only barnaby.tag models. However, if I run…
django_ct:(barnaby.tag OR barnaby.userprofile) (username:pfrazee OR name:Tag114)
…I end up getting results from both tag and userprofile. I can only assume that’s a problem with Whoosh, but I can’t say for sure. We should probably contact Haystack and/or Whoosh about it.
At any rate, you can avoid this problem without altering haystack by setting this:
HAYSTACK_LIMIT_TO_REGISTERED_MODELS = False
1👍
Okay, so here’s what I did to find out whether the problem is in Whoosh or Haystack. I opened the django shell and performed a search for the term that was not showing up in haystack SearchQuery API search:
./manage.py shell
$>> import whoosh
$>> from whoosh.query import *
$>> from whoosh.index import open_dir
$>> ix.schema
<Schema: ['branch', 'category', 'coordinator', 'date_event', 'designation','details', 'django_ct', 'django_id'> 'name', 'organisation', 'overview','text', 'title']>
$>> ix = open_dir('/home/somedir/my_project/haystack/whoosh/')
$>> searcher = ix.searcher()
$>> res = ix.search(Term('text',u'pink'))
$>> print res
<Top 1 Results for Term('text', 'pink') runtime=0.000741004943848>
$>> print res['0']['name']
u'Pink Floyd'
So you see, Whoosh is correctly indexing all data. So, now I try the SearchQuery API
./manage.py shell
$>> from haystack.query import SearchQuerySet
$>> sqs = SearchQuerySet().filter(content='pink')
$>> sqs
$>> []
So, I realize that I must check out the whoosh_backend.py file of the haystack library to see what’s happening. Open – haystack.backends.whoosh_backend around line number 345
'''Comment 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 returning exactly one result for the test query as expected. Web search working. Time for sweet sleep, though I would like to know what’s the issue with haystack here.
- [Django]-Django 1.9.4 template inheritance does not work
- [Django]-Django getting foreign-key object list