Java Code Examples for org.apache.lucene.util.Version#LUCENE_43
The following examples show how to use
org.apache.lucene.util.Version#LUCENE_43 .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SpatialTermQueryPrefixTreeStrategyFieldTypeDefinitionGeohashTest.java From incubator-retired-blur with Apache License 2.0 | 6 votes |
public void testGeoHash() throws IOException, ParseException { BaseFieldManager fieldManager = getFieldManager(new NoStopWordStandardAnalyzer()); setupGisField(fieldManager); DirectoryReader reader = DirectoryReader.open(_dir); IndexSearcher searcher = new IndexSearcher(reader); SuperParser parser = new SuperParser(Version.LUCENE_43, fieldManager, true, null, ScoreType.SUPER, new Term( BlurConstants.PRIME_DOC, BlurConstants.PRIME_DOC_VALUE)); Query query = parser.parse("fam.geo:\"GeoHash(uvgb26kqsm0)\""); TopDocs topDocs = searcher.search(query, 10); assertEquals(1, topDocs.totalHits); reader.close(); }
Example 2
Source File: AclReadFieldTypeDefinitionTest.java From incubator-retired-blur with Apache License 2.0 | 6 votes |
private void test(int expected, boolean rowQuery, Collection<String> readAuthorizations) throws IOException, ParseException { DirectoryReader reader = DirectoryReader.open(_dir); SuperParser parser = new SuperParser(Version.LUCENE_43, _fieldManager, rowQuery, null, ScoreType.SUPER, new Term( BlurConstants.PRIME_DOC, BlurConstants.PRIME_DOC_VALUE)); Query query = parser.parse("fam.string:value"); Collection<String> discoverAuthorizations = null; Set<String> discoverableFields = null; IndexSearcher searcher = new SecureIndexSearcher(reader, getAccessControlFactory(), readAuthorizations, discoverAuthorizations, discoverableFields, null); TopDocs topDocs = searcher.search(query, 10); assertEquals(expected, topDocs.totalHits); reader.close(); }
Example 3
Source File: HdfsDirectorySymlinkTest.java From incubator-retired-blur with Apache License 2.0 | 6 votes |
@Test public void testSymlinkWithIndexes() throws IOException { HdfsDirectory dir1 = new HdfsDirectory(_configuration, new Path(_base, "dir1")); IndexWriterConfig conf = new IndexWriterConfig(Version.LUCENE_43, new KeywordAnalyzer()); IndexWriter writer1 = new IndexWriter(dir1, conf.clone()); writer1.addDocument(getDoc()); writer1.close(); HdfsDirectory dir2 = new HdfsDirectory(_configuration, new Path(_base, "dir2")); IndexWriter writer2 = new IndexWriter(dir2, conf.clone()); writer2.addIndexes(dir1); writer2.close(); DirectoryReader reader1 = DirectoryReader.open(dir1); DirectoryReader reader2 = DirectoryReader.open(dir2); assertEquals(1, reader1.maxDoc()); assertEquals(1, reader2.maxDoc()); assertEquals(1, reader1.numDocs()); assertEquals(1, reader2.numDocs()); Document document1 = reader1.document(0); Document document2 = reader2.document(0); assertEquals(document1.get("id"), document2.get("id")); }
Example 4
Source File: FastHdfsKeyValueDirectoryTest.java From incubator-retired-blur with Apache License 2.0 | 6 votes |
@Test public void testMultipleWritersOpenOnSameDirectory() throws IOException { IndexWriterConfig config = new IndexWriterConfig(Version.LUCENE_43, new KeywordAnalyzer()); FastHdfsKeyValueDirectory directory = new FastHdfsKeyValueDirectory(false, _timer, _configuration, new Path(_path, "test_multiple")); IndexWriter writer1 = new IndexWriter(directory, config.clone()); addDoc(writer1, getDoc(1)); IndexWriter writer2 = new IndexWriter(directory, config.clone()); addDoc(writer2, getDoc(2)); writer1.close(); writer2.close(); DirectoryReader reader = DirectoryReader.open(directory); int maxDoc = reader.maxDoc(); assertEquals(1, maxDoc); Document document = reader.document(0); assertEquals("2", document.get("id")); reader.close(); }
Example 5
Source File: Blur024CodecTest.java From incubator-retired-blur with Apache License 2.0 | 6 votes |
@Test public void testDocValuesFormat() throws IOException { RAMDirectory directory = new RAMDirectory(); IndexWriterConfig conf = new IndexWriterConfig(Version.LUCENE_43, new WhitespaceAnalyzer(Version.LUCENE_43)); conf.setCodec(new Blur024Codec()); IndexWriter writer = new IndexWriter(directory, conf); Document doc = new Document(); doc.add(new StringField("f", "v", Store.YES)); doc.add(new SortedDocValuesField("f", new BytesRef("v"))); writer.addDocument(doc); writer.close(); DirectoryReader reader = DirectoryReader.open(directory); AtomicReaderContext context = reader.leaves().get(0); AtomicReader atomicReader = context.reader(); SortedDocValues sortedDocValues = atomicReader.getSortedDocValues("f"); assertTrue(sortedDocValues.getClass().getName().startsWith(DiskDocValuesProducer.class.getName())); reader.close(); }
Example 6
Source File: TableShardCountCollapserTest.java From incubator-retired-blur with Apache License 2.0 | 6 votes |
private static void createShard(Configuration configuration, int i, Path path, int totalShardCount) throws IOException { HdfsDirectory hdfsDirectory = new HdfsDirectory(configuration, path); IndexWriterConfig conf = new IndexWriterConfig(Version.LUCENE_43, new KeywordAnalyzer()); TieredMergePolicy mergePolicy = (TieredMergePolicy) conf.getMergePolicy(); mergePolicy.setUseCompoundFile(false); IndexWriter indexWriter = new IndexWriter(hdfsDirectory, conf); Partitioner<IntWritable, IntWritable> partitioner = new HashPartitioner<IntWritable, IntWritable>(); int partition = partitioner.getPartition(new IntWritable(i), null, totalShardCount); assertEquals(i, partition); Document doc = getDoc(i); indexWriter.addDocument(doc); indexWriter.close(); }
Example 7
Source File: BlurIndexWriterTest.java From incubator-retired-blur with Apache License 2.0 | 5 votes |
private Directory addDir(String v) throws IOException { RAMDirectory directory = new RAMDirectory(); IndexWriterConfig config = new IndexWriterConfig(Version.LUCENE_43, new KeywordAnalyzer()); IndexWriter writer = new IndexWriter(directory, config); writer.addDocument(getDoc(v)); writer.close(); return directory; }
Example 8
Source File: FilterCacheTest.java From incubator-retired-blur with Apache License 2.0 | 5 votes |
private void writeDocs(FilterCache filterCache, RAMDirectory directory) throws IOException { IndexWriterConfig conf = new IndexWriterConfig(Version.LUCENE_43, new KeywordAnalyzer()); conf.setCodec(new Blur024Codec()); IndexWriter indexWriter = new IndexWriter(directory, conf); int count = 10000; addDocs(indexWriter, count); indexWriter.close(); }
Example 9
Source File: CacheDirectoryTest.java From incubator-retired-blur with Apache License 2.0 | 5 votes |
@Test public void test3() throws IOException, InterruptedException { // Thread.sleep(30000); IndexWriterConfig conf = new IndexWriterConfig(Version.LUCENE_43, new KeywordAnalyzer()); IndexWriter writer = new IndexWriter(_cacheDirectory, conf); int docs = 100000; for (int i = 0; i < docs; i++) { if (i % 500 == 0) { System.out.println(i); } writer.addDocument(newDoc()); // Thread.sleep(1); } writer.close(); System.out.println("done writing"); DirectoryReader reader = DirectoryReader.open(_cacheDirectory); System.out.println("done opening"); assertEquals(docs, reader.numDocs()); Document document = reader.document(0); System.out.println("done fetching"); System.out.println(document); IndexSearcher searcher = new IndexSearcher(reader); TopDocs topDocs = searcher.search(new TermQuery(new Term("test", "test")), 10); System.out.println("done searching"); assertEquals(docs, topDocs.totalHits); reader.close(); }
Example 10
Source File: BlurSecureIndexSearcherTest.java From incubator-retired-blur with Apache License 2.0 | 5 votes |
private IndexReader getIndexReader() throws IOException { IndexWriterConfig conf = new IndexWriterConfig(Version.LUCENE_43, new KeywordAnalyzer()); Directory dir = new RAMDirectory(); IndexWriter writer = new IndexWriter(dir, conf); writer.close(); return DirectoryReader.open(dir); }
Example 11
Source File: CoreTestContext.java From incubator-retired-blur with Apache License 2.0 | 5 votes |
/** * Index will contain 26 documents with the following column/values: alpha = * double-letter a-z (lowercase characters); num = 0-25 val = val (constant * across all docs) * * New columns may be added so don't rely on the column count in tests. * * @return */ public static IndexContext newSimpleAlpaNumContext() { CoreTestContext ctx = new CoreTestContext(); IndexWriterConfig conf = new IndexWriterConfig(Version.LUCENE_43, new StandardAnalyzer(Version.LUCENE_43)); try { IndexWriter writer = new IndexWriter(ctx.directory, conf); for (int i = 0; i < 26; i++) { String alpha = new Character((char) (97 + i)).toString(); Document doc = new Document(); doc.add(new Field("id", Integer.toString(i), TextField.TYPE_STORED)); doc.add(new Field("alpha", alpha + alpha, TextField.TYPE_STORED)); doc.add(new Field("num", Integer.toString(i), TextField.TYPE_STORED)); doc.add(new Field("val", "val", TextField.TYPE_STORED)); writer.addDocument(doc); writer.commit(); } writer.commit(); writer.close(); } catch (IOException e) { throw new RuntimeException("Unable to create test context.", e); } return ctx; }
Example 12
Source File: PrimeDocOverFlowHelper.java From incubator-retired-blur with Apache License 2.0 | 5 votes |
private static Directory getDirectoryUpdateRow(String currentRowId) { try { RAMDirectory directoryUpdateRow = new RAMDirectory(); IndexWriter writer = new IndexWriter(directoryUpdateRow, new IndexWriterConfig(Version.LUCENE_43, new KeywordAnalyzer())); Document document = new Document(); document.add(new StringField(BlurConstants.PRIME_DOC, BlurConstants.PRIME_DOC_VALUE, Store.NO)); document.add(new StringField(BlurConstants.UPDATE_ROW, currentRowId, Store.NO)); writer.addDocument(document); writer.close(); return directoryUpdateRow; } catch (Exception e) { throw new RuntimeException(e); } }
Example 13
Source File: SecureAtomicReaderTestBase.java From incubator-retired-blur with Apache License 2.0 | 5 votes |
private DirectoryReader createReader() throws IOException { IndexWriterConfig conf = new IndexWriterConfig(Version.LUCENE_43, new KeywordAnalyzer()); Directory dir = new RAMDirectory(); IndexWriter writer = new IndexWriter(dir, conf); AccessControlWriter accessControlWriter = getAccessControlFactory().getWriter(); addDoc(writer, accessControlWriter, "r1", "d1", 0); addDoc(writer, accessControlWriter, "r2", "d1", 1); addDoc(writer, accessControlWriter, "r1", "d2", 2); addDoc(writer, accessControlWriter, "r2", "d2", 3); addDoc(writer, accessControlWriter, "r1", "d1", 4, "test"); addDoc(writer, accessControlWriter, "r1", "d1", 5, "termmask"); writer.close(); return DirectoryReader.open(dir); }
Example 14
Source File: LoadTest.java From incubator-retired-blur with Apache License 2.0 | 5 votes |
private static void createIndex(Directory directory, AccessControlFactory accessControlFactory) throws IOException { IndexWriterConfig conf = new IndexWriterConfig(Version.LUCENE_43, new KeywordAnalyzer()); IndexWriter writer = new IndexWriter(directory, conf); AccessControlWriter accessControlWriter = accessControlFactory.getWriter(); Random random = new Random(1); for (long i = 0; i < MAX_DOCS; i++) { if (i % 1000000 == 0) { System.out.println("Building " + i); } writer.addDocument(accessControlWriter.addDiscoverVisiblity("d1", accessControlWriter.addReadVisiblity("r1", getDoc(i, random)))); } writer.close(); }
Example 15
Source File: AclDiscoverFieldTypeDefinitionTest.java From incubator-retired-blur with Apache License 2.0 | 5 votes |
private void test(int expected, boolean rowQuery, Collection<String> discoverAuthorizations) throws IOException, ParseException { DirectoryReader reader = DirectoryReader.open(_dir); SuperParser parser = new SuperParser(Version.LUCENE_43, _fieldManager, rowQuery, null, ScoreType.SUPER, new Term( BlurConstants.PRIME_DOC, BlurConstants.PRIME_DOC_VALUE)); Query query = parser.parse("fam.string:value"); Collection<String> readAuthorizations = null; Set<String> discoverableFields = new HashSet<String>(); discoverableFields.add("rowid"); discoverableFields.add("recordid"); discoverableFields.add("family"); IndexSearcher searcher = new SecureIndexSearcher(reader, getAccessControlFactory(), readAuthorizations, discoverAuthorizations, discoverableFields, null); TopDocs topDocs = searcher.search(query, 10); assertEquals(expected, topDocs.totalHits); for (int i = 0; i < expected; i++) { int doc = topDocs.scoreDocs[i].doc; Document document = searcher.doc(doc); List<IndexableField> fields = document.getFields(); for (IndexableField field : fields) { assertTrue(discoverableFields.contains(field.name())); } } reader.close(); }
Example 16
Source File: Blur024CodecTest.java From incubator-retired-blur with Apache License 2.0 | 4 votes |
@Test public void testSmallDocs() throws IOException { RAMDirectory directory = new RAMDirectory(); IndexWriterConfig conf1 = new IndexWriterConfig(Version.LUCENE_43, new WhitespaceAnalyzer(Version.LUCENE_43)); conf1.setCodec(new Blur024Codec()); Random random1 = new Random(1); IndexWriter writer1 = new IndexWriter(directory, conf1); for (int i = 0; i < 1000; i++) { writer1.addDocument(getSmallDoc(random1)); } writer1.close(); DirectoryReader reader1 = DirectoryReader.open(directory); int numDocs1 = reader1.numDocs(); assertEquals(1000, numDocs1); // for (int i = 0; i < numDocs1; i++) { // System.out.println(reader1.document(i)); // } IndexWriterConfig conf2 = new IndexWriterConfig(Version.LUCENE_43, new WhitespaceAnalyzer(Version.LUCENE_43)); conf2.setCodec(new Blur024Codec(1 << 16, CompressionMode.HIGH_COMPRESSION)); Random random2 = new Random(1); IndexWriter writer2 = new IndexWriter(directory, conf2); for (int i = 0; i < 1000; i++) { writer2.addDocument(getSmallDoc(random2)); } writer2.close(); DirectoryReader reader2 = DirectoryReader.open(directory); int numDocs2 = reader2.numDocs(); assertEquals(2000, numDocs2); for (int i = 0; i < 2; i++) { long t1 = System.nanoTime(); long hash1 = 0; long hash2 = 0; for (int d = 0; d < 1000; d++) { Document document1 = reader1.document(d); hash1 += document1.hashCode(); } long t2 = System.nanoTime(); for (int d = 0; d < 1000; d++) { Document document2 = reader2.document(d + 1000); hash2 += document2.hashCode(); } long t3 = System.nanoTime(); System.out.println((t3 - t2) / 1000000.0); System.out.println((t2 - t1) / 1000000.0); System.out.println("doc1 " + hash1); System.out.println("doc2 " + hash2); } // for (int i = 0; i < numDocs2; i++) { // System.out.println(reader2.document(i)); // } // long fileLength = directory.fileLength("_0.fdt"); for (String name : directory.listAll()) { if (name.endsWith(".fdt")) { System.out.println(name); System.out.println(directory.fileLength(name)); } } }
Example 17
Source File: Blur022CodecTest.java From incubator-retired-blur with Apache License 2.0 | 4 votes |
@Test public void testLargeDocs() throws IOException { Random random = new Random(); Iterable<? extends IndexableField> doc = getLargeDoc(random); RAMDirectory directory = new RAMDirectory(); IndexWriterConfig conf1 = new IndexWriterConfig(Version.LUCENE_43, new WhitespaceAnalyzer(Version.LUCENE_43)); conf1.setCodec(new Blur022Codec()); IndexWriter writer1 = new IndexWriter(directory, conf1); writer1.addDocument(doc); writer1.close(); DirectoryReader reader1 = DirectoryReader.open(directory); int numDocs1 = reader1.numDocs(); assertEquals(1, numDocs1); // for (int i = 0; i < numDocs1; i++) { // System.out.println(reader1.document(i)); // } IndexWriterConfig conf2 = new IndexWriterConfig(Version.LUCENE_43, new WhitespaceAnalyzer(Version.LUCENE_43)); conf2.setCodec(new Blur022Codec(1 << 16, CompressionMode.HIGH_COMPRESSION)); IndexWriter writer2 = new IndexWriter(directory, conf2); writer2.addDocument(doc); writer2.close(); DirectoryReader reader2 = DirectoryReader.open(directory); int numDocs2 = reader2.numDocs(); assertEquals(2, numDocs2); for (int i = 0; i < 2; i++) { long t1 = System.nanoTime(); Document document1 = reader1.document(0); long t2 = System.nanoTime(); Document document2 = reader2.document(1); long t3 = System.nanoTime(); System.out.println((t3 - t2) / 1000000.0); System.out.println((t2 - t1) / 1000000.0); System.out.println("doc1 " + document1.hashCode()); System.out.println("doc2 " + document2.hashCode()); } // for (int i = 0; i < numDocs2; i++) { // System.out.println(reader2.document(i)); // } // long fileLength = directory.fileLength("_0.fdt"); for (String name : directory.listAll()) { if (name.endsWith(".fdt")) { System.out.println(name); System.out.println(directory.fileLength(name)); } } }
Example 18
Source File: Blur022CodecTest.java From incubator-retired-blur with Apache License 2.0 | 4 votes |
@Test public void testSmallDocs() throws IOException { RAMDirectory directory = new RAMDirectory(); IndexWriterConfig conf1 = new IndexWriterConfig(Version.LUCENE_43, new WhitespaceAnalyzer(Version.LUCENE_43)); conf1.setCodec(new Blur022Codec()); Random random1 = new Random(1); IndexWriter writer1 = new IndexWriter(directory, conf1); for (int i = 0; i < 1000; i++) { writer1.addDocument(getSmallDoc(random1)); } writer1.close(); DirectoryReader reader1 = DirectoryReader.open(directory); int numDocs1 = reader1.numDocs(); assertEquals(1000, numDocs1); // for (int i = 0; i < numDocs1; i++) { // System.out.println(reader1.document(i)); // } IndexWriterConfig conf2 = new IndexWriterConfig(Version.LUCENE_43, new WhitespaceAnalyzer(Version.LUCENE_43)); conf2.setCodec(new Blur022Codec(1 << 16, CompressionMode.HIGH_COMPRESSION)); Random random2 = new Random(1); IndexWriter writer2 = new IndexWriter(directory, conf2); for (int i = 0; i < 1000; i++) { writer2.addDocument(getSmallDoc(random2)); } writer2.close(); DirectoryReader reader2 = DirectoryReader.open(directory); int numDocs2 = reader2.numDocs(); assertEquals(2000, numDocs2); for (int i = 0; i < 2; i++) { long t1 = System.nanoTime(); long hash1 = 0; long hash2 = 0; for (int d = 0; d < 1000; d++) { Document document1 = reader1.document(d); hash1 += document1.hashCode(); } long t2 = System.nanoTime(); for (int d = 0; d < 1000; d++) { Document document2 = reader2.document(d + 1000); hash2 += document2.hashCode(); } long t3 = System.nanoTime(); System.out.println((t3 - t2) / 1000000.0); System.out.println((t2 - t1) / 1000000.0); System.out.println("doc1 " + hash1); System.out.println("doc2 " + hash2); } // for (int i = 0; i < numDocs2; i++) { // System.out.println(reader2.document(i)); // } // long fileLength = directory.fileLength("_0.fdt"); for (String name : directory.listAll()) { if (name.endsWith(".fdt")) { System.out.println(name); System.out.println(directory.fileLength(name)); } } }
Example 19
Source File: FastHdfsKeyValueDirectoryTest.java From incubator-retired-blur with Apache License 2.0 | 4 votes |
@Test public void testMulipleCommitsAndReopens() throws IOException { IndexWriterConfig conf = new IndexWriterConfig(Version.LUCENE_43, new KeywordAnalyzer()); conf.setMergeScheduler(new SerialMergeScheduler()); TieredMergePolicy mergePolicy = (TieredMergePolicy) conf.getMergePolicy(); mergePolicy.setUseCompoundFile(false); Set<String> fileSet = new TreeSet<String>(); long seed = new Random().nextLong(); System.out.println("Seed:" + seed); Random random = new Random(seed); int docCount = 0; int passes = 10; byte[] segmentsGenContents = null; for (int run = 0; run < passes; run++) { final FastHdfsKeyValueDirectory directory = new FastHdfsKeyValueDirectory(false, _timer, _configuration, new Path(_path, "test_multiple_commits_reopens")); if (segmentsGenContents != null) { byte[] segmentsGenContentsCurrent = readSegmentsGen(directory); assertTrue(Arrays.equals(segmentsGenContents, segmentsGenContentsCurrent)); } assertFiles(fileSet, run, -1, directory); assertEquals(docCount, getDocumentCount(directory)); IndexWriter writer = new IndexWriter(directory, conf.clone()); int numberOfCommits = random.nextInt(100); for (int i = 0; i < numberOfCommits; i++) { assertFiles(fileSet, run, i, directory); addDocuments(writer, random.nextInt(100)); // Before Commit writer.commit(); // After Commit // Set files after commit { fileSet.clear(); List<IndexCommit> listCommits = DirectoryReader.listCommits(directory); assertEquals(1, listCommits.size()); IndexCommit indexCommit = listCommits.get(0); fileSet.addAll(indexCommit.getFileNames()); } segmentsGenContents = readSegmentsGen(directory); } docCount = getDocumentCount(directory); } }
Example 20
Source File: BaseSpatialFieldTypeDefinitionTest.java From incubator-retired-blur with Apache License 2.0 | 3 votes |
public void runGisTypeTest() throws IOException, ParseException { BaseFieldManager fieldManager = getFieldManager(new NoStopWordStandardAnalyzer()); setupGisField(fieldManager); Record record = new Record(); record.setFamily("fam"); record.setRecordId("1234"); record.addToColumns(new Column("geo", "77.4011984,39.040444")); List<Field> fields = fieldManager.getFields("1234", record); IndexWriterConfig conf = new IndexWriterConfig(Version.LUCENE_43, fieldManager.getAnalyzerForIndex()); IndexWriter writer = new IndexWriter(_dir, conf); fields.add(new StringField(BlurConstants.PRIME_DOC, BlurConstants.PRIME_DOC_VALUE, Store.NO)); writer.addDocument(fields); writer.close(); DirectoryReader reader = DirectoryReader.open(_dir); IndexSearcher searcher = new IndexSearcher(reader); SuperParser parser = new SuperParser(Version.LUCENE_43, fieldManager, true, null, ScoreType.SUPER, new Term( BlurConstants.PRIME_DOC, BlurConstants.PRIME_DOC_VALUE)); Query query = parser.parse("fam.geo:\"Intersects(Circle(77.4011984,39.040444 d=10.0m))\""); TopDocs topDocs = searcher.search(query, 10); assertEquals(1, topDocs.totalHits); reader.close(); }