List of usage examples for org.apache.lucene.search SearcherFactory SearcherFactory
SearcherFactory
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 w w w . jav a2 s . co 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.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//from w ww . j a v a 2s . 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.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 {// ww w . j a v a2 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.google.gerrit.lucene.LuceneAccountIndex.java
License:Apache License
@Inject
LuceneAccountIndex(@GerritServerConfig Config cfg, SitePaths sitePaths, AccountCache accountCache,
@Assisted Schema<AccountState> schema) throws IOException {
super(schema, sitePaths, dir(schema, cfg, sitePaths), ACCOUNTS, null,
new GerritIndexWriterConfig(cfg, ACCOUNTS), new SearcherFactory());
this.accountCache = accountCache;
indexWriterConfig = new GerritIndexWriterConfig(cfg, ACCOUNTS);
queryBuilder = new QueryBuilder<>(schema, indexWriterConfig.getAnalyzer());
}
From source file:com.google.gerrit.lucene.LuceneChangeIndex.java
License:Apache License
private SearcherFactory newSearcherFactory() { if (useDocValuesForSorting) { return new SearcherFactory(); }//from w w w . ja v a2 s. c om @SuppressWarnings("deprecation") final Map<String, UninvertingReader.Type> mapping = ImmutableMap.of(ChangeField.LEGACY_ID.getName(), UninvertingReader.Type.INTEGER, ChangeField.UPDATED.getName(), UninvertingReader.Type.LONG); return new SearcherFactory() { @Override public IndexSearcher newSearcher(IndexReader reader, IndexReader previousReader) throws IOException { checkState(reader instanceof DirectoryReader, "expected DirectoryReader, found %s", reader.getClass().getName()); return new IndexSearcher(UninvertingReader.wrap((DirectoryReader) reader, mapping)); } }; }
From source file:com.google.gerrit.lucene.LuceneGroupIndex.java
License:Apache License
@Inject
LuceneGroupIndex(@GerritServerConfig Config cfg, SitePaths sitePaths, Provider<GroupCache> groupCache,
@Assisted Schema<AccountGroup> schema) throws IOException {
super(schema, sitePaths, dir(schema, cfg, sitePaths), GROUPS, null,
new GerritIndexWriterConfig(cfg, GROUPS), new SearcherFactory());
this.groupCache = groupCache;
indexWriterConfig = new GerritIndexWriterConfig(cfg, GROUPS);
queryBuilder = new QueryBuilder<>(schema, indexWriterConfig.getAnalyzer());
}
From source file:com.google.gerrit.lucene.WrappableSearcherManager.java
License:Apache License
/** * Creates and returns a new SearcherManager from the given * {@link IndexWriter}.//from ww w . j a v a2 s. co m * * @param writer * the IndexWriter to open the IndexReader from. * @param applyAllDeletes * If <code>true</code>, all buffered deletes will be applied (made * visible) in the {@link IndexSearcher} / {@link DirectoryReader}. * If <code>false</code>, the deletes may or may not be applied, but * remain buffered (in IndexWriter) so that they will be applied in * the future. Applying deletes can be costly, so if your app can * tolerate deleted documents being returned you might gain some * performance by passing <code>false</code>. See * {@link DirectoryReader#openIfChanged(DirectoryReader, IndexWriter, boolean)}. * @param searcherFactory * An optional {@link SearcherFactory}. Pass <code>null</code> if you * don't require the searcher to be warmed before going live or other * custom behavior. * * @throws IOException if there is a low-level I/O error */ public WrappableSearcherManager(IndexWriter writer, boolean applyAllDeletes, SearcherFactory searcherFactory) throws IOException { if (searcherFactory == null) { searcherFactory = new SearcherFactory(); } this.searcherFactory = searcherFactory; current = getSearcher(searcherFactory, DirectoryReader.open(writer, applyAllDeletes)); }
From source file:com.google.gerrit.lucene.WrappableSearcherManager.java
License:Apache License
/** * Creates and returns a new SearcherManager from the given {@link Directory}. * @param dir the directory to open the DirectoryReader on. * @param searcherFactory An optional {@link SearcherFactory}. Pass * <code>null</code> if you don't require the searcher to be warmed * before going live or other custom behavior. * * @throws IOException if there is a low-level I/O error */// ww w . ja v a 2s . c o m public WrappableSearcherManager(Directory dir, SearcherFactory searcherFactory) throws IOException { if (searcherFactory == null) { searcherFactory = new SearcherFactory(); } this.searcherFactory = searcherFactory; current = getSearcher(searcherFactory, DirectoryReader.open(dir)); }
From source file:com.google.gerrit.lucene.WrappableSearcherManager.java
License:Apache License
/** * Creates and returns a new SearcherManager from an existing {@link DirectoryReader}. Note that * this steals the incoming reference./*from w w w. jav a 2 s.com*/ * * @param reader the DirectoryReader. * @param searcherFactory An optional {@link SearcherFactory}. Pass * <code>null</code> if you don't require the searcher to be warmed * before going live or other custom behavior. * * @throws IOException if there is a low-level I/O error */ public WrappableSearcherManager(DirectoryReader reader, SearcherFactory searcherFactory) throws IOException { if (searcherFactory == null) { searcherFactory = new SearcherFactory(); } this.searcherFactory = searcherFactory; this.current = getSearcher(searcherFactory, reader); }