【问题标题】:Querying multiple index in django-sphinx在 django-sphinx 中查询多个索引
【发布时间】:2009-11-20 01:43:22
【问题描述】:

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 似乎不包含函数 query()。我还尝试在 django-sphinx 文档中提到的 sphinx.conf sql_query 配置中包含 content_type。没有任何效果。

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

谁能说明我如何从 sphinx 中的多个索引中获得排名结果

【问题讨论】:

    标签: django full-text-search django-sphinx


    【解决方案1】:

    你想使用SphinxQuerySet而不是SphinxSearch

    例如,如果我想查询三个索引,使用titletagscontent 字段对结果进行加权,并设置自定义匹配(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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-05-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-04
      • 1970-01-01
      • 2010-12-11
      相关资源
      最近更新 更多