领先的通配符在Lucene.NET中引发错误

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

If the search query contains a leading wildcard character (* or ?), the QueryParser's Parse function throws an error.

如果搜索查询包含前导通配符(*或?),则QueryParser的Parse函数会抛出错误。

Dim q As String = "*abc"
Dim qp As New QueryParser("text", New StandardAnalyzer())
Dim query As Query = qp.Parse(q)

Is there any way to solve this problem in Lucene.NET v2.0.0.4?

有没有办法在Lucene.NET v2.0.0.4中解决这个问题?

3 个解决方案

#1


Set QueryParser.SetAllowLeadingWildcard Method to true. The API page states that "this can produce very slow queries on big indexes" though.

将QueryParser.SetAllowLeadingWildcard方法设置为true。 API页面指出“这可能会对大型索引产生非常慢的查询”。

#2


Maybe you have to use a WildcardQuery, but

也许你必须使用WildcardQuery,但是

...In order to prevent extremely slow WildcardQueries, a Wildcard term should not start with one of the wildcards...

...为了防止极慢的WildcardQueries,通配符术语不应该以其中一个通配符开头......

#3


You can avoid wildcard queries by utilizing NGramFilter for your index analyzer. Than you have to use search_analyzer without NGramFilter. This way you can search similar to like "%text%" without even needing wildcards. You just enter 'abc' and your index would be searched for all entries containing 'abc' very quickly.

您可以通过将NGramFilter用于索引分析器来避免使用通配符查询。比没有NGramFilter你必须使用search_analyzer。通过这种方式,您甚至无需使用通配符即可搜索类似“%text%”的内容。您只需输入'abc'即可快速搜索包含'abc'的所有条目。

#1


Set QueryParser.SetAllowLeadingWildcard Method to true. The API page states that "this can produce very slow queries on big indexes" though.

将QueryParser.SetAllowLeadingWildcard方法设置为true。 API页面指出“这可能会对大型索引产生非常慢的查询”。

#2


Maybe you have to use a WildcardQuery, but

也许你必须使用WildcardQuery,但是

...In order to prevent extremely slow WildcardQueries, a Wildcard term should not start with one of the wildcards...

...为了防止极慢的WildcardQueries,通配符术语不应该以其中一个通配符开头......

#3


You can avoid wildcard queries by utilizing NGramFilter for your index analyzer. Than you have to use search_analyzer without NGramFilter. This way you can search similar to like "%text%" without even needing wildcards. You just enter 'abc' and your index would be searched for all entries containing 'abc' very quickly.

您可以通过将NGramFilter用于索引分析器来避免使用通配符查询。比没有NGramFilter你必须使用search_analyzer。通过这种方式,您甚至无需使用通配符即可搜索类似“%text%”的内容。您只需输入'abc'即可快速搜索包含'abc'的所有条目。