Package org.apache.lucene.index

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


  private void initCustomDataIndex(String dataFile, Directory directory)
      throws CorruptIndexException, LockObtainFailedException,
      IOException {
    BufferedReader dataReader = createDataBufferedReader(dataFile);
    if (dataReader != null) {
      IndexWriter indexWriter = new IndexWriter(directory,
          new KeywordAnalyzer(), true);
      try {
        String aline = dataReader.readLine();
        while (aline != null) {
          StringTokenizer tokenizer = new StringTokenizer(aline,
              "\n\r\f", false);
          while (tokenizer.hasMoreTokens()) {
            String token = tokenizer.nextToken().trim();
            if (token != null) {
              Document doc = createDocument(token);
              indexWriter.addDocument(doc);
            }
          }
          aline = dataReader.readLine();
        }
        indexWriter.optimize();
      } finally {
        if (indexWriter != null) {
          try {
            indexWriter.close();
          } catch (Exception e) {
            logger.error(e);
          }
        }
        if (dataReader != null) {
View Full Code Here


    workerThread.setDaemon(true);
    workerThread.start();
  }

  private void createEmptyIndexDirectory() {
    IndexWriter writer = null;
    try {
      writer = new IndexWriter(indexDirectory, DocumentCreator
          .createDocumentAnalyzer(), true);
    } catch (Exception e) {
      logger.error("Unable to reset the search index. Path "
          + indexDirectory.toString(), e);
    } finally {
      if (writer != null) {
        try {
          writer.optimize();
          writer.close();
        } catch (Exception e) {
          logger.error(e);
        }
      }
    }
View Full Code Here

      directory = new RAMDirectory();
      directory.setLockFactory(NoLockFactory.getNoLockFactory());

      /* Index News */
      try {
        IndexWriter indexWriter = new IndexWriter(directory, Indexer.createAnalyzer());
        for (int i = 0; i < news.size(); i++) {

          /* Return early on cancellation */
          if (monitor.isCanceled() || Owl.isShuttingDown())
            return false;

          NewsDocument document = new NewsDocument(news.get(i));
          document.addFields(indexDescription);
          document.getDocument().getField(SearchDocument.ENTITY_ID_TEXT).setValue(String.valueOf(i));
          indexWriter.addDocument(document.getDocument());
        }
        indexWriter.close();

        searcher[0] = new IndexSearcher(directory);
      } catch (Exception e) {
        directory.close();
        throw e;
View Full Code Here

  boolean freshIndex = (crawlConfig.getFreshIndex() == -1) ? freshCrawl:
         (crawlConfig.getFreshIndex() ==  0) ? false: true;
  try 
  {
   fsd = FSDirectory.getDirectory(new File(Constants.getINDEXDIR()), freshIndex);
   analyzer = new StandardBgramAnalyzer(); iw = new IndexWriter(fsd, analyzer, freshIndex);
   iw.setSimilarity(new SearchSimilarity());
   ctRef.setIw(iw);
  }
  catch (IOException ie) { ctRef.cleanUp("Could not get IndexWriter " + ie.getMessage() ); }
View Full Code Here

/*
  * 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

TOP

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

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.