简体   繁体   中英

How to search GUID using lucene.net

I am using lucene.net (LUCENE_30) in that I want to search categories which is in GUID format but not able to search that via using lucene searchresult.

Could we search GUID using lucene search?

My code look like this where maxResult = 10000;

QueryParser parser = new QueryParser(version, "IDTag", analyzer);
termQuery = parser.Parse(strIDTag);// where I am passing GUID value
TopDocs topDocs = searcher.Search(termQuery, maxResults);

After this in topDocs I am getting zero hits. What type of search query could I use, I have used QueryParser, BooleanQuery, TermQuery. Could anyone help me on this?

There is not a problem indexing and searching GUID fields in Lucene. The only thing you need to ensure is that you are not processing your query through the analyser if you actually indexed the field with the NOT_ANALYZED option.

As you are using the Standard Analyzer the only change to the field when indexing would be to change any text in the GUID to lower case (if for some reason it isn't already in lower case).

My recommendation would be to set the GUID field not be Analysed, and then use a TermQuery instead of parsing.

If you want a more informed answer you really need to supply the code you have used to index the GUID, and what your GUID's actually look like.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM