Lucene: indexwriterconfig settings

Source: Internet
Author: User

Lucene Series

The instance code is as follows:

1 Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_36);2 IndexWriterConfig iwconf = new IndexWriterConfig(Version.LUCENE_36, analyzer);3 iwconf.setOpenMode(IndexWriterConfig.OpenMode.CREATE);4 IndexWriter indexWriter = new IndexWriter(indexDir, iwconf);


Note: standardanalyzer is a built-in "Standard analyzer" in Lucene and can be used as follows:

  1. The original sentence is segmented by Space
  2. All uppercase letters can be converted to lowercase letters.
  3. You can remove useless words, such as "is", "the", "are", and delete all punctuation marks.


In ipve3.x, the initialization of the indexwriter instance is different from the previous versions. The indexwriterconfig class is required. In addition, we can see from the Lucene API that the latest constructor of the indexwriter class currently uses the indexwriterconfig class (Other constructor is not recommended and is discarded ), you need to set the openmode attribute:

1 iwconf. setopenmode (openmode. Create); 2 // or 3 iwconf. setopenmode (openmode. append); 4 // or 5 iwconf. setopenmode (openmode. create_or_append );


Note: This line of code sets the folder for storing the index to be created in overwrite or new mode. If this setting is not set and the index in the original index folder is not deleted, the new index file will be appended to the original index file, which leads to an index result error.



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.