我使用RamDirectory实现了搜索。该目录只填写一次,并从那里开始只读。
有时我得到错误我无法解释(见下文)。大多数时候他们说查询无法解析,但查询 venlo OR venlo * 看起来不错。
我也不理解Encountered " <TERM> "marburg "
的含义,因为marburg是索引中的值,但它不是查询的一部分......
Lucene.Net.QueryParsers.ParseException: Cannot parse 'venlo OR
venlo\*': Encountered " <TERM> "marburg "" at line 1, column 0. Was
expecting one of: <NOT> ... "+" ... "-" ... "(" ... "*" ... <QUOTED>
... <TERM> ... <PREFIXTERM> ...
此处解析nice~
System.ArgumentOutOfRangeException: Length cannot be less than zero.
Parameter name: length
at System.String.CtorCharArrayStartLength(Char[] value, Int32 startIndex, Int32 length)
at Lucene.Net.QueryParsers.FastCharStream.get_Image() in d:\Lucene.Net\FullRepo\trunk\src\core\QueryParser\FastCharStream.cs:line 107
at Lucene.Net.QueryParsers.QueryParserTokenManager.JjFillToken() in d:\Lucene.Net\FullRepo\trunk\src\core\QueryParser\QueryParserTokenManager.cs:line 1313
at Lucene.Net.QueryParsers.QueryParserTokenManager.GetNextToken() in d:\Lucene.Net\FullRepo\trunk\src\core\QueryParser\QueryParserTokenManager.cs:line 1388
at Lucene.Net.QueryParsers.QueryParser.Jj_ntk() in d:\Lucene.Net\FullRepo\trunk\src\core\QueryParser\QueryParser.cs:line 1929
at Lucene.Net.QueryParsers.QueryParser.Modifiers() in d:\Lucene.Net\FullRepo\trunk\src\core\QueryParser\QueryParser.cs:line 1248
at Lucene.Net.QueryParsers.QueryParser.Query(String field) in d:\Lucene.Net\FullRepo\trunk\src\core\QueryParser\QueryParser.cs:line 1300
at Lucene.Net.QueryParsers.QueryParser.Parse(String query) in d:\Lucene.Net\FullRepo\trunk\src\core\QueryParser\QueryParser.cs:line 224
at SR.BusPortal.Graph.Lucene.Cities.LuceneCityReader.ParseQuery(String searchQuery)
我的代码看起来像这样
private static Query ParseQuery(string searchQuery, Analyzer analyzer)
{
var parser = new MultiFieldQueryParser(global::Lucene.Net.Util.Version.LUCENE_30, new[] { "SimpleName", "SimpleNativeName" }, analyzer)
{
FuzzyMinSim = 0.3f,
AllowLeadingWildcard = false,
MultiTermRewriteMethod = MultiTermQuery.SCORING_BOOLEAN_QUERY_REWRITE
};
Query query;
try
{
query = parser.Parse(searchQuery.Trim());
}
catch (Exception)
{
query = parser.Parse(QueryParser.Escape(searchQuery.Trim()));
}
return query;
}
作为输入,该方法获得 venlo或venlo * 和SimpleAnalyzer