在PY-whoosh全文搜索引擎中,如何创建查询来查找范围中的值?

2024-04-29 09:07:55 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试按特定范围内的值查找文档。 官方文档没有给出不同类型字段和搜索方法的示例。 任何一个聪明的家伙能给我一个更多的例子和应用程序的链接?有什么提示吗?你知道吗

谢谢你!你知道吗

这是我的密码

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])

Tags: infrom文档import类型官方schemacreate
1条回答
网友
1楼 · 发布于 2024-04-29 09:07:55

范围查询语法是[START to END],例如STARTEND是表示范围边界的数字。[ START to]如果没有定义结束。[to END]如果没有定义开始。你知道吗

在您的情况下,对于大于20.0的温度,使用temperature:[20.0 to]因为to]之间没有空格。你知道吗

 query = QueryParser("temperature", ix.schema).parse("temperature:[ 20 to 1000 ]")

也可以使用^{}

class whoosh.query.NumericRange (fieldname, start, end, startexcl=False, endexcl=False, boost=1.0, constantscore=True)

query = NumericRange(u'temperature', 20.0, None)

参考号:Query lang - Ranges

相关问题 更多 >