Last active
December 14, 2015 16:18
-
-
Save zzzfree/5113692 to your computer and use it in GitHub Desktop.
Lucene Add
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.apache.lucene.analysis.Analyzer | |
import org.apache.lucene.analysis.standard.StandardAnalyzer | |
import org.apache.lucene.document.Document | |
import org.apache.lucene.document.Field | |
import org.apache.lucene.document.LongField | |
import org.apache.lucene.document.StringField | |
import org.apache.lucene.document.TextField | |
import org.apache.lucene.index.IndexWriter | |
import org.apache.lucene.index.IndexWriterConfig | |
import org.apache.lucene.index.Term | |
import org.apache.lucene.store.Directory | |
import org.apache.lucene.store.FSDirectory; | |
import org.apache.lucene.util.Version; | |
import org.apache.lucene.index.IndexWriterConfig.OpenMode; | |
Directory dir = FSDirectory.open(new File("./db")); | |
Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_41); | |
IndexWriterConfig iwc = new IndexWriterConfig(Version.LUCENE_41, analyzer); | |
iwc.setOpenMode(OpenMode.CREATE_OR_APPEND); | |
// iwc.setRAMBufferSizeMB(256.0); | |
IndexWriter writer = new IndexWriter(dir, iwc); | |
Document doc = new Document(); | |
Field pathField = new StringField("path", "c:/elllse", Field.Store.YES); | |
doc.add(pathField); | |
doc.add(new LongField("modified", 32324, Field.Store.NO)); | |
doc.add(new TextField("contents", "我爱北京天安门", Field.Store.YES)); | |
writer.addDocument(doc); | |
// update | |
//writer.updateDocument(new Term("path", file.getPath()), doc); | |
writer.Optimize(); | |
writer.close(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment