当前位置: 首页>>代码示例>>Java>>正文


Java LuceneDictionary类代码示例

本文整理汇总了Java中org.apache.lucene.search.spell.LuceneDictionary的典型用法代码示例。如果您正苦于以下问题:Java LuceneDictionary类的具体用法?Java LuceneDictionary怎么用?Java LuceneDictionary使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


LuceneDictionary类属于org.apache.lucene.search.spell包,在下文中一共展示了LuceneDictionary类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: VocabularyNeo4jImpl

import org.apache.lucene.search.spell.LuceneDictionary; //导入依赖的package包/类
@Inject
public VocabularyNeo4jImpl(GraphDatabaseService graph,
    @Nullable @IndicatesNeo4jGraphLocation String neo4jLocation, CurieUtil curieUtil,
    NodeTransformer transformer) throws IOException {
  this.graph = graph;
  this.curieUtil = curieUtil;
  this.transformer = transformer;
  if (null != neo4jLocation) {
    Directory indexDirectory =
        FSDirectory.open((new File(new File(neo4jLocation), "index/lucene/node/node_auto_index"))
            .toPath());
    Directory spellDirectory =
        FSDirectory.open((new File(new File(neo4jLocation), "index/lucene/spellchecker"))
            .toPath());
    spellChecker = new SpellChecker(spellDirectory);
    try (IndexReader reader = DirectoryReader.open(indexDirectory)) {
      IndexWriterConfig config = new IndexWriterConfig(new KeywordAnalyzer());
      spellChecker.indexDictionary(new LuceneDictionary(reader, NodeProperties.LABEL
          + LuceneUtils.EXACT_SUFFIX), config, true);
    }
  } else {
    spellChecker = null;
  }
}
 
开发者ID:SciGraph,项目名称:SciGraph,代码行数:25,代码来源:VocabularyNeo4jImpl.java

示例2: buildSpellCheckerIndex

import org.apache.lucene.search.spell.LuceneDictionary; //导入依赖的package包/类
protected void buildSpellCheckerIndex(SearchFactory searchFactory) {
	IndexReader reader = null;
	Directory dir = null;
	long _entr = System.currentTimeMillis();
	File spellCheckIndexDir = new File("lucene_index/spellcheck");
	log.info("Building SpellChecker index in {0}", spellCheckIndexDir.getAbsolutePath());
	ReaderProvider readerProvider = searchFactory.getReaderProvider();

	try {
		reader = readerProvider.openReader(searchFactory.getDirectoryProviders(NodeDocumentVersion.class)[0]);
		dir = FSDirectory.open(spellCheckIndexDir);
		SpellChecker spell = new SpellChecker(dir);
		spell.clearIndex();
		spell.indexDictionary(new LuceneDictionary(reader, NodeDocument.TEXT_FIELD));
		spell.close();
		dir.close();
		dir = null;
		long _exit = System.currentTimeMillis();
		log.info("Took {1} (ms) to build SpellChecker index in {0}",
				spellCheckIndexDir.getAbsolutePath(), String.valueOf((_exit - _entr)));
	} catch (Exception exc) {
		log.error("Failed to build spell checker index!", exc);
	} finally {
		if (dir != null) {
			try {
				dir.close();
			} catch (Exception zzz) {
			}
		}
		if (reader != null) {
			readerProvider.closeReader(reader);
		}
	}
}
 
开发者ID:openkm,项目名称:document-management-system,代码行数:35,代码来源:IndexHelper.java

示例3: indexDictionary

import org.apache.lucene.search.spell.LuceneDictionary; //导入依赖的package包/类
/**
  * Indexes the data from the given reader.
* @param reader Source index reader, from which autocomplete words are obtained for the defined field
* @param field the field of the source index reader to index for autocompletion
* @param mergeFactor mergeFactor to use when indexing
* @param ramMB the max amount or memory in MB to use
* @param optimize whether or not the autocomplete index should be optimized
  * @throws AlreadyClosedException if the Autocompleter is already closed
  * @throws IOException
  */
 public final void indexDictionary(IndexReader reader, String field, int mergeFactor, int ramMB, boolean optimize) throws IOException {
   synchronized (modifyCurrentIndexLock) {
     ensureOpen();
     final Directory dir = this.autoCompleteIndex;
     final Dictionary dict = new LuceneDictionary(reader, field);
     final IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig(Version.LUCENE_CURRENT, new WhitespaceAnalyzer(Version.LUCENE_CURRENT)).setRAMBufferSizeMB(ramMB));
     IndexSearcher indexSearcher = obtainSearcher();
     final List<IndexReader> readers = new ArrayList<IndexReader>();

     if (searcher.maxDoc() > 0) {
       ReaderUtil.gatherSubReaders(readers, searcher.getIndexReader());
     }

     //clear the index
     writer.deleteAll();

     try {
       Iterator<String> iter = dict.getWordsIterator();

     while (iter.hasNext()) {
         String word = iter.next();

         // ok index the word
         Document doc = createDocument(word, reader.docFreq(new Term(field, word)));
         writer.addDocument(doc);
       }
     } finally {
       releaseSearcher(indexSearcher);
     }
     // close writer
     if (optimize)
       writer.optimize();
     writer.close();
     // also re-open the autocomplete index to see our own changes when the next suggestion
     // is fetched:
     swapSearcher(dir);
   }
 }
 
开发者ID:webdsl,项目名称:webdsl,代码行数:49,代码来源:AutoCompleter.java

示例4: indexSpellCheck

import org.apache.lucene.search.spell.LuceneDictionary; //导入依赖的package包/类
private void indexSpellCheck(String id) throws SearchException  {
   	if(!spellcheck) return;
   	
   	IndexReader reader=null;
   	FSDirectory spellDir=null;
   	
   	Resource dir = _createSpellDirectory(id);
	try {
   		File spellFile = FileWrapper.toFile(dir);
   		spellDir = FSDirectory.getDirectory(spellFile);
    	reader = _getReader(id,false);
    	Dictionary dictionary = new LuceneDictionary(reader,"contents");
		
    	SpellChecker spellChecker = new SpellChecker(spellDir);
    	spellChecker.indexDictionary(dictionary);
		
   	}
   	catch(IOException ioe) {
   		throw new SearchException(ioe);
   	}
   	finally {
   		flushEL(reader);
		closeEL(reader);
   	}
}
 
开发者ID:lucee,项目名称:Lucee4,代码行数:26,代码来源:LuceneSearchCollection.java

示例5: populate

import org.apache.lucene.search.spell.LuceneDictionary; //导入依赖的package包/类
@Override
protected void populate(Timer timer) throws Exception {
	LuceneDictionary dict = reader.getLuceneDirectionary(field);
	spellChecker = new SpellChecker(new RAMDirectory());
	spellChecker.indexDictionary(dict, new IndexWriterConfig(
			Version.LUCENE_36, null), true);
}
 
开发者ID:jaeksoft,项目名称:opensearchserver,代码行数:8,代码来源:SpellCheckCacheItem.java

示例6: main

import org.apache.lucene.search.spell.LuceneDictionary; //导入依赖的package包/类
public static void main(String[] args) throws IOException {

    if (args.length != 3) {
      LOGGER.info("Usage: java lia.tools.SpellCheckerTest SpellCheckerIndexDir IndexDir IndexField");
      System.exit(1);
    }

    String spellCheckDir = args[0];
    String indexDir = args[1];
    String indexField = args[2];

    LOGGER.info("Now build SpellChecker index...");
    Directory dir = FSDirectory.open(new File(spellCheckDir));
    SpellChecker spell = new SpellChecker(dir);     //#A
    long startTime = System.currentTimeMillis();
    
    Directory dir2 = FSDirectory.open(new File(indexDir));
    IndexReader r = DirectoryReader.open(dir2);     //#B
    try {
      spell.indexDictionary(new LuceneDictionary(r, indexField));  //#C
    } finally {
      r.close();
    }
    dir.close();
    dir2.close();
    long endTime = System.currentTimeMillis();
    LOGGER.info("  took " + (endTime-startTime) + " milliseconds");
  }
 
开发者ID:xuzhikethinker,项目名称:t4f-data,代码行数:29,代码来源:CreateSpellCheckerIndex.java

示例7: createSpellIndex

import org.apache.lucene.search.spell.LuceneDictionary; //导入依赖的package包/类
/**
 * Creates a new spell-check index based on search-index
 */
public void createSpellIndex() {
    if (isSpellCheckEnabled) {
        IndexReader indexReader = null;
        try {
            log.info("Start generating Spell-Index...");
            long startSpellIndexTime = 0;
            if (log.isDebugEnabled()) {
                startSpellIndexTime = System.currentTimeMillis();
            }
            final Directory indexDir = FSDirectory.open(new File(indexPath));
            indexReader = IndexReader.open(indexDir);
            // 1. Create content spellIndex
            final File spellDictionaryFile = new File(spellDictionaryPath);
            final Directory contentSpellIndexDirectory = FSDirectory.open(new File(spellDictionaryPath + CONTENT_PATH));// true
            final SpellChecker contentSpellChecker = new SpellChecker(contentSpellIndexDirectory);
            final Dictionary contentDictionary = new LuceneDictionary(indexReader, AbstractOlatDocument.CONTENT_FIELD_NAME);
            contentSpellChecker.indexDictionary(contentDictionary);
            // 2. Create title spellIndex
            final Directory titleSpellIndexDirectory = FSDirectory.open(new File(spellDictionaryPath + TITLE_PATH));// true
            final SpellChecker titleSpellChecker = new SpellChecker(titleSpellIndexDirectory);
            final Dictionary titleDictionary = new LuceneDictionary(indexReader, AbstractOlatDocument.TITLE_FIELD_NAME);
            titleSpellChecker.indexDictionary(titleDictionary);
            // 3. Create description spellIndex
            final Directory descriptionSpellIndexDirectory = FSDirectory.open(new File(spellDictionaryPath + DESCRIPTION_PATH));// true
            final SpellChecker descriptionSpellChecker = new SpellChecker(descriptionSpellIndexDirectory);
            final Dictionary descriptionDictionary = new LuceneDictionary(indexReader, AbstractOlatDocument.DESCRIPTION_FIELD_NAME);
            descriptionSpellChecker.indexDictionary(descriptionDictionary);
            // 4. Create author spellIndex
            final Directory authorSpellIndexDirectory = FSDirectory.open(new File(spellDictionaryPath + AUTHOR_PATH));// true
            final SpellChecker authorSpellChecker = new SpellChecker(authorSpellIndexDirectory);
            final Dictionary authorDictionary = new LuceneDictionary(indexReader, AbstractOlatDocument.AUTHOR_FIELD_NAME);
            authorSpellChecker.indexDictionary(authorDictionary);

            // Merge all part spell indexes (content,title etc.) to one common spell index
            final Directory spellIndexDirectory = FSDirectory.open(spellDictionaryFile);// true
            final IndexWriter merger = new IndexWriter(spellIndexDirectory, new StandardAnalyzer(Version.LUCENE_CURRENT), true, IndexWriter.MaxFieldLength.UNLIMITED);
            final Directory[] directories = { contentSpellIndexDirectory, titleSpellIndexDirectory, descriptionSpellIndexDirectory, authorSpellIndexDirectory };
            merger.addIndexesNoOptimize(directories);
            merger.optimize();
            merger.close();
            spellChecker = new SpellChecker(spellIndexDirectory);
            spellChecker.setAccuracy(0.7f);
            if (log.isDebugEnabled()) {
                log.debug("SpellIndex created in " + (System.currentTimeMillis() - startSpellIndexTime) + "ms");
            }
            log.info("New generated Spell-Index ready to use.");
        } catch (final IOException ioEx) {
            log.warn("Can not create SpellIndex", ioEx);
        } finally {
            if (indexReader != null) {
                try {
                    indexReader.close();
                } catch (final IOException e) {
                    log.warn("Can not close indexReader properly", e);
                }
            }
        }
    }
}
 
开发者ID:huihoo,项目名称:olat,代码行数:63,代码来源:SearchSpellChecker.java

示例8: getLuceneDirectionary

import org.apache.lucene.search.spell.LuceneDictionary; //导入依赖的package包/类
public LuceneDictionary getLuceneDirectionary(String fieldName) {
	return new LuceneDictionary(indexReader, fieldName);
}
 
开发者ID:jaeksoft,项目名称:opensearchserver,代码行数:4,代码来源:ReaderLocal.java


注:本文中的org.apache.lucene.search.spell.LuceneDictionary类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。