List of usage examples for org.apache.lucene.search FieldDoc FieldDoc
public FieldDoc(int doc, float score, Object[] fields)
From source file:io.crate.execution.engine.collect.collectors.LuceneOrderedDocCollectorTest.java
License:Apache License
@Test public void testNextPageQueryWithLastCollectedNullValue() { FieldDoc fieldDoc = new FieldDoc(1, 0, new Object[] { null }); OrderBy orderBy = new OrderBy(Collections.singletonList(REFERENCE), new boolean[] { false }, new Boolean[] { null }); OptimizeQueryForSearchAfter queryForSearchAfter = new OptimizeQueryForSearchAfter(orderBy, mock(QueryShardContext.class), name -> valueFieldType); queryForSearchAfter.apply(fieldDoc); }
From source file:io.crate.execution.engine.collect.collectors.LuceneOrderedDocCollectorTest.java
License:Apache License
@Test public void testSearchAfterQueriesNullsLast() throws Exception { Directory index = createLuceneIndex(); IndexReader reader = DirectoryReader.open(index); // reverseOrdering = false, nulls First = false // 1 2 null null // ^ (lastCollected = 2) FieldDoc afterDoc = new FieldDoc(0, 0, new Object[] { 2L }); Long[] result = nextPageQuery(reader, afterDoc, false, null); assertThat(result, is(new Long[] { 2L, null, null })); // reverseOrdering = false, nulls First = false // 1 2 null null // ^//from w w w. j a v a 2 s .co m afterDoc = new FieldDoc(0, 0, new Object[] { LuceneMissingValue.missingValue(false, null, SortField.Type.LONG) }); result = nextPageQuery(reader, afterDoc, false, null); assertThat(result, is(new Long[] { null, null })); // reverseOrdering = true, nulls First = false // 2 1 null null // ^ afterDoc = new FieldDoc(0, 0, new Object[] { 1L }); result = nextPageQuery(reader, afterDoc, true, false); assertThat(result, is(new Long[] { 1L, null, null })); // reverseOrdering = true, nulls First = false // 2 1 null null // ^ afterDoc = new FieldDoc(0, 0, new Object[] { LuceneMissingValue.missingValue(true, false, SortField.Type.LONG) }); result = nextPageQuery(reader, afterDoc, true, false); assertThat(result, is(new Long[] { null, null })); reader.close(); }
From source file:io.crate.execution.engine.collect.collectors.LuceneOrderedDocCollectorTest.java
License:Apache License
@Test public void testSearchAfterQueriesNullsFirst() throws Exception { Directory index = createLuceneIndex(); IndexReader reader = DirectoryReader.open(index); // reverseOrdering = false, nulls First = true // null, null, 1, 2 // ^ (lastCollected = 2L) FieldDoc afterDoc = new FieldDoc(0, 0, new Object[] { 2L }); Long[] result = nextPageQuery(reader, afterDoc, false, true); assertThat(result, is(new Long[] { 2L })); // reverseOrdering = false, nulls First = true // null, null, 1, 2 // ^/*from ww w . j a v a 2 s . co m*/ afterDoc = new FieldDoc(0, 0, new Object[] { LuceneMissingValue.missingValue(false, true, SortField.Type.LONG) }); result = nextPageQuery(reader, afterDoc, false, true); assertThat(result, is(new Long[] { null, null, 1L, 2L })); // reverseOrdering = true, nulls First = true // null, null, 2, 1 // ^ afterDoc = new FieldDoc(0, 0, new Object[] { 1L }); result = nextPageQuery(reader, afterDoc, true, true); assertThat(result, is(new Long[] { 1L })); // reverseOrdering = true, nulls First = true // null, null, 2, 1 // ^ afterDoc = new FieldDoc(0, 0, new Object[] { LuceneMissingValue.missingValue(true, true, SortField.Type.LONG) }); result = nextPageQuery(reader, afterDoc, true, true); assertThat(result, is(new Long[] { null, null, 2L, 1L })); reader.close(); }
From source file:io.crate.execution.engine.collect.collectors.LuceneOrderedDocCollectorTest.java
License:Apache License
@Test public void testSearchAfterWithSystemColumn() { Reference sysColReference = new Reference( new ReferenceIdent(new TableIdent(Schemas.DOC_SCHEMA_NAME, "table"), DocSysColumns.SCORE), RowGranularity.DOC, DataTypes.FLOAT); OrderBy orderBy = new OrderBy(ImmutableList.of(sysColReference, REFERENCE), new boolean[] { false, false }, new Boolean[] { false, false }); FieldDoc lastCollected = new FieldDoc(0, 0, new Object[] { 2L }); OptimizeQueryForSearchAfter queryForSearchAfter = new OptimizeQueryForSearchAfter(orderBy, mock(QueryShardContext.class), name -> valueFieldType); Query nextPageQuery = queryForSearchAfter.apply(lastCollected); // returns null which leads to reuse of old query without paging optimization assertNull(nextPageQuery);/* w ww . j a v a 2s. c om*/ }
From source file:io.crate.operation.collect.collectors.LuceneOrderedDocCollectorTest.java
License:Apache License
@Test public void testNextPageQueryWithLastCollectedNullValue() throws Exception { FieldDoc fieldDoc = new FieldDoc(1, 0, new Object[] { null }); OrderBy orderBy = new OrderBy(Collections.<Symbol>singletonList(REFERENCE), new boolean[] { false }, new Boolean[] { null }); Object missingValue = LuceneMissingValue.missingValue(orderBy, 0); LuceneOrderedDocCollector.nextPageQuery(fieldDoc, orderBy, new Object[] { missingValue }, name -> valueFieldType);//ww w .j a va 2s .c om }
From source file:io.crate.operation.collect.LuceneDocCollectorTest.java
License:Apache License
@Test public void testSearchAfterQueriesNullsLast() throws Exception { Directory index = createLuceneIndex(); IndexReader reader = DirectoryReader.open(index); // reverseOrdering = false, nulls First = false // 1 2 null null // ^ (lastCollected = 2) FieldDoc afterDoc = new FieldDoc(0, 0, new Object[] { 2L }); Long[] result = nextPageQuery(reader, afterDoc, false, null); assertThat(result, is(new Long[] { 2L, null, null })); // reverseOrdering = false, nulls First = false // 1 2 null null // ^//w ww . ja va2 s . com afterDoc = new FieldDoc(0, 0, new Object[] { LuceneMissingValue.missingValue(false, null, SortField.Type.LONG) }); result = nextPageQuery(reader, afterDoc, false, null); assertThat(result, is(new Long[] { null, null })); // reverseOrdering = true, nulls First = false // 2 1 null null // ^ afterDoc = new FieldDoc(0, 0, new Object[] { 1L }); result = nextPageQuery(reader, afterDoc, true, null); assertThat(result, is(new Long[] { null, null, 1L })); // reverseOrdering = true, nulls First = false // 2 1 null null // ^ afterDoc = new FieldDoc(0, 0, new Object[] { LuceneMissingValue.missingValue(true, null, SortField.Type.LONG) }); result = nextPageQuery(reader, afterDoc, true, null); assertThat(result, is(new Long[] { null, null })); reader.close(); }
From source file:org.apache.solr.search.CursorMark.java
License:Apache License
/** * Returns a synthetically constructed {@link FieldDoc} whose {@link FieldDoc#fields} * match the values of this object. // ww w.j ava 2s . c o m * <p> * Important Notes: * </p> * <ul> * <li>{@link FieldDoc#doc} will always be set to {@link Integer#MAX_VALUE} so * that the tie breaking logic used by <code>IndexSearcher</code> won't select * the same doc again based on the internal lucene docId when the Solr * <code>uniqueKey</code> value is the same. * </li> * <li>{@link FieldDoc#score} will always be set to 0.0F since it is not used * when applying <code>searchAfter</code> logic. (Even if the sort values themselves * contain scores which are used in the sort) * </li> * </ul> * * @return a {@link FieldDoc} to "search after" or null if the initial * page of results is requested. */ public FieldDoc getSearchAfterFieldDoc() { if (null == values) return null; return new FieldDoc(Integer.MAX_VALUE, 0.0F, values.toArray()); }
From source file:org.codelibs.elasticsearch.common.lucene.Lucene.java
License:Apache License
public static FieldDoc readFieldDoc(StreamInput in) throws IOException { Comparable[] cFields = new Comparable[in.readVInt()]; for (int j = 0; j < cFields.length; j++) { byte type = in.readByte(); if (type == 0) { cFields[j] = null;/*from w ww .j ava 2 s. c o m*/ } else if (type == 1) { cFields[j] = in.readString(); } else if (type == 2) { cFields[j] = in.readInt(); } else if (type == 3) { cFields[j] = in.readLong(); } else if (type == 4) { cFields[j] = in.readFloat(); } else if (type == 5) { cFields[j] = in.readDouble(); } else if (type == 6) { cFields[j] = in.readByte(); } else if (type == 7) { cFields[j] = in.readShort(); } else if (type == 8) { cFields[j] = in.readBoolean(); } else if (type == 9) { cFields[j] = in.readBytesRef(); } else { throw new IOException("Can't match type [" + type + "]"); } } return new FieldDoc(in.readVInt(), in.readFloat(), cFields); }
From source file:org.codelibs.elasticsearch.search.searchafter.SearchAfterBuilder.java
License:Apache License
public static FieldDoc buildFieldDoc(SortAndFormats sort, Object[] values) { if (sort == null || sort.sort.getSort() == null || sort.sort.getSort().length == 0) { throw new IllegalArgumentException("Sort must contain at least one field."); }//from w ww .jav a2s. com SortField[] sortFields = sort.sort.getSort(); if (sortFields.length != values.length) { throw new IllegalArgumentException(SEARCH_AFTER.getPreferredName() + " has " + values.length + " value(s) but sort has " + sort.sort.getSort().length + "."); } Object[] fieldValues = new Object[sortFields.length]; for (int i = 0; i < sortFields.length; i++) { SortField sortField = sortFields[i]; DocValueFormat format = sort.formats[i]; if (values[i] != null) { fieldValues[i] = convertValueFromSortField(values[i], sortField, format); } else { fieldValues[i] = null; } } /* * We set the doc id to Integer.MAX_VALUE in order to make sure that the search starts "after" the first document that is equal to * the field values. */ return new FieldDoc(Integer.MAX_VALUE, 0, fieldValues); }
From source file:org.elasticsearch.common.lucene.Lucene.java
License:Apache License
public static TopDocs readTopDocs(StreamInput in) throws IOException { if (!in.readBoolean()) { // no docs return null; }/*from w w w . j a v a 2 s . c o m*/ if (in.readBoolean()) { int totalHits = in.readVInt(); float maxScore = in.readFloat(); SortField[] fields = new SortField[in.readVInt()]; for (int i = 0; i < fields.length; i++) { String field = null; if (in.readBoolean()) { field = in.readString(); } fields[i] = new SortField(field, readSortType(in), in.readBoolean()); } FieldDoc[] fieldDocs = new FieldDoc[in.readVInt()]; for (int i = 0; i < fieldDocs.length; i++) { Comparable[] cFields = new Comparable[in.readVInt()]; for (int j = 0; j < cFields.length; j++) { byte type = in.readByte(); if (type == 0) { cFields[j] = null; } else if (type == 1) { cFields[j] = in.readString(); } else if (type == 2) { cFields[j] = in.readInt(); } else if (type == 3) { cFields[j] = in.readLong(); } else if (type == 4) { cFields[j] = in.readFloat(); } else if (type == 5) { cFields[j] = in.readDouble(); } else if (type == 6) { cFields[j] = in.readByte(); } else if (type == 7) { cFields[j] = in.readShort(); } else if (type == 8) { cFields[j] = in.readBoolean(); } else if (type == 9) { cFields[j] = in.readBytesRef(); } else { throw new IOException("Can't match type [" + type + "]"); } } fieldDocs[i] = new FieldDoc(in.readVInt(), in.readFloat(), cFields); } return new TopFieldDocs(totalHits, fieldDocs, fields, maxScore); } else { int totalHits = in.readVInt(); float maxScore = in.readFloat(); ScoreDoc[] scoreDocs = new ScoreDoc[in.readVInt()]; for (int i = 0; i < scoreDocs.length; i++) { scoreDocs[i] = new ScoreDoc(in.readVInt(), in.readFloat()); } return new TopDocs(totalHits, scoreDocs, maxScore); } }