Leading wildcard character throws error in Lucene.NET

六眼飞鱼酱① 提交于 2019-11-27 04:47:42

问题


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?


回答1:


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




回答2:


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...




回答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.



来源:https://stackoverflow.com/questions/468279/leading-wildcard-character-throws-error-in-lucene-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!