如何使用本机Lucene查询语法?

时间:2022-02-28 03:10:19

I read that Lucene has an internal query language where one specifies : and you make combinations of these using boolean operators. I read all about it on their website and it works just fine in LUKE, I can do things like

我读到Lucene有一个内部查询语言,其中一个指定:并使用布尔运算符组合这些语言。我在他们的网站上阅读了所有关于它的内容,它在LUKE中运行得很好,我可以做类似的事情

field1:value1 AND field2:value2 

and it will return seemingly correct results.

它会返回看似正确的结果。

My problem is how do I pass this who Lucene query into the API? I've seen QueryParser, but I have to specifiy a field. Does this mean I still have to manually parse my input string, fields, values, parenthesis, etc or is there a way to feed the whole thing in and let lucene do it's thing?

我的问题是如何通过这个Lucene查询到API的人?我见过QueryParser,但我必须指定一个字段。这是否意味着我仍然需要手动解析我的输入字符串,字段,值,括号等,或者有没有办法提供整个事情并让lucene做它的事情?

I'm using Lucene.NET but since it's a method by method port of the orignal java, any advice is appreciated.

我正在使用Lucene.NET,但因为它是orignal java的方法端口的方法,所以任何建议都值得赞赏。

1 个解决方案

#1


Are you asking whether you need to force your user to enter the field? If so, the query parser has a default field. Here's a little more info. As long as you have a default field that will do the job, they don't need to specify fields.

您是否在询问是否需要强制用户进入该字段?如果是,则查询解析器具有默认字段。这里有更多信息。只要您有一个可以完成工作的默认字段,它们就不需要指定字段。

If you're asking how to get a Query object from the String, you need the parse method. It understands about fields, and the default field, etc. mentioned earlier. You just need to make sure that the query parser and the index builder are both using the same analysis.

如果您正在询问如何从String中获取Query对象,则需要使用parse方法。它了解前面提到的字段和默认字段等。您只需要确保查询解析器和索引构建器都使用相同的分析。

#1


Are you asking whether you need to force your user to enter the field? If so, the query parser has a default field. Here's a little more info. As long as you have a default field that will do the job, they don't need to specify fields.

您是否在询问是否需要强制用户进入该字段?如果是,则查询解析器具有默认字段。这里有更多信息。只要您有一个可以完成工作的默认字段,它们就不需要指定字段。

If you're asking how to get a Query object from the String, you need the parse method. It understands about fields, and the default field, etc. mentioned earlier. You just need to make sure that the query parser and the index builder are both using the same analysis.

如果您正在询问如何从String中获取Query对象,则需要使用parse方法。它了解前面提到的字段和默认字段等。您只需要确保查询解析器和索引构建器都使用相同的分析。