当查询GAE搜索API版本中的搜索索引时,搜索具有与标题匹配的文档的项目的最佳做法是什么,然后搜索单词匹配正文的文档?
例如:
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的索引执行搜索,并以此优先级返回结果,其中搜索的短语位于变量qs中。
title与qs匹配的文档;然后qs单词匹配的文档。似乎正确的解决方案是使用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.发布于 2013-12-19 17:15:46
自定义评分是我们最优先的功能要求之一。我们希望尽快找到一种好办法来做这类事情。
在特定情况下,您当然可以通过执行两个单独的查询来达到预期的结果:第一个查询对"title“有字段限制,第二个查询限制在"body”上。
https://stackoverflow.com/questions/20659188
复制相似问题