IndexWriter Sınıfı
GirişŞu satırı dahil ederiz.
import org.apache.lucene.index.IndexWriter;
constructorİmzası şöyle
IndexWriter(Directory d, Analyzer a, boolean create, IndexWriter.MaxFieldLength mfl)
Açıklaması şöyleIndexWriter accepts an analyzer used to tokenize data before it is indexed.Şöyle yaparız.
File directory = ...;
IndexWriter indexWriter = new IndexWriter(FSDirectory.open(directory), analyzer,
IndexWriter.MaxFieldLength.LIMITED);
constructor - Directory + IndexWriterConfigŞöyle yaparız.
RAMDirectory ramDir = ...;
Analyzer analyzer = ...;
// Setup the configuration for the index
IndexWriterConfig config = new IndexWriterConfig(analyzer);
config.setOpenMode(IndexWriterConfig.OpenMode.CREATE);
// IndexWriter creates and maintains the index
IndexWriter writer = new IndexWriter(ramDir, config);
close metoduŞöyle yaparız.
indexWriter.close();
constructor - IndexWriterConfigŞöyle yaparız.
Analyzer analyzer = ...;
Directory directory = new RAMDirectory();
IndexWriterConfig config = new IndexWriterConfig(analyzer);
IndexWriter indexWriter = new IndexWriter(directory, config);
addDocument metodu
Şöyle yaparız.
Document doc = new Document();
...
indexWriter.addDocument(doc);
ÖrnekŞöyle yaparız.
// Create the documents
indexDoc(writer, "document-1", "hello planet mercury");
indexDoc(writer, "document-2", "hi PLANET venus");
indexDoc(writer, "document-3", "howdy Planet Earth");
indexDoc(writer, "document-4", "hey planet MARS");
indexDoc(writer, "document-5", "ayee Planet jupiter");
// Close down the writer
writer.close();
private static void indexDoc(IndexWriter writer, String name, String content)
throws IOException {
Document document = new Document();
document.add(new TextField("name", name, Field.Store.YES));
document.add(new TextField("body", content, Field.Store.YES));
writer.addDocument(document);
}
getReader metoduŞöyle yaparız.
IndexReader indexReader = indexWriter.getReader();
IndexWriterConfig Sınıfı
Giriş
Şu satırı dahil ederiz.
Giriş
Şu satırı dahil ederiz.
import org.apache.lucene.index.IndexWriterConfig;
constructor metodu - Analyzer
Örnek
Şöyle yaparız.
Şöyle yaparız.
Şöyle yaparız.
// Create the analyzer (has default stop words)
Analyzer analyzer = new StandardAnalyzer();
// Setup the configuration for the index
IndexWriterConfig config = new IndexWriterConfig(analyzer);
config.setOpenMode(IndexWriterConfig.OpenMode.CREATE);
ÖrnekŞöyle yaparız.
EnglishAnalyzer an = new EnglishAnalyzer();
IndexWriterConfig config = new IndexWriterConfig(an);
constructor metodu - version + Analyzer
Şöyle yaparız.
Şöyle yaparız.
Şöyle yaparız.
StandardAnalyzer analyzer = new StandardAnalyzer(Version.LUCENE_30);
IndexWriterConfig config = new IndexWriterConfig(Version.LUCENE_30,analyzer);
setCommitOnClose metoduŞöyle yaparız.
config.setCommitOnClose(true);
setOpenMode metodu
Şöyle yaparız.
config.setOpenMode(IndexWriterConfig.OpenMode.CREATE);
Hiç yorum yok:
Yorum Gönder