简体   繁体   中英

search on non analyzed field using lucene

I am trying to search using Apache Lucene index. For it i have created Lucene index on a field filepath which is showing the path and it is not analyzed .

Now i am not able to search on the non analyzed field . Is it possible to search on non analyzed field . or is there any way to stop the splitting of the words to be store while analyzed.

You're able to search for non-analyzed field query but there will be a match only in case of field value being completely equals to search term. As mindas mentioned - phrase query should be used for that.

In case you want to search for that field, you'd need to reindex your documents with that field being analyzed.

You can try using existing Analyzers / Tokenizers (ie set StandardAnalyzer when creating IndexWriter, for example) or implement your own one that will split file path into tokens using file separator as delimiter.

In case you're interested, there's Solr's PathHierarchyTokenizerFactory that already splits some hierarchical path into tokens before storing then to index and that makes file path search much easier.

Is it possible to search on non analyzed field

In order to search non-analyzed fields, you need to use phrase query .

or is there any way to stop the splitting of the words to be store while analyzed

Sorry, I don't get this. If a field is not analyzed, it is neither split and stored as is. Can you clarify your question?

Yes, you can replace standardAnalyzer by others like KeywordAnalyzer in IndexSearcher config. It will treat the field as one term for search.

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