【发布时间】:2010-11-09 09:00:01
【问题描述】:
通常当我们搜索时,我们有一个故事列表,我们提供一个搜索字符串,并期望返回一个给定搜索字符串与故事匹配的结果列表。
我想做的恰恰相反。给出一个搜索字符串列表和一个故事,然后找出与该故事匹配的搜索字符串。
现在这可以通过 re 完成,但这里的情况是我想使用 solr 支持的复杂搜索查询。 query syntax here 的完整详细信息。注意:我不会使用 boost。
基本上我想在下面的示例代码中为 doitmatch 函数获取一些指针。
def doesitmatch(contents, searchstring):
"""
returns result of searching contents for searchstring (True or False)
"""
???????
???????
story = "big chunk of story 200 to 1000 words long"
searchstrings = ['sajal' , 'sajal AND "is a jerk"' , 'sajal kayan' , 'sajal AND (kayan OR bangkok OR Thailand OR ( webmaster AND python))' , 'bangkok']
matches = [[searchstr] for searchstr in searchstrings if doesitmatch(story, searchstr) ]
编辑:另外还想知道是否有任何模块可以将如下所示的 lucene 查询转换为正则表达式:
sajal AND (kayan OR bangkok OR Thailand OR ( webmaster AND python) OR "is a jerk")
【问题讨论】: