List of usage examples for org.apache.lucene.search SearcherManager SearcherManager
public SearcherManager(DirectoryReader reader, SearcherFactory searcherFactory) throws IOException
From source file:be.ugent.tiwi.sleroux.newsrec.newsreclib.newsFetch.storm.bolts.NewsItemToTermsBolt.java
License:Apache License
@Override public void prepare(Map stormConf, TopologyContext context, OutputCollector collector) { try {//from w w w. ja v a2 s . co m this.collector = collector; Directory dir = FSDirectory.open(new File(luceneIndexLocation)); searcherManager = new SearcherManager(dir, null); readerManager = new ReaderManager(dir); } catch (IOException ex) { logger.fatal(ex); } }
From source file:be.ugent.tiwi.sleroux.newsrec.newsreclib.recommend.RecommenderBuilder.java
License:Apache License
private void build() throws RecommenderBuildException { try {// w w w .j a v a 2 s .c o m Directory dir = FSDirectory.open(new File(luceneIndexLocation)); searcherManager = new SearcherManager(dir, null); } catch (IOException ex) { throw new RecommenderBuildException(ex); } }
From source file:com.andreig.jetty.Search.java
License:GNU General Public License
private Search(String index_path) throws IOException, ParseException { this.index_path = index_path; analyzer = new StandardAnalyzer(Version.LUCENE_36); tl = new ThreadLocal<QueryParser>() { @Override//from www.j av a2s .c o m protected synchronized QueryParser initialValue() { return new QueryParser(Version.LUCENE_36, Config.search_default_field, analyzer); } }; File f = new File(index_path); if (!f.exists()) f.mkdir(); index = FSDirectory.open(f); try { sm = new SearcherManager(index, new SearcherFactory()); } catch (IndexNotFoundException e) { log.warning("No index found. First time use?"); create_writer(); writer.commit(); sm = new SearcherManager(index, new SearcherFactory()); } final Runnable r = new Runnable() { public void run() { try { sm.maybeRefresh(); } catch (IOException e) { log.severe("maybeRefresh() error " + e); } } }; service = Executors.newScheduledThreadPool(1); alarm = service.scheduleAtFixedRate(r, 30, 30, MINUTES); }
From source file:com.b2international.index.compat.SingleDirectoryIndexImpl.java
License:Apache License
protected void initLucene(final File indexDirectory, final boolean clean) { try {//from w w w. j a va2 s .com this.directory = Directories.openFile(indexDirectory.toPath()); final Analyzer analyzer = new ComponentTermAnalyzer(); final IndexWriterConfig config = new IndexWriterConfig(analyzer); config.setOpenMode(clean ? OpenMode.CREATE : OpenMode.CREATE_OR_APPEND); config.setIndexDeletionPolicy(new SnapshotDeletionPolicy(config.getIndexDeletionPolicy())); this.writer = new IndexWriter(directory, config); this.writer.commit(); // Create index if it didn't exist this.manager = new SearcherManager(directory, new SearchWarmerFactory()); } catch (final IOException e) { throw new RuntimeException(e.getMessage(), e); } }
From source file:com.baidu.rigel.biplatform.tesseract.isservice.search.service.IndexSearcherFactory.java
License:Open Source License
/** * // w w w.ja v a 2 s . com * getSearcherManager * * @param idxPath * * @return SearcherManager * @throws IOException * ? */ public synchronized SearcherManager getSearcherManager(String idxPath) throws IOException { LOGGER.info(String.format(LogInfoConstants.INFO_PATTERN_FUNCTION_BEGIN, "getSearcherManager", idxPath)); SearcherManager searcherManager = null; if (StringUtils.isEmpty(idxPath)) { LOGGER.info( String.format(LogInfoConstants.INFO_PATTERN_FUNCTION_EXCEPTION, "getSearcherManager", idxPath)); throw new IllegalArgumentException(); } if (this.searcherManagerMaps.containsKey(idxPath)) { searcherManager = this.searcherManagerMaps.get(idxPath); } else { File indexFile = new File(idxPath); if (indexFile.exists()) { Directory directory = FSDirectory.open(indexFile); searcherManager = new SearcherManager(directory, this.new TesseractSearcherFactory()); } else { LOGGER.info(String.format(LogInfoConstants.INFO_PATTERN_FUNCTION_PROCESS_NO_PARAM, "getSearcherManager", "[idxPath:" + idxPath + " not exist]")); } } LOGGER.info(String.format(LogInfoConstants.INFO_PATTERN_FUNCTION_END, "getSearcherManager", idxPath)); return searcherManager; }
From source file:com.berico.clavin.resolver.impl.lucene.LuceneComponentsFactory.java
License:Apache License
/** * Initialize the SearcherManager (and other components). * @return This object (it's needlessly fluent!). * @throws IOException // www. jav a 2 s .c om */ public LuceneComponentsFactory initializeSearcher() throws IOException { initializeCommon(); // instantiate an index searcher indexSearcher = new IndexSearcher(DirectoryReader.open(index)); // override default TF/IDF score to ignore multiple appearances indexSearcher.setSimilarity(new BinarySimilarity()); // Instantiate the searcher manager. searcherManager = new SearcherManager(index, null); // Do it. return this; }
From source file:com.cyslab.craftvm.rest.mongo.Search.java
License:GNU General Public License
private Search(String index_path) throws IOException, ParseException { this.index_path = index_path; analyzer = new StandardAnalyzer(Version.LUCENE_36); tl = new ThreadLocal<QueryParser>() { @Override/* w ww . j ava 2s . c om*/ protected synchronized QueryParser initialValue() { return new QueryParser(Version.LUCENE_36, Config.search_default_field, analyzer); } }; File f = new File(index_path); if (!f.exists()) f.mkdir(); index = FSDirectory.open(f); try { sm = new SearcherManager(index, new SearcherFactory()); } catch (IndexNotFoundException e) { log.warn("No index found. First time use?"); create_writer(); writer.commit(); sm = new SearcherManager(index, new SearcherFactory()); } final Runnable r = new Runnable() { public void run() { try { sm.maybeRefresh(); } catch (IOException e) { log.error("maybeRefresh() error " + e); } } }; service = Executors.newScheduledThreadPool(1); alarm = service.scheduleAtFixedRate(r, 30, 30, MINUTES); }
From source file:com.foundationdb.server.service.text.Searcher.java
License:Open Source License
public Searcher(FullTextIndexShared index, Analyzer analyzer) throws IOException { this.index = index; this.searcherManager = new SearcherManager(index.open(), new SearcherFactory()); }
From source file:com.github.hotware.lucene.extension.manager.LuceneManagerImpl.java
License:BEER-WARE LICENSE
public LuceneManagerImpl(Directory directory, Scheduling scheduling) throws IOException { this.lock = new ReentrantLock(); this.beanConverter = new BeanConverterImpl(this.beanInformationCache = new BeanInformationCacheImpl()); this.directory = directory; try {//from w ww . j a v a 2 s .c o m this.searcherManager = new SearcherManager(this.directory, new SearcherFactory()); } catch (IOException e) { this.close(); throw e; } this.searcherScheduler = Executors.newScheduledThreadPool(1); this.searcherScheduler.scheduleAtFixedRate(new Runnable() { @Override public void run() { try { LuceneManagerImpl.this.searcherManager.maybeRefresh(); } catch (IOException e) { LOGGER.warning(e.toString()); } } }, scheduling.getInitialDelay(), scheduling.getPeriod(), scheduling.getUnit()); }
From source file:com.qwazr.search.bench.LuceneNoTaxonomyIndex.java
License:Apache License
public LuceneNoTaxonomyIndex(final Path rootDirectory, final String schemaName, final String indexName, final ExecutorService executorService, final double ramBufferSize, final boolean useCompoundFile) throws IOException { super(rootDirectory, schemaName, indexName, ramBufferSize, useCompoundFile); searcherManager = new SearcherManager(this.indexWriter, executorService == null ? new SearcherFactory() : new MultiThreadSearcherFactory(executorService)); }