干草堆飞快移动索引一切

时间:2011-04-04 19:04:46

标签: python django django-haystack whoosh


我正在使用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 不会返回任何结果(问题!)

在rebuild_index之前,两个值'Akshit'和'Vikesh'都存在。以下是我要搜索的所有26个成员的列表 - http://www.edciitr.com/contact/

2 个答案:

答案 0 :(得分:3)

好的,所以这就是我所做的,以确定问题是在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文件,看看发生了什么。打开 - 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)

#if narrowed_results:
      #raw_results.filter(narrowed_results)

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

答案 1 :(得分:0)

我有类似的症状,这是我问Django django-haystack cannot import CategoryBase from django-categories on the first run

的问题

也可能与您的问题有关。

相关问题