Beispiel #1
0
 private SegmentCommitInfo indexDoc(IndexWriter writer, String fileName) throws Exception {
   File file = new File(workDir, fileName);
   Document doc = new Document();
   InputStreamReader is = new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8);
   doc.add(new TextField("contents", is));
   writer.addDocument(doc);
   writer.commit();
   is.close();
   return writer.newestSegment();
 }
Beispiel #2
0
 /**
  * Writes the document to the directory using the analyzer and the similarity score; returns the
  * SegmentInfo describing the new segment
  */
 public static SegmentCommitInfo writeDoc(
     Random random, Directory dir, Analyzer analyzer, Similarity similarity, Document doc)
     throws IOException {
   IndexWriter writer =
       new IndexWriter(
           dir,
           new IndexWriterConfig(
                   /* LuceneTestCase.newIndexWriterConfig(random, */
                   TEST_VERSION_CURRENT, analyzer)
               .setSimilarity(
                   similarity == null ? IndexSearcher.getDefaultSimilarity() : similarity));
   // writer.setNoCFSRatio(0.0);
   writer.addDocument(doc);
   writer.commit();
   SegmentCommitInfo info = writer.newestSegment();
   writer.close();
   return info;
 }