在django-sphinx中查询多个索引

sau*_*abh 1 django full-text-search 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')
Run Code Online (Sandbox Code Playgroud)

似乎SphinxSearch不包含函数query().我还尝试在spinx.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'
Run Code Online (Sandbox Code Playgroud)

任何人都可以了解如何从sphinx中的多个索引中获得排名结果

Car*_*son 6

而不是使用SphinxSearch,你想使用SphinxQuerySet

例如,如果我想查询三个指标,用称量的结果title,tagscontent领域,并设置自定义匹配(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
Run Code Online (Sandbox Code Playgroud)

  • 答案是42;) (3认同)