@Override Directory getDirectory( File baseStorePath, IndexIdentifier identifier ) { return new RAMDirectory(); }
TransactionStateLuceneIndexWriter( LuceneFulltextIndex index ) { this.index = index; directory = new RAMDirectory(); }
private void ensureLuceneDataInstantiated() { if ( this.directory == null ) { try { this.directory = new RAMDirectory(); IndexWriterConfig writerConfig = new IndexWriterConfig( index.type.analyzer ); this.writer = new IndexWriter( directory, writerConfig ); } catch ( IOException e ) { throw new RuntimeException( e ); } } }
Directory directory = new RAMDirectory(); // RAM index storage Directory directory = FSDirectory.open(new File("/path/to/index")); // disk index storage
@Override public synchronized Directory open( File dir ) { if ( !directories.containsKey( dir ) ) { directories.put( dir, new RAMDirectory() ); } return new UncloseableDirectory( directories.get( dir ) ); }
/** * Get the index writer/searcher wrapper for the given connection. * * @param conn the connection * @return the index access wrapper */ protected static IndexAccess getIndexAccess(Connection conn) throws SQLException { String path = getIndexPath(conn); synchronized (INDEX_ACCESS) { IndexAccess access = INDEX_ACCESS.get(path); if (access == null) { try { Directory indexDir = path.startsWith(IN_MEMORY_PREFIX) ? new RAMDirectory() : FSDirectory.open(new File(path)); Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_30); IndexWriterConfig conf = new IndexWriterConfig(Version.LUCENE_30, analyzer); conf.setOpenMode(IndexWriterConfig.OpenMode.CREATE_OR_APPEND); IndexWriter writer = new IndexWriter(indexDir, conf); //see http://wiki.apache.org/lucene-java/NearRealtimeSearch access = new IndexAccess(writer); } catch (IOException e) { throw convertException(e); } INDEX_ACCESS.put(path, access); } return access; } }
/** * 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); } }
RAMDirectory index_dir = new RAMDirectory(); StandardAnalyzer analyzer = new StandardAnalyzer(Version.LUCENE_48); AnalyzingInfixSuggester suggester = new AnalyzingInfixSuggester(
@Override public IndexRepository computeIndexRepository(final Integer bucketId, LuceneSerializer serializer, InternalLuceneIndex index, PartitionedRegion userRegion, IndexRepository oldRepository, PartitionedRepositoryManager partitionedRepositoryManager) throws IOException { final IndexRepository repo; if (oldRepository != null) { oldRepository.cleanup(); } LuceneRawIndex indexForRaw = (LuceneRawIndex) index; BucketRegion dataBucket = getMatchingBucket(userRegion, bucketId); Directory dir = null; if (indexForRaw.withPersistence()) { String bucketLocation = LuceneServiceImpl.getUniqueIndexName(index.getName(), index.getRegionPath() + "_" + bucketId); File location = new File(index.getName(), bucketLocation); if (!location.exists()) { location.mkdirs(); } dir = new NIOFSDirectory(location.toPath()); } else { dir = new RAMDirectory(); } IndexWriterConfig config = new IndexWriterConfig(indexForRaw.getAnalyzer()); IndexWriter writer = new IndexWriter(dir, config); return new IndexRepositoryImpl(null, writer, serializer, indexForRaw.getIndexStats(), dataBucket, null, "", indexForRaw); } }
public static IndexReader openIndexReader(FSDirectory directory, boolean RAMDirectory) throws IOException { if (RAMDirectory) return DirectoryReader.open(new RAMDirectory(directory, IOContext.READONCE)); else return DirectoryReader.open(directory); }
public static IndexReader openIndexReader(FSDirectory directory, boolean RAMDirectory) throws IOException { if (RAMDirectory) return DirectoryReader.open(new RAMDirectory(directory, IOContext.READONCE)); else return DirectoryReader.open(directory); }
@Test void samplingOfLargeNumericValues() throws Exception { try ( RAMDirectory dir = new RAMDirectory(); WritableIndexPartition indexPartition = new WritableIndexPartition( new File( "testPartition" ), dir, IndexWriterConfigs.standard() ) ) { insertDocument( indexPartition, 1, Long.MAX_VALUE ); insertDocument( indexPartition, 2, Integer.MAX_VALUE ); indexPartition.maybeRefreshBlocking(); try ( PartitionSearcher searcher = indexPartition.acquireSearcher() ) { NonUniqueLuceneIndexSampler sampler = new NonUniqueLuceneIndexSampler( searcher.getIndexSearcher(), taskControl.newInstance(), new IndexSamplingConfig( Config.defaults() ) ); assertEquals( new IndexSample( 2, 2, 2 ), sampler.sampleIndex() ); } } }
@BeforeEach void before() throws Exception { directory = new RAMDirectory(); DirectoryFactory directoryFactory = new DirectoryFactory.Single( new DirectoryFactory.UncloseableDirectory( directory ) ); provider = new LuceneIndexProvider( fs, directoryFactory, defaultDirectoryStructure( testDir.directory( "folder" ) ), IndexProvider.Monitor.EMPTY, Config.defaults(), OperationalMode.single ); indexStoreView = mock( IndexStoreView.class ); IndexSamplingConfig samplingConfig = new IndexSamplingConfig( Config.defaults() ); index = IndexDescriptorFactory.forSchema( forLabel( 42, propertyKeyId ), provider.getProviderDescriptor() ).withId( 0 ); indexPopulator = provider.getPopulator( index, samplingConfig ); indexPopulator.create(); }
RAMDirectory idx = new RAMDirectory(); IndexWriter writer = new IndexWriter( idx, new IndexWriterConfig(Version.LUCENE_40, new ClassicAnalyzer(Version.LUCENE_40)) ); Document document = new Document(); document.add(new StringField("ticket_number", "t123", Field.Store.YES)); document.add(new IntField("ticket_id", 234, Field.Store.YES)); document.add(new StringField("id_s", "234", Field.Store.YES)); writer.addDocument(document); writer.commit(); IndexReader reader = DirectoryReader.open(idx); IndexSearcher searcher = new IndexSearcher(reader); Query q1 = new TermQuery(new Term("id_s", "234")); TopDocs td1 = searcher.search(q1, 1); System.out.println(td1.totalHits); // prints "1" Query q2 = NumericRangeQuery.newIntRange("ticket_id", 1, 234, 234, true, true); TopDocs td2 = searcher.search(q2, 1); System.out.println(td2.totalHits); // prints "1"
private void openIndexes(boolean overwrite) throws IOException { if (directory == null) { try { if (path == null) directory = new RAMDirectory(); else { //directory = new MMapDirectory(new File(config.getPath())); // as per http://wiki.apache.org/lucene-java/ImproveSearchingSpeed // we use NIOFSDirectory, provided we're not on Windows if (Utils.isWindowsOS()) directory = FSDirectory.open(new File(path)); else directory = NIOFSDirectory.open(new File(path)); } IndexWriterConfig cfg = new IndexWriterConfig(Version.LUCENE_CURRENT, analyzer); cfg.setOpenMode(overwrite ? IndexWriterConfig.OpenMode.CREATE : IndexWriterConfig.OpenMode.APPEND); iwriter = new IndexWriter(directory, cfg); iwriter.commit(); // so that the searcher doesn't fail } catch (IndexNotFoundException e) { if (!overwrite) { // the index was not there, so make a new one directory = null; // ensure we really do try again openIndexes(true); } else throw new DukeException(e); } } }
public static void main(String[] args) throws Exception { Directory directory = new RAMDirectory(); Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_30); MaxFieldLength mlf = MaxFieldLength.UNLIMITED;
index = new RAMDirectory(sourceDir, IOContext.DEFAULT); index = new RAMDirectory();
private void testSearchSpeed(Class<? extends GlobalFeature> featureClass) throws IOException { ParallelIndexer parallelIndexer = new ParallelIndexer(DocumentBuilder.NUM_OF_THREADS, indexPath, testExtensive, true); parallelIndexer.addExtractor(featureClass); parallelIndexer.run(); IndexReader reader = DirectoryReader.open(new RAMDirectory(FSDirectory.open(Paths.get(indexPath)), IOContext.READONCE)); Bits liveDocs = MultiFields.getLiveDocs(reader); double queryCount = 0d; ImageSearcher searcher = new GenericFastImageSearcher(100, featureClass); long ms = System.currentTimeMillis(); String fileName; Document queryDoc; ImageSearchHits hits; for (int i = 0; i < reader.maxDoc(); i++) { if (reader.hasDeletions() && !liveDocs.get(i)) continue; // if it is deleted, just ignore it. fileName = getIDfromFileName(reader.document(i).getValues(DocumentBuilder.FIELD_NAME_IDENTIFIER)[0]); if (queries.keySet().contains(fileName)) { queryCount += 1d; // ok, we've got a query here for a document ... queryDoc = reader.document(i); hits = searcher.search(queryDoc, reader); } } ms = System.currentTimeMillis() - ms; System.out.printf("%s \t %3.1f \n", featureClass.getName().substring(featureClass.getName().lastIndexOf('.') + 1), (double) ms / queryCount); }
IndexReader reader = DirectoryReader.open(new RAMDirectory(FSDirectory.open(Paths.get(indexPath)), IOContext.READONCE)); System.out.println("Documents in the reader: " + reader.maxDoc());
IndexReader reader = DirectoryReader.open(new RAMDirectory(FSDirectory.open(Paths.get(indexPath)), IOContext.READONCE)); System.out.println("Documents in the reader: " + reader.maxDoc());