我试图按特定范围内的值查找文档。官方文档没有提供不同类型的字段和搜索方法的示例。有什么聪明的人可以给我链接更多示例和应用程序吗?有什么提示吗?
谢谢!
这是我的密码,
from whoosh.index import create_in
from whoosh.fields import *
from whoosh.qparser import QueryParser
schema = Schema(temperature=NUMERIC(float, stored=True))
ix = create_in("indexdir", schema)
writer = ix.writer()
writer.add_document(temperature = 32.3)
writer.commit()
with ix.searcher() as searcher:
query = QueryParser("temperature", ix.schema).parse("temperature:>20.0") ## should be something like this
print(searcher.search(query)[0])
范围查询语法[START to END]
例如START
和END
是表示范围界限的数字。[ START to]
如果没有定义终点。[to END]
如果未定义开始。
如果您的温度高于20.0,请使用temperature:[20.0 to]
。carto
和之间没有空格]
。
query = QueryParser("temperature", ix.schema).parse("temperature:[ 20 to 1000 ]")
您也可以使用whoosh.query.NumericRange
:
类whoosh.query.NumericRange(字段名称,开始,结束,startexcl = False,endexcl = False,boost = 1.0,constantscore = True)
query = NumericRange(u'temperature', 20.0, None)
参考:查询语言-范围
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句