编程语言
首页 > 编程语言> > python – Haystack飞快移动索引一切

python – Haystack飞快移动索引一切

作者:互联网

我正在使用Haystack v1.0和Whoosh v1.8.1为我的网站构建自定义搜索引擎.一切都很好,但问题是我的索引模型中的很多条目都没有结果.

对于例如 – 我有四个注册模特 – 会员,嘉宾,活动,赞助商.在从django shell重建索引时,会发生以下情况:

./manage.py rebuild_index

Indexing 26 members.  
Indexing 3 events.
Indexing <x> guests.  
Indexing <y> sponsors.  

但是在运行SearchQuery API命令以及搜索搜索页面时,我无法搜索一半的成员名称.我没想到的是,当我可以搜索14-15名成员时,为什么不搜索其他成员.我的模板* _text.txt *文件应该是正确的,因为有一半的成员正确索引.

你可以试试这个
http://www.edciitr.com/search/?q=x
x = Vikesh返回1个结果(如预期的那样)
x = Akshit没有返回结果(问题!)

两个值’Akshit’和’Vikesh’都存在于rebuild_index之前.这是我要搜索的所有26个成员的列表 – http://www.edciitr.com/contact/

解决方法:

好的,所以这就是我所做的,以确定问题是在Whoosh还是Haystack.我打开了django shell并搜索了在haystack SearchQuery API搜索中没有显示的术语:

./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'   

所以你看,Whoosh正确索引所有数据.所以,现在我尝试使用SearchQuery API

./manage.py shell
 $>> from haystack.query import SearchQuerySet
 $>> sqs = SearchQuerySet().filter(content='akshit')
 $>> sqs
 $>> []

所以,我意识到我必须查看haystack库的whoosh_backend.py文件,看看发生了什么.打开 – 在第345行附近的haystack.backends.whoosh_backend

'''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)

#if narrowed_results:
      #raw_results.filter(narrowed_results)

然后它的工作原理. SearchQueryAPI按预期返回测试查询的一个结果.网络搜索工作,但我想知道这里干草堆有什么问题.

标签:python,django,django-haystack,whoosh
来源: https://codeday.me/bug/20190630/1339568.html