Examples of Directory


Examples of org.apache.lucene.store.Directory

  /**
   * @param args
   */
  public static void main(String[] args) throws Exception
  {
    Directory idxDir = FSDirectory.open(new File("/Users/jwang/proj/bobo-trunk/cardata/cartag"));
    File outDir = new File("/Users/jwang/proj/bobo-trunk/cardata");
    FieldDumper dumper = new FieldDumper(idxDir,outDir);
    dumper.doit();
  }
View Full Code Here

Examples of org.apache.lucene.store.Directory

 
  protected void initialize(Collection<FacetHandler<?>> facetHandlers) throws IOException
  {
    if (facetHandlers == null) // try to load from index
    {
      Directory idxDir = directory();
      if (idxDir != null && idxDir instanceof FSDirectory)
      {
        FSDirectory fsDir = (FSDirectory) idxDir;
        File file = fsDir.getFile();
View Full Code Here

Examples of org.apache.lucene.store.Directory

     }
  }
 
  //*-- return IndexSearcher if zero sub-directories
  if (idirs.size() == 0)
   { Directory directory = FSDirectory.getDirectory( dirs[0], create);
     return( new IndexSearcher(directory) );
   }
 
  //*-- otherwise return MultiSearcher
  IndexSearcher[] searchers = new IndexSearcher[ idirs.size() ];
  for (int i = 0; i < idirs.size(); i++)
  { Directory directory = FSDirectory.getDirectory( idirs.get(i), create);
    searchers[i] = new IndexSearcher(directory);
  }
 
  return (new MultiSearcher(searchers));
}
View Full Code Here

Examples of org.apache.lucene.store.Directory

  }
 
  private int getMemorySize(Object index) {
    if (index instanceof Directory) {
      try {
        Directory dir = (Directory) index;
        int size = 0;
        String[] fileNames = dir.list();
        for (int i=0; i < fileNames.length; i++) {
          size += dir.fileLength(fileNames[i]);
        }
        return size;
      }
      catch (IOException e) { // can never happen (RAMDirectory)
        throw new RuntimeException(e);
View Full Code Here

Examples of org.apache.lucene.store.Directory

          deleteCopy = new Vector<Document>(deleteQueue);
          deleteQueue.clear();
        }
        // 1. Open Index Reader
        File indexFile = new File(indexPath);
        Directory directory = FSDirectory.open(indexFile);
        IndexReader indexReader = IndexReader.open(directory);

        log.info("befor delete: indexReader.numDocs()=" + indexReader.numDocs());
        // 2. Delete old Document
        // loop over all documents in updateQueue
        for (int i = 0; i < updateCopy.size(); i++) {
          String resourceUrl = updateCopy.get(i).get(OlatDocument.RESOURCEURL_FIELD_NAME);
          Term term = new Term(OlatDocument.RESOURCEURL_FIELD_NAME, resourceUrl );
          log.info("updateQueue:delete documents with resourceUrl=" + resourceUrl );
          indexReader.deleteDocuments(term);         
        }
        // loop over all documents in deleteQueue
        for (int i = 0; i < deleteCopy.size(); i++) {
          String resourceUrl = deleteCopy.get(i).get(OlatDocument.RESOURCEURL_FIELD_NAME);
          Term term = new Term(OlatDocument.RESOURCEURL_FIELD_NAME, resourceUrl );
          log.info("deleteQueue:delete documents with resourceUrl='" + resourceUrl + "'");
          indexReader.deleteDocuments(term);
         
        }
        log.info("after delete: indexReader.numDocs()=" + indexReader.numDocs());
        // 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
View Full Code Here

Examples of org.apache.lucene.store.Directory

    try {
      if(spellChecker==null) { //lazy initialization
        try {
          synchronized(spellDictionaryPath) {//o_clusterOK by:pb if service is only configured on one vm, which is recommended way
            File spellDictionaryFile = new File(spellDictionaryPath);
            Directory spellIndexDirectory = FSDirectory.open(spellDictionaryFile);
            if (spellChecker==null && IndexReader.indexExists(spellIndexDirectory) && isSpellCheckEnabled ) {
              spellChecker = new SpellChecker(spellIndexDirectory);
              spellChecker.setAccuracy(0.7f);
            }
          }
View Full Code Here

Examples of org.apache.lucene.store.Directory

      IndexReader indexReader = null;
      try {
        log.info("Start generating Spell-Index...");
        long startSpellIndexTime = 0;
        if (log.isDebug()) startSpellIndexTime = System.currentTimeMillis();
        Directory indexDir = FSDirectory.open(new File(indexPath));
        indexReader = IndexReader.open(indexDir);
        // 1. Create content spellIndex
        File spellDictionaryFile = new File(spellDictionaryPath);
        Directory contentSpellIndexDirectory = FSDirectory.open(new File(spellDictionaryPath + CONTENT_PATH));//true
        SpellChecker contentSpellChecker = new SpellChecker(contentSpellIndexDirectory);
        Dictionary contentDictionary = new LuceneDictionary(indexReader, OlatDocument.CONTENT_FIELD_NAME);
        contentSpellChecker.indexDictionary(contentDictionary);
        // 2. Create title spellIndex
        Directory titleSpellIndexDirectory = FSDirectory.open(new File(spellDictionaryPath + TITLE_PATH));//true
        SpellChecker titleSpellChecker = new SpellChecker(titleSpellIndexDirectory);
        Dictionary titleDictionary = new LuceneDictionary(indexReader, OlatDocument.TITLE_FIELD_NAME);
        titleSpellChecker.indexDictionary(titleDictionary);
        // 3. Create description spellIndex
        Directory descriptionSpellIndexDirectory = FSDirectory.open(new File(spellDictionaryPath + DESCRIPTION_PATH));//true
        SpellChecker descriptionSpellChecker = new SpellChecker(descriptionSpellIndexDirectory);
        Dictionary descriptionDictionary = new LuceneDictionary(indexReader, OlatDocument.DESCRIPTION_FIELD_NAME);
        descriptionSpellChecker.indexDictionary(descriptionDictionary);
        // 4. Create author spellIndex
        Directory authorSpellIndexDirectory = FSDirectory.open(new File(spellDictionaryPath + AUTHOR_PATH));//true
        SpellChecker authorSpellChecker = new SpellChecker(authorSpellIndexDirectory);
        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();
View Full Code Here

Examples of org.apache.lucene.store.Directory

    return false;
  }

  private void createIndexSearcher(String path) throws IOException {
    File indexFile = new File(path);
    Directory directory = FSDirectory.open(indexFile);
    searcher = new IndexSearcher(directory);
    openIndexDate = getCurrentIndexDate();
  }
View Full Code Here

Examples of org.apache.lucene.store.Directory

  /**
   * @return  Creation date of current used search index.
   */
  private Date getCurrentIndexDate() throws IOException {
    File indexFile = new File(indexPath);
    Directory directory = FSDirectory.open(indexFile);
    return new Date(IndexReader.getCurrentVersion(directory));
  }
View Full Code Here

Examples of org.apache.lucene.store.Directory

   */
  private boolean existIndex()
  throws IOException {
    try {
      File indexFile = new File(indexPath);
      Directory directory = FSDirectory.open(indexFile);
      return IndexReader.indexExists(directory);
    } catch (IOException e) {
      throw e;
    }
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.