[英]Lucene not searching for word having '-'
I am using Standard Analyzer to store text as well same analyzer for searching 我正在使用标准分析器来存储文本以及用于搜索的相同分析器
Here is a code for searching text: 这是用于搜索文本的代码:
Analyzer analyzer = GetAnalyzer();
QueryParser parser = new QueryParser("Text", analyzer);
parser.SetAllowLeadingWildcard(true);
Query query;
query = parser.Parse(finalSearch);
Hits hits = searcher.Search(query);
And Here is a code How I am storing Text: 这是我存储文本的代码:
fieldText = new Field("Text", text.ToLower(), Field.Store.YES, Field.Index.TOKENIZED);
document.Add(fieldText);
Try escaping your characters using '\\'
. 尝试使用
'\\'
转义字符。 '-'
will be '\\-'
. '-'
将为'\\-'
。
From http://lucene.apache.org/java/2_9_1/queryparsersyntax.html#Escaping%20Special%20Characters 来自http://lucene.apache.org/java/2_9_1/queryparsersyntax.html#Escaping%20Special%20Characters
Lucene supports escaping special characters that are part of the query syntax. Lucene支持转义查询语法中包含的特殊字符。 The current list special characters are
当前列表的特殊字符是
+ - && || ! ( ) { } [ ] ^ " ~ * ? : \
To escape these character use the \\ before the character. 要转义这些字符,请在字符前使用\\。 For example to search for (1+1):2 use the query:
例如,要搜索(1 + 1):2,请使用查询:
\(1\+1\)\:2
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.