org.apache.lucene.document.IntPoint Java Examples
The following examples show how to use
org.apache.lucene.document.IntPoint.
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: AbstractLuceneQueryVisitorTest.java From cxf with Apache License 2.0 | 7 votes |
@Before public void setUp() throws Exception { analyzer = new StandardAnalyzer(); tempDirectory = Files.createTempDirectory("lucene"); directory = new MMapDirectory(tempDirectory); IndexWriterConfig config = new IndexWriterConfig(analyzer); IndexWriter iwriter = new IndexWriter(directory, config); Document doc = new Document(); doc.add(new Field("contents", "name=text", TextField.TYPE_STORED)); IntPoint intPoint = new IntPoint("intfield", 4); doc.add(intPoint); doc.add(new StoredField("intfield", 4)); iwriter.addDocument(doc); iwriter.close(); ireader = DirectoryReader.open(directory); isearcher = new IndexSearcher(ireader); }
Example #2
Source File: TestPointValues.java From lucene-solr with Apache License 2.0 | 6 votes |
public void testMergedStatsOneSegmentWithoutPoints() throws IOException { Directory dir = new ByteBuffersDirectory(); IndexWriter w = new IndexWriter(dir, new IndexWriterConfig(null).setMergePolicy(NoMergePolicy.INSTANCE)); w.addDocument(new Document()); DirectoryReader.open(w).close(); Document doc = new Document(); doc.add(new IntPoint("field", Integer.MIN_VALUE)); w.addDocument(doc); IndexReader reader = DirectoryReader.open(w); assertArrayEquals(new byte[4], PointValues.getMinPackedValue(reader, "field")); assertArrayEquals(new byte[4], PointValues.getMaxPackedValue(reader, "field")); assertEquals(1, PointValues.getDocCount(reader, "field")); assertEquals(1, PointValues.size(reader, "field")); assertNull(PointValues.getMinPackedValue(reader, "field2")); assertNull(PointValues.getMaxPackedValue(reader, "field2")); assertEquals(0, PointValues.getDocCount(reader, "field2")); assertEquals(0, PointValues.size(reader, "field2")); }
Example #3
Source File: DocMaker.java From lucene-solr with Apache License 2.0 | 6 votes |
public DocState(boolean reuseFields, FieldType ft, FieldType bodyFt) { this.reuseFields = reuseFields; if (reuseFields) { fields = new HashMap<>(); numericFields = new HashMap<>(); // Initialize the map with the default fields. fields.put(BODY_FIELD, new Field(BODY_FIELD, "", bodyFt)); fields.put(TITLE_FIELD, new Field(TITLE_FIELD, "", ft)); fields.put(DATE_FIELD, new Field(DATE_FIELD, "", ft)); fields.put(ID_FIELD, new StringField(ID_FIELD, "", Field.Store.YES)); fields.put(NAME_FIELD, new Field(NAME_FIELD, "", ft)); numericFields.put(DATE_MSEC_FIELD, new LongPoint(DATE_MSEC_FIELD, 0L)); numericFields.put(TIME_SEC_FIELD, new IntPoint(TIME_SEC_FIELD, 0)); doc = new Document(); } else { numericFields = null; fields = null; doc = null; } }
Example #4
Source File: HighlighterTest.java From lucene-solr with Apache License 2.0 | 6 votes |
public void testDimensionalRangeQuery() throws Exception { // doesn't currently highlight, but make sure it doesn't cause exception either query = IntPoint.newRangeQuery(NUMERIC_FIELD_NAME, 2, 6); searcher = newSearcher(reader); hits = searcher.search(query, 100); int maxNumFragmentsRequired = 2; QueryScorer scorer = new QueryScorer(query, FIELD_NAME); Highlighter highlighter = new Highlighter(this, scorer); for (int i = 0; i < hits.totalHits.value; i++) { String text = searcher.doc(hits.scoreDocs[i].doc).getField(NUMERIC_FIELD_NAME).numericValue().toString(); TokenStream tokenStream = analyzer.tokenStream(FIELD_NAME, text); highlighter.setTextFragmenter(new SimpleFragmenter(40)); // String result = highlighter.getBestFragments(tokenStream, text, maxNumFragmentsRequired,"..."); //if (VERBOSE) System.out.println("\t" + result); } }
Example #5
Source File: SimpleDocumentWriter.java From dremio-oss with Apache License 2.0 | 6 votes |
void addToDoc(IndexKey key, Integer value){ Preconditions.checkArgument(key.getValueType() == Integer.class); if(value == null){ return; } checkIfMultiValueField(key); final String indexFieldName = key.getIndexFieldName(); doc.add(new IntPoint(indexFieldName, value)); if (key.isStored()) { doc.add(new StoredField(indexFieldName, value)); } if (key.isSorted()) { Preconditions.checkArgument(key.getSortedValueType() == SearchFieldSorting.FieldType.INTEGER); doc.add(new NumericDocValuesField(indexFieldName, value)); } }
Example #6
Source File: TestMemoryIndex.java From lucene-solr with Apache License 2.0 | 6 votes |
public void testMultiValuedPointsSortedCorrectly() throws Exception { Document doc = new Document(); doc.add(new IntPoint("ints", 3)); doc.add(new IntPoint("ints", 2)); doc.add(new IntPoint("ints", 1)); doc.add(new LongPoint("longs", 3L)); doc.add(new LongPoint("longs", 2L)); doc.add(new LongPoint("longs", 1L)); doc.add(new FloatPoint("floats", 3F)); doc.add(new FloatPoint("floats", 2F)); doc.add(new FloatPoint("floats", 1F)); doc.add(new DoublePoint("doubles", 3D)); doc.add(new DoublePoint("doubles", 2D)); doc.add(new DoublePoint("doubles", 1D)); MemoryIndex mi = MemoryIndex.fromDocument(doc, analyzer); IndexSearcher s = mi.createSearcher(); assertEquals(1, s.count(IntPoint.newSetQuery("ints", 2))); assertEquals(1, s.count(LongPoint.newSetQuery("longs", 2))); assertEquals(1, s.count(FloatPoint.newSetQuery("floats", 2))); assertEquals(1, s.count(DoublePoint.newSetQuery("doubles", 2))); }
Example #7
Source File: PointMerger.java From lucene-solr with Apache License 2.0 | 6 votes |
@Override public void visit(int docID, byte[] packedValue) throws IOException { // TODO: handle filter or deleted documents? int v = IntPoint.decodeDimension(packedValue, 0); if (v < last) return; if (v == last && pos >= 0) { count[pos]++; } else { if (pos+1 < values.length) { last = v; ++pos; values[pos] = v; count[pos] = 1; } else { // a new value we don't have room for throw breakException; } } }
Example #8
Source File: LuceneQueryTestCase.java From jstarcraft-core with Apache License 2.0 | 6 votes |
@Test public void testPointExactQuery() throws Exception { // 精确查询 Query exactQuery = IntPoint.newExactQuery("id", 1); TopDocs search = searcher.search(exactQuery, 1000); Assert.assertEquals(1, search.totalHits.value); }
Example #9
Source File: IntPointField.java From lucene-solr with Apache License 2.0 | 6 votes |
@Override public Query getPointRangeQuery(QParser parser, SchemaField field, String min, String max, boolean minInclusive, boolean maxInclusive) { int actualMin, actualMax; if (min == null) { actualMin = Integer.MIN_VALUE; } else { actualMin = parseIntFromUser(field.getName(), min); if (!minInclusive) { if (actualMin == Integer.MAX_VALUE) return new MatchNoDocsQuery(); actualMin++; } } if (max == null) { actualMax = Integer.MAX_VALUE; } else { actualMax = parseIntFromUser(field.getName(), max); if (!maxInclusive) { if (actualMax == Integer.MIN_VALUE) return new MatchNoDocsQuery(); actualMax--; } } return IntPoint.newRangeQuery(field.getName(), actualMin, actualMax); }
Example #10
Source File: IntQuery.java From HongsCORE with MIT License | 6 votes |
@Override public Query whr(String k, Object n, Object x, boolean l, boolean g) { if (n == null && x == null) { throw new NullPointerException("Range for "+k+" must be number, but null"); } int n2, x2; if (n == null || "".equals(n)) { n2 = Integer.MIN_VALUE; } else { n2 = Synt.asInt(n); if (!l) { n2 = n2 + 1; } } if (x == null || "".equals(x)) { x2 = Integer.MAX_VALUE; } else { x2 = Synt.asInt(x); if (!g) { x2 = x2 - 1; } } Query q2 = IntPoint.newRangeQuery("@"+k, n2, x2); return q2; }
Example #11
Source File: TestPointValues.java From lucene-solr with Apache License 2.0 | 6 votes |
public void testIllegalTooManyDimensions() throws Exception { Directory dir = newDirectory(); IndexWriterConfig iwc = new IndexWriterConfig(new MockAnalyzer(random())); IndexWriter w = new IndexWriter(dir, iwc); Document doc = new Document(); byte[][] values = new byte[PointValues.MAX_INDEX_DIMENSIONS +1][]; for(int i=0;i<values.length;i++) { values[i] = new byte[4]; } expectThrows(IllegalArgumentException.class, () -> { doc.add(new BinaryPoint("dim", values)); }); Document doc2 = new Document(); doc2.add(new IntPoint("dim", 17)); w.addDocument(doc2); w.close(); dir.close(); }
Example #12
Source File: CoreParserTestIndexData.java From lucene-solr with Apache License 2.0 | 6 votes |
CoreParserTestIndexData(Analyzer analyzer) throws Exception { BufferedReader d = new BufferedReader(new InputStreamReader( TestCoreParser.class.getResourceAsStream("reuters21578.txt"), StandardCharsets.US_ASCII)); dir = LuceneTestCase.newDirectory(); IndexWriter writer = new IndexWriter(dir, LuceneTestCase.newIndexWriterConfig(analyzer)); String line = d.readLine(); while (line != null) { int endOfDate = line.indexOf('\t'); String date = line.substring(0, endOfDate).trim(); String content = line.substring(endOfDate).trim(); Document doc = new Document(); doc.add(LuceneTestCase.newTextField("date", date, Field.Store.YES)); doc.add(LuceneTestCase.newTextField("contents", content, Field.Store.YES)); doc.add(new IntPoint("date3", Integer.parseInt(date))); writer.addDocument(doc); line = d.readLine(); } d.close(); writer.close(); reader = DirectoryReader.open(dir); searcher = LuceneTestCase.newSearcher(reader, false); }
Example #13
Source File: TestPointQueries.java From lucene-solr with Apache License 2.0 | 6 votes |
public void testPointInSetQueryToString() throws Exception { // int assertEquals("int:{-42 18}", IntPoint.newSetQuery("int", -42, 18).toString()); // long assertEquals("long:{-42 18}", LongPoint.newSetQuery("long", -42L, 18L).toString()); // float assertEquals("float:{-42.0 18.0}", FloatPoint.newSetQuery("float", -42.0f, 18.0f).toString()); // double assertEquals("double:{-42.0 18.0}", DoublePoint.newSetQuery("double", -42.0, 18.0).toString()); // binary assertEquals("bytes:{[12] [2a]}", BinaryPoint.newSetQuery("bytes", new byte[] {42}, new byte[] {18}).toString()); }
Example #14
Source File: TestPointQueries.java From lucene-solr with Apache License 2.0 | 6 votes |
public void testEmptyPointInSetQuery() throws Exception { Directory dir = newDirectory(); IndexWriterConfig iwc = newIndexWriterConfig(); iwc.setCodec(getCodec()); IndexWriter w = new IndexWriter(dir, iwc); Document doc = new Document(); doc.add(new IntPoint("int", 17)); doc.add(new LongPoint("long", 17L)); doc.add(new FloatPoint("float", 17.0f)); doc.add(new DoublePoint("double", 17.0)); doc.add(new BinaryPoint("bytes", new byte[] {0, 17})); w.addDocument(doc); IndexReader r = DirectoryReader.open(w); IndexSearcher s = newSearcher(r, false); assertEquals(0, s.count(IntPoint.newSetQuery("int"))); assertEquals(0, s.count(LongPoint.newSetQuery("long"))); assertEquals(0, s.count(FloatPoint.newSetQuery("float"))); assertEquals(0, s.count(DoublePoint.newSetQuery("double"))); assertEquals(0, s.count(BinaryPoint.newSetQuery("bytes"))); w.close(); r.close(); dir.close(); }
Example #15
Source File: LuceneQueryVisitor.java From cxf with Apache License 2.0 | 6 votes |
private Query createIntRangeQuery(final String name, final Object value, final ConditionType type, final boolean minInclusive, final boolean maxInclusive) { final Integer intValue = Integer.valueOf(value.toString()); Integer min = getMin(type, intValue); if (min == null) { min = Integer.MIN_VALUE; } else if (!minInclusive) { min = Math.addExact(min, 1); } Integer max = getMax(type, intValue); if (max == null) { max = Integer.MAX_VALUE; } else if (!maxInclusive) { max = Math.addExact(max, -1); } return IntPoint.newRangeQuery(name, min, max); }
Example #16
Source File: TestMatchesIterator.java From lucene-solr with Apache License 2.0 | 6 votes |
@Override public void setUp() throws Exception { super.setUp(); directory = newDirectory(); RandomIndexWriter writer = new RandomIndexWriter(random(), directory, newIndexWriterConfig(new MockAnalyzer(random())).setMergePolicy(newLogMergePolicy())); for (int i = 0; i < docFields.length; i++) { Document doc = new Document(); doc.add(newField(FIELD_WITH_OFFSETS, docFields[i], OFFSETS)); doc.add(newField(FIELD_NO_OFFSETS, docFields[i], TextField.TYPE_STORED)); doc.add(newField(FIELD_DOCS_ONLY, docFields[i], DOCS)); doc.add(newField(FIELD_FREQS, docFields[i], DOCS_AND_FREQS)); doc.add(new IntPoint(FIELD_POINT, 10)); doc.add(new NumericDocValuesField(FIELD_POINT, 10)); doc.add(new NumericDocValuesField("id", i)); doc.add(newField("id", Integer.toString(i), TextField.TYPE_STORED)); writer.addDocument(doc); } writer.forceMerge(1); reader = writer.getReader(); writer.close(); searcher = newSearcher(getOnlyLeafReader(reader)); }
Example #17
Source File: TestPointQueries.java From lucene-solr with Apache License 2.0 | 6 votes |
public void testToString() throws Exception { // ints assertEquals("field:[1 TO 2]", IntPoint.newRangeQuery("field", 1, 2).toString()); assertEquals("field:[-2 TO 1]", IntPoint.newRangeQuery("field", -2, 1).toString()); // longs assertEquals("field:[1099511627776 TO 2199023255552]", LongPoint.newRangeQuery("field", 1L<<40, 1L<<41).toString()); assertEquals("field:[-5 TO 6]", LongPoint.newRangeQuery("field", -5L, 6L).toString()); // floats assertEquals("field:[1.3 TO 2.5]", FloatPoint.newRangeQuery("field", 1.3F, 2.5F).toString()); assertEquals("field:[-2.9 TO 1.0]", FloatPoint.newRangeQuery("field", -2.9F, 1.0F).toString()); // doubles assertEquals("field:[1.3 TO 2.5]", DoublePoint.newRangeQuery("field", 1.3, 2.5).toString()); assertEquals("field:[-2.9 TO 1.0]", DoublePoint.newRangeQuery("field", -2.9, 1.0).toString()); // n-dimensional double assertEquals("field:[1.3 TO 2.5],[-2.9 TO 1.0]", DoublePoint.newRangeQuery("field", new double[] { 1.3, -2.9 }, new double[] { 2.5, 1.0 }).toString()); }
Example #18
Source File: TestPointQueries.java From lucene-solr with Apache License 2.0 | 6 votes |
public void testBasicMultiDimPointInSetQuery() throws Exception { Directory dir = newDirectory(); IndexWriterConfig iwc = newIndexWriterConfig(); iwc.setCodec(getCodec()); IndexWriter w = new IndexWriter(dir, iwc); Document doc = new Document(); doc.add(new IntPoint("int", 17, 42)); w.addDocument(doc); IndexReader r = DirectoryReader.open(w); IndexSearcher s = newSearcher(r, false); assertEquals(0, s.count(newMultiDimIntSetQuery("int", 2, 17, 41))); assertEquals(1, s.count(newMultiDimIntSetQuery("int", 2, 17, 42))); assertEquals(1, s.count(newMultiDimIntSetQuery("int", 2, -7, -7, 17, 42))); assertEquals(1, s.count(newMultiDimIntSetQuery("int", 2, 17, 42, -14, -14))); w.close(); r.close(); dir.close(); }
Example #19
Source File: NumberFieldMapper.java From crate with Apache License 2.0 | 6 votes |
@Override public Query termsQuery(String field, List<Object> values) { int[] v = new int[values.size()]; int upTo = 0; for (int i = 0; i < values.size(); i++) { Object value = values.get(i); if (!hasDecimalPart(value)) { v[upTo++] = parse(value, true); } } if (upTo == 0) { return Queries.newMatchNoDocsQuery("All values have a decimal part"); } if (upTo != v.length) { v = Arrays.copyOf(v, upTo); } return IntPoint.newSetQuery(field, v); }
Example #20
Source File: TestPointFields.java From lucene-solr with Apache License 2.0 | 5 votes |
public void testWhiteboxCreateFields() throws Exception { String[] typeNames = new String[]{"i", "l", "f", "d", "dt"}; @SuppressWarnings({"rawtypes"}) Class<?>[] expectedClasses = new Class[]{IntPoint.class, LongPoint.class, FloatPoint.class, DoublePoint.class, LongPoint.class}; Date dateToTest = new Date(); Object[][] values = new Object[][] { {42, "42"}, {42, "42"}, {42.123, "42.123"}, {12345.6789, "12345.6789"}, {dateToTest, new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.ROOT).format(dateToTest), "NOW"} // "NOW" won't be equal to the other dates }; Set<String> typesTested = new HashSet<>(); for (int i = 0; i < typeNames.length; i++) { for (String suffix:FIELD_SUFFIXES) { doWhiteboxCreateFields("whitebox_p_" + typeNames[i] + suffix, expectedClasses[i], values[i]); typesTested.add("*_p_" + typeNames[i] + suffix); } } Set<String> typesToTest = new HashSet<>(); for (DynamicField dynField:h.getCore().getLatestSchema().getDynamicFields()) { if (dynField.getPrototype().getType() instanceof PointField) { typesToTest.add(dynField.getRegex()); } } assertEquals("Missing types in the test", typesTested, typesToTest); }
Example #21
Source File: TestAddIndexes.java From lucene-solr with Apache License 2.0 | 5 votes |
public void testWithPendingDeletes2() throws IOException { // main directory Directory dir = newDirectory(); // auxiliary directory Directory aux = newDirectory(); setUpDirs(dir, aux); IndexWriter writer = newWriter(dir, newIndexWriterConfig(new MockAnalyzer(random())).setOpenMode(OpenMode.APPEND)); // Adds 10 docs, then replaces them with another 10 // docs, so 10 pending deletes: for (int i = 0; i < 20; i++) { Document doc = new Document(); doc.add(newStringField("id", "" + (i % 10), Field.Store.NO)); doc.add(newTextField("content", "bbb " + i, Field.Store.NO)); doc.add(new IntPoint("doc", i)); doc.add(new IntPoint("doc2d", i, i)); doc.add(new NumericDocValuesField("dv", i)); writer.updateDocument(new Term("id", "" + (i%10)), doc); } writer.addIndexes(aux); // Deletes one of the 10 added docs, leaving 9: PhraseQuery q = new PhraseQuery("content", "bbb", "14"); writer.deleteDocuments(q); writer.forceMerge(1); writer.commit(); verifyNumDocs(dir, 1039); verifyTermDocs(dir, new Term("content", "aaa"), 1030); verifyTermDocs(dir, new Term("content", "bbb"), 9); writer.close(); dir.close(); aux.close(); }
Example #22
Source File: TestAddIndexes.java From lucene-solr with Apache License 2.0 | 5 votes |
public void testWithPendingDeletes() throws IOException { // main directory Directory dir = newDirectory(); // auxiliary directory Directory aux = newDirectory(); setUpDirs(dir, aux); IndexWriter writer = newWriter(dir, newIndexWriterConfig(new MockAnalyzer(random())).setOpenMode(OpenMode.APPEND)); writer.addIndexes(aux); // Adds 10 docs, then replaces them with another 10 // docs, so 10 pending deletes: for (int i = 0; i < 20; i++) { Document doc = new Document(); doc.add(newStringField("id", "" + (i % 10), Field.Store.NO)); doc.add(newTextField("content", "bbb " + i, Field.Store.NO)); doc.add(new IntPoint("doc", i)); doc.add(new IntPoint("doc2d", i, i)); doc.add(new NumericDocValuesField("dv", i)); writer.updateDocument(new Term("id", "" + (i%10)), doc); } // Deletes one of the 10 added docs, leaving 9: PhraseQuery q = new PhraseQuery("content", "bbb", "14"); writer.deleteDocuments(q); writer.forceMerge(1); writer.commit(); verifyNumDocs(dir, 1039); verifyTermDocs(dir, new Term("content", "aaa"), 1030); verifyTermDocs(dir, new Term("content", "bbb"), 9); writer.close(); dir.close(); aux.close(); }
Example #23
Source File: TestPointQueries.java From lucene-solr with Apache License 2.0 | 5 votes |
@Nightly public void testInversePointRange() throws IOException { Directory dir = newDirectory(); IndexWriter w = new IndexWriter(dir, newIndexWriterConfig()); final int numDims = TestUtil.nextInt(random(), 1, 3); final int numDocs = atLeast(10 * BKDWriter.DEFAULT_MAX_POINTS_IN_LEAF_NODE); // we need multiple leaves to enable this optimization for (int i = 0; i < numDocs; ++i) { Document doc = new Document(); int[] values = new int[numDims]; Arrays.fill(values, i); doc.add(new IntPoint("f", values)); w.addDocument(doc); } w.forceMerge(1); IndexReader r = DirectoryReader.open(w); w.close(); IndexSearcher searcher = newSearcher(r); int[] low = new int[numDims]; int[] high = new int[numDims]; Arrays.fill(high, numDocs - 2); assertEquals(high[0] - low[0] + 1, searcher.count(IntPoint.newRangeQuery("f", low, high))); Arrays.fill(low, 1); assertEquals(high[0] - low[0] + 1, searcher.count(IntPoint.newRangeQuery("f", low, high))); Arrays.fill(high, numDocs - 1); assertEquals(high[0] - low[0] + 1, searcher.count(IntPoint.newRangeQuery("f", low, high))); Arrays.fill(low, BKDWriter.DEFAULT_MAX_POINTS_IN_LEAF_NODE + 1); assertEquals(high[0] - low[0] + 1, searcher.count(IntPoint.newRangeQuery("f", low, high))); Arrays.fill(high, numDocs - BKDWriter.DEFAULT_MAX_POINTS_IN_LEAF_NODE); assertEquals(high[0] - low[0] + 1, searcher.count(IntPoint.newRangeQuery("f", low, high))); r.close(); dir.close(); }
Example #24
Source File: TestPointQueries.java From lucene-solr with Apache License 2.0 | 5 votes |
public void testPointInSetEquals() { Query q1, q2; q1 = IntPoint.newSetQuery("a", 0, 1000, 17); q2 = IntPoint.newSetQuery("a", 17, 0, 1000); assertEquals(q1, q2); assertEquals(q1.hashCode(), q2.hashCode()); assertFalse(q1.equals(IntPoint.newSetQuery("a", 1, 17, 1000))); assertFalse(q1.equals(IntPoint.newSetQuery("b", 0, 1000, 17))); q1 = LongPoint.newSetQuery("a", 0, 1000, 17); q2 = LongPoint.newSetQuery("a", 17, 0, 1000); assertEquals(q1, q2); assertEquals(q1.hashCode(), q2.hashCode()); assertFalse(q1.equals(LongPoint.newSetQuery("a", 1, 17, 1000))); q1 = FloatPoint.newSetQuery("a", 0, 1000, 17); q2 = FloatPoint.newSetQuery("a", 17, 0, 1000); assertEquals(q1, q2); assertEquals(q1.hashCode(), q2.hashCode()); assertFalse(q1.equals(FloatPoint.newSetQuery("a", 1, 17, 1000))); q1 = DoublePoint.newSetQuery("a", 0, 1000, 17); q2 = DoublePoint.newSetQuery("a", 17, 0, 1000); assertEquals(q1, q2); assertEquals(q1.hashCode(), q2.hashCode()); assertFalse(q1.equals(DoublePoint.newSetQuery("a", 1, 17, 1000))); byte[] zeros = new byte[5]; byte[] ones = new byte[5]; Arrays.fill(ones, (byte) 0xff); q1 = BinaryPoint.newSetQuery("a", new byte[][] {zeros, ones}); q2 = BinaryPoint.newSetQuery("a", new byte[][] {zeros, ones}); assertEquals(q1, q2); assertEquals(q1.hashCode(), q2.hashCode()); byte[] other = ones.clone(); other[2] = (byte) 5; assertFalse(q1.equals(BinaryPoint.newSetQuery("a", new byte[][] {zeros, other}))); }
Example #25
Source File: TestPointQueries.java From lucene-solr with Apache License 2.0 | 5 votes |
public void testRangeOptimizesIfAllPointsMatch() throws IOException { final int numDims = TestUtil.nextInt(random(), 1, 3); Directory dir = newDirectory(); RandomIndexWriter w = new RandomIndexWriter(random(), dir); Document doc = new Document(); int[] value = new int[numDims]; for (int i = 0; i < numDims; ++i) { value[i] = TestUtil.nextInt(random(), 1, 10); } doc.add(new IntPoint("point", value)); w.addDocument(doc); IndexReader reader = w.getReader(); IndexSearcher searcher = new IndexSearcher(reader); searcher.setQueryCache(null); int[] lowerBound = new int[numDims]; int[] upperBound = new int[numDims]; for (int i = 0; i < numDims; ++i) { lowerBound[i] = value[i] - random().nextInt(1); upperBound[i] = value[i] + random().nextInt(1); } Query query = IntPoint.newRangeQuery("point", lowerBound, upperBound); Weight weight = searcher.createWeight(query, ScoreMode.COMPLETE_NO_SCORES, 1); Scorer scorer = weight.scorer(searcher.getIndexReader().leaves().get(0)); assertEquals(DocIdSetIterator.all(1).getClass(), scorer.iterator().getClass()); // When not all documents in the query have a value, the optimization is not applicable reader.close(); w.addDocument(new Document()); w.forceMerge(1); reader = w.getReader(); searcher = new IndexSearcher(reader); searcher.setQueryCache(null); weight = searcher.createWeight(query, ScoreMode.COMPLETE_NO_SCORES, 1); scorer = weight.scorer(searcher.getIndexReader().leaves().get(0)); assertFalse(DocIdSetIterator.all(1).getClass().equals(scorer.iterator().getClass())); reader.close(); w.close(); dir.close(); }
Example #26
Source File: TestIndexOptions.java From lucene-solr with Apache License 2.0 | 5 votes |
private void doTestChangeIndexOptionsViaAddDocument(boolean preExistingField, boolean onNewSegment, IndexOptions from, IndexOptions to) throws IOException { Directory dir = newDirectory(); IndexWriter w = new IndexWriter(dir, newIndexWriterConfig()); if (preExistingField) { w.addDocument(Collections.singleton(new IntPoint("foo", 1))); if (onNewSegment) { DirectoryReader.open(w).close(); } } FieldType ft1 = new FieldType(TextField.TYPE_STORED); ft1.setIndexOptions(from); w.addDocument(Collections.singleton(new Field("foo", "bar", ft1))); if (onNewSegment) { DirectoryReader.open(w).close(); } FieldType ft2 = new FieldType(TextField.TYPE_STORED); ft2.setIndexOptions(to); if (from == IndexOptions.NONE || to == IndexOptions.NONE || from == to) { w.addDocument(Collections.singleton(new Field("foo", "bar", ft2))); // no exception w.forceMerge(1); try (LeafReader r = getOnlyLeafReader(DirectoryReader.open(w))) { IndexOptions expected = from == IndexOptions.NONE ? to : from; assertEquals(expected, r.getFieldInfos().fieldInfo("foo").getIndexOptions()); } } else { IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> w.addDocument(Collections.singleton(new Field("foo", "bar", ft2)))); assertEquals("cannot change field \"foo\" from index options=" + from + " to inconsistent index options=" + to, e.getMessage()); } w.close(); dir.close(); }
Example #27
Source File: TestManyPointsInOldIndex.java From lucene-solr with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws IOException { Directory dir = FSDirectory.open(Paths.get("manypointsindex")); IndexWriter w = new IndexWriter(dir, new IndexWriterConfig()); for(int i=0;i<1025;i++) { Document doc = new Document(); doc.add(new IntPoint("intpoint", 1025-i)); w.addDocument(doc); } w.close(); dir.close(); }
Example #28
Source File: TestPointQueries.java From lucene-solr with Apache License 2.0 | 5 votes |
/** Boxed methods for primitive types should behave the same as unboxed: just sugar */ public void testPointIntSetBoxed() throws Exception { assertEquals(IntPoint.newSetQuery("foo", 1, 2, 3), IntPoint.newSetQuery("foo", Arrays.asList(1, 2, 3))); assertEquals(FloatPoint.newSetQuery("foo", 1F, 2F, 3F), FloatPoint.newSetQuery("foo", Arrays.asList(1F, 2F, 3F))); assertEquals(LongPoint.newSetQuery("foo", 1L, 2L, 3L), LongPoint.newSetQuery("foo", Arrays.asList(1L, 2L, 3L))); assertEquals(DoublePoint.newSetQuery("foo", 1D, 2D, 3D), DoublePoint.newSetQuery("foo", Arrays.asList(1D, 2D, 3D))); }
Example #29
Source File: PointMerger.java From lucene-solr with Apache License 2.0 | 5 votes |
@Override public PointValues.Relation compare(byte[] minPackedValue, byte[] maxPackedValue) { int v = IntPoint.decodeDimension(maxPackedValue, 0); if (v >= last) { return PointValues.Relation.CELL_CROSSES_QUERY; } else { return PointValues.Relation.CELL_OUTSIDE_QUERY; } }
Example #30
Source File: TestIndexWriterOnDiskFull.java From lucene-solr with Apache License 2.0 | 5 votes |
private void addDoc(IndexWriter writer) throws IOException { Document doc = new Document(); doc.add(newTextField("content", "aaa", Field.Store.NO)); doc.add(new NumericDocValuesField("numericdv", 1)); doc.add(new IntPoint("point", 1)); doc.add(new IntPoint("point2d", 1, 1)); writer.addDocument(doc); }