开发者

StandardAnalyzer, BackSlash and Lucene.net

开发者 https://www.devze.com 2023-02-21 01:30 出处:网络
I\'m using Lucene.Net 2.9.2.I use StandardAnalyzer with customized stop words list that just including english stop words.My data includes folder path like\"questions\\text\\testing data\". It\'s ok w

I'm using Lucene.Net 2.9.2.I use StandardAnalyzer with customized stop words list that just including english stop words.My data includes folder path like"questions\text\testing data". It's ok when indexing and searching for that folder path. However, I'm using QueryPaser and make query using with Standard Analyzer with the same in indexing. The query parser strips out backslash and change lower case. So I used escape character '\',it does not work.The following are my testing code.

QueryParser queryParser=new QueryParser("",new StandardAnalyzer(STOP_WORDS)); Query query=queryParser.Parse("+Field1:questions\text\testing data +(Field2:good)");

The query syntax change "+Field1:"questionstexttesting" data+(Field2:good".

folder path=questions\text\testing data search text =good

In my application,I could not know which fields will come to search. Firstly, I search that a word and save the search with lucene que开发者_JAVA百科ry syntax. Later I reuse the search and pass with QueryParser. Thank in advance for any advice!


Index your paths using KeywordAnalyzer, and your data using StandardAnalyzer. You can do this using the PerFieldAnalyzerWrapper.

Build your search query using a BooleanQuery, add a PrefixQuery for your path, and use QueryParser for the user provided search string.

var query = new BooleanQuery();
query.Add(new PrefixQuery("Path", "questions\\text\\testing\\"), BooleanClause.Occur.MUST);

var analyzer = new StandardAnalyzer(STOP_WORDS);
var queryParser = new QueryParser("Data", analyzer);
var parsedQuery = queryParser.Parse("data +Field2:good");
query.Add(parsedQuery, BooleanClause.Occur.MUST);

Change your search interface so that the user never needs to manually input paths.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号