Refine search
void setIndexReaderSearcher() throws IOException { FSDirectory index = FSDirectory.open(indexDir.toPath()); if(reader == null){ reader = DirectoryReader.open(index); searcher = new IndexSearcher(reader); }else{ DirectoryReader newreader = DirectoryReader.openIfChanged(reader); if(newreader != null) { reader.close(); reader = newreader; searcher = new IndexSearcher(reader); } } }
private LuceneSearcher(File indexDir) throws IOException { Path path = indexDir.toPath(); // symlinks are not supported here, see https://issues.apache.org/jira/browse/LUCENE-6700, // so we resolve the link ourselves: if (Files.isSymbolicLink(path)) { path = indexDir.getCanonicalFile().toPath(); } this.directory = FSDirectory.open(path); this.reader = DirectoryReader.open(directory); this.searcher = new IndexSearcher(reader); } public IndexReader getReader() {
@Override public List<Document> call() { final List<Document> localScoreDocs = new ArrayList<>(); try (final DirectoryReader directoryReader = DirectoryReader.open(FSDirectory.open(indexDirectory))) { final IndexSearcher searcher = new IndexSearcher(directoryReader); final TopDocs topDocs = searcher.search(luceneQuery, 10000000); logger.info("For {}, Top Docs has {} hits; reading Lucene results", indexDirectory, topDocs.scoreDocs.length); if (topDocs.totalHits > 0) { for (final ScoreDoc scoreDoc : topDocs.scoreDocs) { final int docId = scoreDoc.doc; final Document d = directoryReader.document(docId); localScoreDocs.add(d); } } hits.addAndGet(localScoreDocs.size()); } catch (final IndexNotFoundException e) { } catch (final IOException ioe) { throw new RuntimeException(ioe); } return localScoreDocs; } };
static synchronized void setIndexReaderSearcher() { try{ FSDirectory index = NIOFSDirectory.open(indexDir.toPath()); if(reader == null){ reader = DirectoryReader.open(index); searcher = new IndexSearcher(reader); }else{ DirectoryReader newreader = DirectoryReader.openIfChanged(reader); if(newreader != null) { reader.close(); reader = newreader; searcher = new IndexSearcher(reader); } } }catch(IOException e){ throw new RuntimeException(e); } }
/** * Search one index. This is used if no projects are set up. * @param paging whether to use paging (if yes, first X pages will load * faster) * @param root which db to search * @throws IOException */ private void searchSingleDatabase(File root, boolean paging) throws IOException { IndexReader ireader = DirectoryReader.open(FSDirectory.open(root.toPath())); searcher = new IndexSearcher(ireader); collector = TopScoreDocCollector.create(hitsPerPage * cachePages); searcher.search(query, collector); totalHits = collector.getTotalHits(); if (!paging && totalHits > 0) { collector = TopScoreDocCollector.create(totalHits); searcher.search(query, collector); } hits = collector.topDocs().scoreDocs; for (ScoreDoc hit : hits) { int docId = hit.doc; Document d = searcher.doc(docId); docs.add(d); } }
DirectoryReader.open( this.writer ) : DirectoryReader.openIfChanged( (DirectoryReader) this.reader ); if ( newReader == null ) this.reader = newReader; LuceneUtil.close( searcher ); searcher = new IndexSearcher( reader );
FulltextIndexReader getNearRealTimeReader() throws IOException { DirectoryReader directoryReader = DirectoryReader.open( writer, true ); IndexSearcher searcher = new IndexSearcher( directoryReader ); SearcherReference searcherRef = new DirectSearcherReference( searcher, directoryReader ); return new SimpleFulltextIndexReader( searcherRef, index.getPropertiesArray(), index.getAnalyzer(), index.getPropertyKeyTokenHolder() ); }
LOG.info("Built Lucene index in {} msec", elapsedTime); searcher = new IndexSearcher(DirectoryReader.open(directory)); } catch (Exception ex) { throw new RuntimeException("Lucene indexing failed.", ex);
Analyzer analyzer = new FNLPAnalyzer(Version.LUCENE_47); DirectoryReader ireader = DirectoryReader.open(dir); IndexSearcher isearcher = new IndexSearcher(ireader);
@Override public EventIndexSearcher borrowIndexSearcher(final File indexDir) throws IOException { final File absoluteFile = indexDir.getAbsoluteFile(); final IndexWriterCount writerCount; synchronized (writerCounts) { writerCount = writerCounts.remove(absoluteFile); if (writerCount != null) { // Increment writer count and create an Index Searcher based on the writer writerCounts.put(absoluteFile, new IndexWriterCount(writerCount.getWriter(), writerCount.getAnalyzer(), writerCount.getDirectory(), writerCount.getCount() + 1, writerCount.isCloseableWhenUnused())); } } final DirectoryReader directoryReader; if (writerCount == null) { logger.trace("Creating index searcher for {}", indexDir); final Directory directory = FSDirectory.open(indexDir); directoryReader = DirectoryReader.open(directory); } else { final EventIndexWriter eventIndexWriter = writerCount.getWriter(); directoryReader = DirectoryReader.open(eventIndexWriter.getIndexWriter(), false); } final IndexSearcher searcher = new IndexSearcher(directoryReader, this.searchExecutor); logger.trace("Created index searcher {} for {}", searcher, indexDir); return new LuceneEventIndexSearcher(searcher, indexDir, null, directoryReader); }
/** * Creates and loads data into an in memory index. * * @param cve the data source to retrieve the cpe data * @throws IndexException thrown if there is an error creating the index */ public synchronized void open(CveDB cve) throws IndexException { if (INSTANCE.usageCount.addAndGet(1) == 1) { index = new RAMDirectory(); buildIndex(cve); try { indexReader = DirectoryReader.open(index); } catch (IOException ex) { throw new IndexException(ex); } indexSearcher = new IndexSearcher(indexReader); searchingAnalyzer = createSearchingAnalyzer(); queryParser = new QueryParser(Fields.DOCUMENT_KEY, searchingAnalyzer); } }
private void switchToVerification() throws IOException { indexPopulator.close( true ); assertEquals( InternalIndexState.ONLINE, provider.getInitialState( index ) ); reader = DirectoryReader.open( directory ); searcher = new IndexSearcher( reader ); }
reader = DirectoryReader.open(dir); searcher = new IndexSearcher(reader); closeOnDestroy = true; } else { projects, searcherList); if (reader != null) { searcher = new IndexSearcher(reader); } else { errorMsg = "Failed to initialize search. Check the index.";
final DirectoryReader directoryReader = DirectoryReader.open(directory); final IndexSearcher searcher = new IndexSearcher(directoryReader); final EventIndexSearcher eventIndexSearcher = new LuceneEventIndexSearcher(searcher, indexDir, directory, directoryReader); final DirectoryReader directoryReader = DirectoryReader.open(writer.getIndexWriter(), false); final IndexSearcher searcher = new IndexSearcher(directoryReader); final EventIndexSearcher eventIndexSearcher = new LuceneEventIndexSearcher(searcher, indexDir, null, directoryReader);
reader = DirectoryReader.open(writer); searcher = new IndexSearcher(reader);
public void openSearchers() throws IOException { reader = DirectoryReader.open(directory); searcher = new IndexSearcher(reader); }
List<String> search(String queryStr, int hitCount) throws Exception { IndexReader reader = DirectoryReader.open(FSDirectory.open(index)); IndexSearcher searcher = new IndexSearcher(reader); Analyzer analyzer = CustomAnalyzer.builder() .withTokenizer("standard") .build(); QueryParser parser = new QueryParser("content", analyzer); Query query = parser.parse(queryStr); TopDocs results = searcher.search(query, hitCount); ScoreDoc[] hits = results.scoreDocs; List<String> result = new ArrayList<>(); for (ScoreDoc hit : hits) { Document doc = searcher.doc(hit.doc); result.add(doc.get("content")); } return result; }
public String generateRSS(Path indexFile) throws CorruptIndexException, IOException { StringBuffer output = new StringBuffer(); output.append(getRSSHeaders()); IndexSearcher searcher = null; try { reader = DirectoryReader.open(FSDirectory.open(indexFile)); searcher = new IndexSearcher(reader); GregorianCalendar gc = new java.util.GregorianCalendar(TimeZone.getDefault(), Locale.getDefault()); gc.setTime(new Date()); String nowDateTime = ISO8601.format(gc); gc.add(java.util.GregorianCalendar.MINUTE, -5); String fiveMinsAgo = ISO8601.format(gc); TermRangeQuery query = new TermRangeQuery( TikaCoreProperties.CREATED.getName(), new BytesRef(fiveMinsAgo), new BytesRef(nowDateTime), true, true); TopScoreDocCollector collector = TopScoreDocCollector.create(20); searcher.search(query, collector); ScoreDoc[] hits = collector.topDocs().scoreDocs; for (int i = 0; i < hits.length; i++) { Document doc = searcher.doc(hits[i].doc); output.append(getRSSItem(doc)); } } finally { if (reader != null) reader.close(); } output.append(getRSSFooters()); return output.toString(); }
public IndexSearcher createSearcher(Directory directory, XWikiContext context) { IndexSearcher searcher = null; try { searcher = new IndexSearcher(DirectoryReader.open(directory)); } catch (Exception e) { LOGGER.error("Faild to create IndexSearcher for Lucene index [{}]", directory, e); } return searcher; } }
public QueryExecutor(final String indexPath) throws IOException { this.reader = DirectoryReader.open(FSDirectory.open(Paths.get(indexPath))); this.searcher = new IndexSearcher(reader); this.analyzer = new StandardAnalyzer(); }