2009-11-20 89 views
1

django-sphinx文檔顯示django-sphinx圖層也支持對多個索引進行一些基本查詢。在django-sphinx中查詢多個索引

http://github.com/dcramer/django-sphinx/blob/master/README.rst

from djangosphinx.models import SphinxSearch 

SphinxSearch('index1 index2 index3').query('hello') 

看來SphinxSearch不包含函數查詢()。我還嘗試在sphinx.conf sql_query配置中包含content_type,如django-sphinx文檔中所述。沒有任何工作。

Traceback (most recent call last): 
    File "<console>", line 1, in <module> 
AttributeError: 'SphinxSearch' object has no attribute 'query' 

誰能扔光從多個索引,我怎麼能獲得排名結果在獅身人面像

回答

6

而不是使用SphinxSearch,要使用SphinxQuerySet

例如,如果我想查詢3索引,使用所述titletags,並content字段權衡的結果,並設置自定義匹配(SPH_MATCH_EXTENDED2)和排名(SPH_RANK_NONE)模式:

from djangosphinx.models import SphinxQuerySet 

search = SphinxQuerySet(
    index = "index_1 index_2 index_n", 
    weights = { 
     'title': 100, 
     'tags': 80, 
     'content': 20 
    }, 
    mode = 'SPH_MATCH_EXTENDED2', 
    rankmode = 'SPH_RANK_NONE') 

results = search.query('what is the answer to life, the universe, and everything?') 

for result in results: 
    print result 
+3

答案是42;) – nabizan 2011-02-04 09:35:17