Package org.apache.lucene.index

Examples of org.apache.lucene.index.IndexWriter$IndexReaderWarmer


/*
  * Create a RAM based Lucene index
  */
private void createRamIW()
{ try { ramIW = new IndexWriter(ramDir, analyzer, true)}
   catch (IOException ie) { logger.error("Could not create RAM index writer " + ie.getMessage()); }
   ramIW.setMaxFieldLength(Constants.LUCENE_MAX_WORDS);
}
View Full Code Here


    fNewsListener = null;
  }

  private IndexWriter createIndexWriter(Directory directory, boolean create) throws IOException {
    IndexWriter indexWriter = new IndexWriter(directory, createAnalyzer(), create);
    fFlushRequired = false;
    return indexWriter;
  }
View Full Code Here

    fNewsListener = null;
  }

  private IndexWriter createIndexWriter(Directory directory, boolean create) throws IOException {
    IndexWriter indexWriter = new IndexWriter(directory, false, createAnalyzer(), create);
    indexWriter.setMergeFactor(6);
    fFlushRequired = false;
    return indexWriter;
  }
View Full Code Here

    try {
      objects = new ArrayList();

      analyzer = new SimpleAnalyzer();
      indexDirectory = new RAMDirectory();
      indexWriter = new IndexWriter(indexDirectory,
          new IndexWriterConfig(Version.LUCENE_31,
              new LimitTokenCountAnalyzer(analyzer,
                  Integer.MAX_VALUE))
              .setOpenMode(OpenMode.CREATE));
      queryParser = new QueryParser(Version.LUCENE_31, "text", analyzer);
View Full Code Here

   */
  public void indexItems(boolean createNewIndex, Collection<ItemIF> items)
    throws java.io.IOException {
   
    logger.info("Start writing index.");
    IndexWriter writer = new IndexWriter(indexDir, analyzer, createNewIndex);
    Iterator<ItemIF> itI = items.iterator();
    while (itI.hasNext()) {
      ItemIF item = itI.next();
      if (logger.isDebugEnabled()) {
        logger.debug("Add item " + item + " to index.");
      }
      writer.addDocument(ItemDocument.makeDocument(item));
    }
    writer.optimize();
    nrOfIndexedItems = writer.docCount();
    writer.close();
    logger.info("Finished writing index.");
  }
View Full Code Here

    return index;
  }
 
  private RAMDirectory createRAMIndex(Document doc) {
    RAMDirectory dir = new RAMDirectory();   
    IndexWriter writer = null;
    try {
      writer = new IndexWriter(dir, analyzer, true);
      writer.setMaxFieldLength(Integer.MAX_VALUE);
      writer.addDocument(doc);
      writer.optimize();
      return dir;
    } catch (IOException e) { // should never happen (RAMDirectory)
      throw new RuntimeException(e);
    } finally {
      try {
        if (writer != null) writer.close();
      } catch (IOException e) { // should never happen (RAMDirectory)
        throw new RuntimeException(e);
      }
    }
  }
View Full Code Here

        // 3. Close reader
        indexReader.close();
        directory.close();
       
        // 4. open writer
        IndexWriter indexWriter = new IndexWriter(directory, new StandardAnalyzer(Version.LUCENE_CURRENT), false, IndexWriter.MaxFieldLength.UNLIMITED);
        indexWriter.setMergeFactor(INDEX_MERGE_FACTOR); //for better performance
        // 5. Add new Document
        for (int i = 0; i < updateCopy.size(); i++) {
          Document document = updateCopy.get(i);
          log.info("addDocument:" + document);
          indexWriter.addDocument(document);         
        }
        // 6. Close writer
        long startOptimizeTime = 0;
        if (log.isDebug()) startOptimizeTime = System.currentTimeMillis();
        indexWriter.optimize();// TODO:chg: dauert ev. zulange oder nocht noetig
        if (log.isDebug()) log.debug("Optimized in " + (System.currentTimeMillis() - startOptimizeTime) + "ms");
        indexWriter.close();
      } catch (Exception ex) {
        log.warn("Exception during doUpdate. ", ex);
      }
    } else {
      log.debug("Queues are ampty.");
View Full Code Here

        Dictionary authorDictionary = new LuceneDictionary(indexReader, OlatDocument.AUTHOR_FIELD_NAME);
        authorSpellChecker.indexDictionary(authorDictionary);
       
        // Merge all part spell indexes (content,title etc.) to one common spell index
        Directory spellIndexDirectory = FSDirectory.open(spellDictionaryFile);//true
        IndexWriter merger = new IndexWriter(spellIndexDirectory, new StandardAnalyzer(Version.LUCENE_CURRENT), true, IndexWriter.MaxFieldLength.UNLIMITED);
        Directory[] directories = { contentSpellIndexDirectory, titleSpellIndexDirectory, descriptionSpellIndexDirectory, authorSpellIndexDirectory};
        merger.addIndexesNoOptimize(directories);
        merger.optimize();
        merger.close();
        spellChecker = new SpellChecker(spellIndexDirectory);
        spellChecker.setAccuracy(0.7f);
         if (log.isDebug()) log.debug("SpellIndex created in " + (System.currentTimeMillis() - startSpellIndexTime) + "ms");
        log.info("New generated Spell-Index ready to use.");
      } catch(IOException ioEx) {
View Full Code Here

  private void doIndex() throws InterruptedException{
    try {
      File tempIndexDir = new File(tempIndexPath);
      Directory indexPath = FSDirectory.open(new File(tempIndexDir, "main"));
      Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_CURRENT);
      indexWriter = new IndexWriter(indexPath, analyzer, true, IndexWriter.MaxFieldLength.UNLIMITED);
      indexWriter.deleteAll();
      indexWriter.setMergeFactor(INDEX_MERGE_FACTOR); //for better performance
      // Create IndexWriterWorker
      log.info("Running with " + numberIndexWriter + " IndexerWriterWorker");
      indexWriterWorkers = new IndexWriterWorker[numberIndexWriter];
View Full Code Here

    this.id = id;
    this.fullIndexer = fullIndexer;
    try {
      File indexPartFile = new File(tempIndexDir, "part" + id);
      Directory indexPartDirectory = FSDirectory.open(indexPartFile);
      indexWriter = new IndexWriter(indexPartDirectory, new StandardAnalyzer(Version.LUCENE_CURRENT), true, IndexWriter.MaxFieldLength.UNLIMITED);
      indexWriter.deleteAll();
    } catch (IOException e) {
      log.warn("Can not create IndexWriter");
    }
  }
View Full Code Here

TOP

Related Classes of org.apache.lucene.index.IndexWriter$IndexReaderWarmer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.