Esempio n. 1
0
  void indexar(Document document) throws Exception {

    Analyzer analyzer = new StandardAnalyzer();
    IndexWriter writer = new IndexWriter(directorioIndexacion, analyzer, true);
    writer.setUseCompoundFile(false);
    writer.addDocument(document);
    writer.optimize();
    writer.close();
  }
  private IndexWriter createWriter() throws IOException {
    IndexWriter writer = new IndexWriter(dir, false, null, new KeepOnlyLastCommitDeletionPolicy());
    writer.setUseCompoundFile(false);

    if (iconf != null) {
      int maxFieldLength = iconf.getIndexMaxFieldLength();
      if (maxFieldLength > 0) {
        writer.setMaxFieldLength(maxFieldLength);
      }
    }

    return writer;
  }
  @SuppressWarnings("deprecation")
  public static int index(File indexDir, File dataDir) {

    try {
      IndexWriter writer = new IndexWriter(indexDir, new StandardAnalyzer(), true);
      writer.setUseCompoundFile(false);
      indexDirectory(writer, dataDir);
      int numIndexed = writer.docCount();
      writer.optimize();
      writer.close();
      return numIndexed;

    } catch (IOException e) {
      e.printStackTrace();
      return -1;
    }
  }
  public void sort(File directory) throws IOException {
    LOG.info("IndexSorter: starting.");
    Date start = new Date();
    int termIndexInterval = getConf().getInt("indexer.termIndexInterval", 128);
    IndexReader reader = IndexReader.open(new File(directory, "index"));
    Searcher searcher =
        new IndexSearcher(new File(directory, "index").getAbsolutePath()); // TODO MC

    SortingReader sorter = new SortingReader(reader, newToOld(reader, searcher)); // TODO MC
    IndexWriter writer = new IndexWriter(new File(directory, "index-sorted"), null, true);
    writer.setTermIndexInterval(termIndexInterval);
    writer.setUseCompoundFile(false);
    writer.addIndexes(new IndexReader[] {sorter});
    writer.close();
    Date end = new Date();
    LOG.info("IndexSorter: done, " + (end.getTime() - start.getTime()) + " total milliseconds");
  }
 private IndexWriter createWriter() throws IOException {
   IndexWriter writer =
       new IndexWriter(dir, new IKAnalyzer(), true, IndexWriter.MaxFieldLength.UNLIMITED);
   writer.setUseCompoundFile(false);
   return writer;
 }