Google App Engine搜索API

Bri*_*unt 6 python google-app-engine gae-search

GAE Search 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),
   ])
Run Code Online (Sandbox Code Playgroud)

如果可能的话,如何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.
Run Code Online (Sandbox Code Playgroud)

小智 3

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

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