Leading wildcard character throws error in Lucene.

2019-01-15 16:01发布

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

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?

3条回答
我命由我不由天
2楼-- · 2019-01-15 16:40

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

查看更多
看我几分像从前
3楼-- · 2019-01-15 16:46

Maybe you have to use a WildcardQuery, but

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

查看更多
三岁会撩人
4楼-- · 2019-01-15 16:47

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.

查看更多
登录 后发表回答