Package org.apache.lucene.index

Examples of org.apache.lucene.index.IndexWriter


 
  //@Override
  protected void setUp() throws Exception {
    directory = new RAMDirectory();
    analyzer = new WhitespaceAnalyzer();
    writer = new IndexWriter(directory, analyzer, true, MaxFieldLength.UNLIMITED);
    addDoc("1", new String[]{ "aa","bb"}, new String[]{"aaa","aaa"}, new int[]{100,200});
    addDoc("2", new String[]{ "aa","bb"}, new String[]{"aaa","bbb"}, new int[]{200,200});
    addDoc("3", new String[]{ "aa","bb"}, new String[]{"bbb","aaa"}, new int[]{300,300});
    addDoc("3", new String[]{ "bb","aa"}, new String[]{"bbb","bbb"}, new int[]{300,400});
    addDoc("3", new String[]{ "bb","aa"}, new String[]{"aaa","ccc"}, new int[]{300,500});
View Full Code Here


  {
    super(testname);
    _ramDir = new RAMDirectory();
    try
    {
      IndexWriter writer = new IndexWriter(_ramDir,new StandardAnalyzer(Version.LUCENE_CURRENT),MaxFieldLength.UNLIMITED);
      writer.close();
    }
    catch(Exception ioe)
    {
      fail("unable to load test");
    }
View Full Code Here

    }
  }

  private IndexWriter createIndexWriter(boolean createNewIndex)
          throws IOException {
    IndexWriter indexWriter = new IndexWriter(mLuceneTempIndexDir, mAnalyzer,
            createNewIndex, IndexWriter.MaxFieldLength.UNLIMITED);

    int maxFieldLength = mConfig.getMaxFieldLength();
    if (maxFieldLength > 0) {
      indexWriter.setMaxFieldLength(maxFieldLength);
    }

    return indexWriter;
  }
View Full Code Here

    }

    private IndexWriter createIndexWriter() throws CorruptIndexException,
        LockObtainFailedException, IOException {
      Analyzer analyzer = DocumentCreator.createDocumentAnalyzer();
      return new IndexWriter(indexDirectory, analyzer);
    }
View Full Code Here

    }
   
    public void run() {
      boolean stopRunning = false;
      while (true && stopRunning == false) {
        IndexWriter writer = null;
        try {
          workQueue = batchRequest(documentQueue);
          logger.debug("UpdateIndexWorker: batching # of Request :"
              + workQueue.size());
          Request aReq = workQueue.poll();
          if(aReq != null && aReq.type != RST){
            writer = createIndexWriter();
          }
          while (aReq != null) {
            Document doc = aReq.doc;
            if (doc != null && POISON_DOC.equals(doc)) {
              logger.debug("Terminate UpdateIndexWorker.");
              stopRunning = true;
            } else if (aReq.type == RST) {
              logger.debug("===================================> Do RESET.");
              doReset();
            } else {           
              if (aReq.type == ADD && doc != null) {
               
                doAdd(doc, writer);
              } else if (aReq.type == UPD && doc != null) {
                doUpdate(doc, writer);
              } else if (aReq.type == DEL && doc != null) {
                doDelete(doc, writer);
              }
            }
            aReq = workQueue.poll();
          }
        } catch (InterruptedException e) {
          logger.debug("UpdateIndexWorker is interrupted.");
          stopRunning = true;
        } catch (Exception e) {
          logger.error(e);
        } finally{
          if(writer != null){
            try{
              writer.optimize();
              writer.flush();
              writer.close();
            }catch(Exception e){
              logger.error(e);
            }
          }
        }
View Full Code Here

  }

  private void initPopularTagDataIndex(List<Tag> tags, Directory directory)
      throws CorruptIndexException, LockObtainFailedException,
      IOException {
    IndexWriter indexWriter = null;
    try {
      indexWriter = new IndexWriter(directory, new KeywordAnalyzer(),
          true);
      for (Tag tag : tags) {
        String t = tag.getLabel();
        if (t.length() >= 3) {
          Document doc = createDocument(t);
          indexWriter.addDocument(doc);
        }
      }
      indexWriter.optimize();
    } finally {
      if (indexWriter != null) {
        try {
          indexWriter.close();
        } catch (Exception e) {
          logger.error(e);
        }
      }
    }
View Full Code Here

  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

TOP

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

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.