简体   繁体   中英

Lucene Field.Store.YES versus Field.Store.NO

Will someone please explain under what circumstance I may use Field.Store.NO instead of Field.Store.YES ? I am extremely new to Lucene. And I am trying to create a document. Per my basic knowledge, I am doing

doc.add(new StringField(fieldNameA,fieldValueA,Field.Store.YES));
doc.add(new TextField(fieldNameB,fieldValueB,Field.Store.YES));

There are two basic ways a document can be written into Lucene.

  • Indexed - The field is analyzed and indexed, and can be searched.
  • Stored - The field's full text is stored and will be returned with search results.

If a document is indexed but not stored, you can search for it, but it won't be returned with search results.

One reasonably common pattern is to use lucene for search, but only have an ID field being stored which can be used to retrieve the full contents of the document/record from, for instance, a SQL database, a file system, or an web resource.

You might also opt not to store a field when that field is just a search tool, but you wouldn't display it to the user, such as a soundex/metaphone, or an alternate analysis of a content field.

Use Field.Store.YES when you need a document back from Lucene document. Use NO when you just need a search from document. Here is a link explained with a scenario. https://handyopinion.com/java-lucene-saving-fields-or-not/

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