6

GAE 搜索 API的 Python 版本中查询搜索索引时,首先搜索单词与标题匹配的文档,然后搜索单词与正文匹配的文档的最佳实践是什么?

例如给出:

body = """This is the body of the document, 
with a set of words"""

my_document = search.Document(
  fields=[
    search.TextField(name='title', value='A Set Of Words'),
    search.TextField(name='body', value=body),
   ])

如果可能,如何Document对上述形式的 s 的索引执行搜索,并以该优先级返回结果,其中要搜索的短语在变量中qs

  1. 与;title匹配的文档 qs然后
  2. qs正文与单词匹配的文档。

似乎正确的解决方案是使用 a MatchScorer,但我可能对此不以为然,因为我以前没有使用过此搜索功能。从文档中不清楚如何使用MatchScorer.

这里有什么我遗漏的东西,还是这是正确的策略?我错过了记录这类事情的地方吗?


为了清楚起见,这里是一个更详细的期望结果示例:

documents = [
  dict(title="Alpha", body="A"),          # "Alpha"
  dict(title="Beta", body="B Two"),       # "Beta"
  dict(title="Alpha Two", body="A"),      # "Alpha2"
]

for doc in documents: 
  search.Document(
    fields=[
       search.TextField(name="title", value=doc.title),
       search.TextField(name="body", value=doc.body),
    ]
  )
  index.put(doc)  # for some search.Index

# Then when we search, we search the Title and Body.
index.search("Alpha")
# returns [Alpha, Alpha2]

# Results where the search is found in the Title are given higher weight.
index.search("Two")
# returns [Alpha2, Beta]  -- note Alpha2 has 'Two' in the title.
4

1 回答 1

3

自定义评分是我们最优先的功能请求之一。我们希望尽快有一个好的方法来做这种事情。

在您的特定情况下,您当然可以通过执行两个单独的查询来获得所需的结果:第一个查询对“标题”有字段限制,第二个对“正文”进行限制。

于 2013-12-19T17:15:46.490 回答