List of usage examples for org.apache.lucene.store ByteBuffersDirectory ByteBuffersDirectory
public ByteBuffersDirectory()
From source file:org.apereo.portal.index.IndexConfiguration.java
License:Apache License
@Bean(destroyMethod = "close") public Directory directory() throws IOException { final String realPath = servletContext != null ? servletContext.getRealPath(relativePath) : null; return realPath != null ? FSDirectory.open(Paths.get(realPath)) : new ByteBuffersDirectory(); // Disables indexing }
From source file:org.opengrok.suggest.query.customized.CustomSloppyPhraseScorerTest.java
License:Open Source License
@SuppressWarnings("unchecked") // for contains() public static void test(final int slop, final int offset, final String[] terms, final Integer[] expectedPositions) throws IOException { Directory dir = new ByteBuffersDirectory(); try (IndexWriter iw = new IndexWriter(dir, new IndexWriterConfig())) { Document doc = new Document(); doc.add(new TextField("test", "zero one two three four five six seven eight nine ten", Field.Store.NO)); iw.addDocument(doc);/*from ww w .j a v a 2 s.c o m*/ } CustomPhraseQuery query = new CustomPhraseQuery(slop, "test", terms); query.offset = offset; try (IndexReader ir = DirectoryReader.open(dir)) { IndexSearcher is = new IndexSearcher(ir); Weight w = query.createWeight(is, false, 1); LeafReaderContext context = ir.getContext().leaves().get(0); Scorer scorer = w.scorer(context); TwoPhaseIterator it = scorer.twoPhaseIterator(); int correctDoc = -1; int docId; while ((docId = it.approximation().nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) { if (it.matches()) { correctDoc = docId; } } BitIntsHolder bs = (BitIntsHolder) ((PhraseScorer) scorer).getPositions(correctDoc); assertThat(toSet(bs), contains(expectedPositions)); } }
From source file:org.opengrok.suggest.SuggesterProjectDataTest.java
License:Open Source License
@Before public void setUp() throws IOException { dir = new ByteBuffersDirectory(); tempDir = Files.createTempDirectory("test"); }
From source file:org.opengrok.suggest.SuggesterProjectDataTest.java
License:Open Source License
@Test public void testRemove() throws IOException { Directory dir = new ByteBuffersDirectory(); Path tempDir = Files.createTempDirectory("test"); try (IndexWriter iw = new IndexWriter(dir, new IndexWriterConfig())) { Document doc = new Document(); doc.add(new TextField("test", "text", Field.Store.NO)); iw.addDocument(doc);//from w w w.ja v a 2 s .c o m } SuggesterProjectData data = new SuggesterProjectData(dir, tempDir, false, Collections.singleton("test")); data.init(); data.remove(); assertFalse(tempDir.toFile().exists()); }
From source file:org.opengrok.suggest.SuggesterSearcherTest.java
License:Open Source License
@BeforeClass public static void setUpClass() throws IOException { dir = new ByteBuffersDirectory(); try (IndexWriter iw = new IndexWriter(dir, new IndexWriterConfig())) { Document doc1 = new Document(); Document doc2 = new Document(); doc1.add(new TextField("test", "opengrok opengrok2", Field.Store.NO)); doc2.add(new TextField("test", "opengrok test", Field.Store.NO)); iw.addDocument(doc1);/*from w w w .ja v a 2 s . c o m*/ iw.addDocument(doc2); } IndexReader ir = DirectoryReader.open(dir); searcher = new SuggesterSearcher(ir, 10); }