Search in sources :

Example 31 with SortedNumericSortField

use of org.apache.lucene.search.SortedNumericSortField in project lucene-solr by apache.

the class TestIndexSorting method testMultiValuedNumericAlreadySorted.

public void testMultiValuedNumericAlreadySorted() throws Exception {
    assertNeedsIndexSortMerge(new SortedNumericSortField("foo", SortField.Type.INT), (doc) -> {
        doc.add(new SortedNumericDocValuesField("foo", Integer.MIN_VALUE));
        int num = random().nextInt(5);
        for (int j = 0; j < num; j++) {
            doc.add(new SortedNumericDocValuesField("foo", random().nextInt()));
        }
    }, (doc) -> {
        int num = random().nextInt(5);
        for (int j = 0; j < num; j++) {
            doc.add(new SortedNumericDocValuesField("foo", random().nextInt()));
        }
    });
}
Also used : SortedNumericSortField(org.apache.lucene.search.SortedNumericSortField) SortedNumericDocValuesField(org.apache.lucene.document.SortedNumericDocValuesField) BinaryPoint(org.apache.lucene.document.BinaryPoint) IntPoint(org.apache.lucene.document.IntPoint)

Example 32 with SortedNumericSortField

use of org.apache.lucene.search.SortedNumericSortField in project querydsl by querydsl.

the class LuceneSerializer method toSort.

public Sort toSort(List<? extends OrderSpecifier<?>> orderBys) {
    List<SortField> sorts = new ArrayList<SortField>(orderBys.size());
    for (OrderSpecifier<?> order : orderBys) {
        if (!(order.getTarget() instanceof Path<?>)) {
            throw new IllegalArgumentException("argument was not of type Path.");
        }
        Class<?> type = order.getTarget().getType();
        boolean reverse = !order.isAscending();
        Path<?> path = getPath(order.getTarget());
        if (Number.class.isAssignableFrom(type)) {
            sorts.add(new SortedNumericSortField(toField(path), sortFields.get(type), reverse));
        } else {
            sorts.add(new SortField(toField(path), SortField.Type.STRING, reverse));
        }
    }
    Sort sort = new Sort();
    sort.setSort(sorts.toArray(new SortField[0]));
    return sort;
}
Also used : Path(com.querydsl.core.types.Path) SortedNumericSortField(org.apache.lucene.search.SortedNumericSortField) ArrayList(java.util.ArrayList) Sort(org.apache.lucene.search.Sort) SortField(org.apache.lucene.search.SortField) SortedNumericSortField(org.apache.lucene.search.SortedNumericSortField)

Example 33 with SortedNumericSortField

use of org.apache.lucene.search.SortedNumericSortField in project crate by crate.

the class LuceneOrderedDocCollectorTest method nextPageQuery.

private Long[] nextPageQuery(IndexReader reader, FieldDoc lastCollected, boolean reverseFlag, boolean nullFirst) throws IOException {
    OrderBy orderBy = new OrderBy(List.of(REFERENCE), new boolean[] { reverseFlag }, new boolean[] { nullFirst });
    SortField sortField = new SortedNumericSortField("value", SortField.Type.LONG, reverseFlag);
    Long missingValue = (Long) NullSentinelValues.nullSentinelForScoreDoc(orderBy, 0);
    sortField.setMissingValue(missingValue);
    Sort sort = new Sort(sortField);
    OptimizeQueryForSearchAfter queryForSearchAfter = new OptimizeQueryForSearchAfter(orderBy, mock(QueryShardContext.class), name -> valueFieldType);
    Query nextPageQuery = queryForSearchAfter.apply(lastCollected);
    TopFieldDocs result = search(reader, nextPageQuery, sort);
    Long[] results = new Long[result.scoreDocs.length];
    for (int i = 0; i < result.scoreDocs.length; i++) {
        Long value = (Long) ((FieldDoc) result.scoreDocs[i]).fields[0];
        results[i] = value.equals(missingValue) ? null : value;
    }
    return results;
}
Also used : OrderBy(io.crate.analyze.OrderBy) SortedNumericSortField(org.apache.lucene.search.SortedNumericSortField) Query(org.apache.lucene.search.Query) FuzzyQuery(org.apache.lucene.search.FuzzyQuery) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) ConstantScoreQuery(org.apache.lucene.search.ConstantScoreQuery) TermQuery(org.apache.lucene.search.TermQuery) FieldDoc(org.apache.lucene.search.FieldDoc) Sort(org.apache.lucene.search.Sort) QueryShardContext(org.elasticsearch.index.query.QueryShardContext) TopFieldDocs(org.apache.lucene.search.TopFieldDocs) SortField(org.apache.lucene.search.SortField) SortedNumericSortField(org.apache.lucene.search.SortedNumericSortField)

Aggregations

SortedNumericSortField (org.apache.lucene.search.SortedNumericSortField)33 SortField (org.apache.lucene.search.SortField)25 Sort (org.apache.lucene.search.Sort)24 SortedSetSortField (org.apache.lucene.search.SortedSetSortField)22 Document (org.apache.lucene.document.Document)18 NumericDocValuesField (org.apache.lucene.document.NumericDocValuesField)18 SortedNumericDocValuesField (org.apache.lucene.document.SortedNumericDocValuesField)18 MockAnalyzer (org.apache.lucene.analysis.MockAnalyzer)13 Directory (org.apache.lucene.store.Directory)13 Version (org.apache.lucene.util.Version)5 CorruptIndexException (org.apache.lucene.index.CorruptIndexException)3 SegmentInfo (org.apache.lucene.index.SegmentInfo)3 SortedNumericSelector (org.apache.lucene.search.SortedNumericSelector)3 SortedSetSelector (org.apache.lucene.search.SortedSetSelector)3 ChecksumIndexInput (org.apache.lucene.store.ChecksumIndexInput)3 OrderBy (io.crate.analyze.OrderBy)2 LongType (io.crate.types.LongType)2 IndexSearcher (org.apache.lucene.search.IndexSearcher)2 IndexOutput (org.apache.lucene.store.IndexOutput)2 Path (com.querydsl.core.types.Path)1