简体   繁体   中英

Use multiple Analyzers on same field - Apache Lucene

I'm using apache lucene 6.3.0 and I want to index my field 'file_name' using 2 Analyzers:
1. StandardAnalyzer (to allow search using terms)
2. KeywordAnalyzer (to preserve the original name also, just in case if the user searches the entire name)

Please note that this can be achieved using search time input analysis but I want to avoid adding that complexity on the search front of my app.

You can't, so you'll either have to:

  • Have two fields with different processing and use copyField to index the same content into both fields, but process it differently (this is useful to also score exact hits higher than those that has been processed by the StandardTokenizer)
  • Use the KeywordTokenizer together with a WordDelimiter(Graph)Filter and set preserveOriginal to true.

The first will allow you to prioritize fields differently, but will require you to include both fields when querying. The latter will have all the data in a single field, but won't allow you to score them differently.

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