org.apache.lucene.search.Sort.<init>()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(8.8k)|赞(0)|评价(0)|浏览(169)

本文整理了Java中org.apache.lucene.search.Sort.<init>()方法的一些代码示例,展示了Sort.<init>()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Sort.<init>()方法的具体详情如下:
包路径:org.apache.lucene.search.Sort
类名称:Sort
方法名:<init>

Sort.<init>介绍

[英]Sorts by computed relevance. This is the same sort criteria as calling IndexSearcher#search(Query,int)without a sort criteria, only with slightly more overhead.
[中]按计算相关性排序。这与在没有排序条件的情况下调用IndexSearcher#search(Query,int)的排序条件相同,只是开销稍大。

代码示例

代码示例来源:origin: soabase/exhibitor

public TopDocs   search(Query query, int maxResults) throws IOException
{
  Sort sort = new Sort(new SortField(FieldNames.DATE, SortField.LONG, true));
  return searcher.search(query, maxResults, sort);
}

代码示例来源:origin: querydsl/querydsl

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 SortField(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[sorts.size()]));
    return sort;
  }
}

代码示例来源:origin: querydsl/querydsl

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 SortField(toField(path), sortFields.get(type), reverse));
      } else {
        sorts.add(new SortField(toField(path), sortLocale, reverse));
      }
    }
    Sort sort = new Sort();
    sort.setSort(sorts.toArray(new SortField[sorts.size()]));
    return sort;
  }
}

代码示例来源:origin: querydsl/querydsl

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[sorts.size()]));
    return sort;
  }
}

代码示例来源:origin: oracle/opengrok

sort = new Sort(new SortField(QueryBuilder.DATE, SortField.Type.STRING, true));
  break;
case BY_PATH:
  sort = new Sort(new SortField(QueryBuilder.FULLPATH, SortField.Type.STRING));
  break;
default:

代码示例来源:origin: oracle/opengrok

SortField sfield = new SortField(QueryBuilder.DATE, SortField.Type.STRING, true);
Sort sort = new Sort(sfield);
QueryParser qparser = new QueryParser(QueryBuilder.PATH, new CompatibleAnalyser());
Query query;

代码示例来源:origin: neo4j/neo4j

@Test
void shouldReturnIndexHitsInGivenSortOrder() throws Exception
{
  // given
  DocValuesCollector collector = new DocValuesCollector( false );
  IndexReaderStub readerStub = indexReaderWithMaxDocs( 43 );
  // when
  collector.doSetNextReader( readerStub.getContext() );
  collector.collect( 1 );
  collector.collect( 3 );
  collector.collect( 37 );
  collector.collect( 42 );
  // then
  Sort byIdDescending = new Sort( new SortField( "id", SortField.Type.LONG, true ) );
  IndexHits<Document> indexHits = collector.getIndexHits( byIdDescending );
  assertEquals( 4, indexHits.size() );
  assertEquals( "42", indexHits.next().get( "id" ) );
  assertEquals( "37", indexHits.next().get( "id" ) );
  assertEquals( "3", indexHits.next().get( "id" ) );
  assertEquals( "1", indexHits.next().get( "id" ) );
  assertFalse( indexHits.hasNext() );
}

代码示例来源:origin: neo4j/neo4j

@Test
void shouldReturnDocValuesInGivenOrder() throws Exception
{
  // given
  DocValuesCollector collector = new DocValuesCollector( false );
  IndexReaderStub readerStub = indexReaderWithMaxDocs( 42 );
  // when
  collector.doSetNextReader( readerStub.getContext() );
  collector.collect( 1 );
  collector.collect( 2 );
  // then
  Sort byIdDescending = new Sort( new SortField( "id", SortField.Type.LONG, true ) );
  LongIterator valuesIterator = collector.getSortedValuesIterator( "id", byIdDescending );
  assertEquals( 2, valuesIterator.next() );
  assertEquals( 1, valuesIterator.next() );
  assertFalse( valuesIterator.hasNext() );
}

代码示例来源:origin: org.elasticsearch/elasticsearch

private TopDocs searchOperations(ScoreDoc after) throws IOException {
  final Query rangeQuery = LongPoint.newRangeQuery(SeqNoFieldMapper.NAME, Math.max(fromSeqNo, lastSeenSeqNo), toSeqNo);
  final Sort sortedBySeqNoThenByTerm = new Sort(
    new SortField(SeqNoFieldMapper.NAME, SortField.Type.LONG),
    new SortField(SeqNoFieldMapper.PRIMARY_TERM_NAME, SortField.Type.LONG, true)
  );
  return indexSearcher.searchAfter(after, rangeQuery, searchBatchSize, sortedBySeqNoThenByTerm);
}

代码示例来源:origin: org.apache.lucene/lucene-core

sortFields[i] = new SortedNumericSortField(fieldName, sortType, reverse, sortedNumericSelector);
  } else {
   sortFields[i] = new SortField(fieldName, sortType, reverse);
 indexSort = new Sort(sortFields);
} else if (numSortFields < 0) {
 throw new CorruptIndexException("invalid index sort field count: " + numSortFields, input);

代码示例来源:origin: rnewson/couchdb-lucene

public static Sort toSort(final String sort) throws ParseException {
  if (sort == null) {
    return null;
  } else {
    final String[] split = sort.split(",");
    final SortField[] sort_fields = new SortField[split.length];
    for (int i = 0; i < split.length; i++) {
      String tmp = split[i];
      final boolean reverse = tmp.charAt(0) == '\\';
      // Strip sort order character.
      if (tmp.charAt(0) == '\\' || tmp.charAt(0) == '/') {
        tmp = tmp.substring(1);
      }
      final SortField sortField;
      if ("_score".equals(tmp)) {
        sortField = new SortField(null, SortField.Type.SCORE, reverse);
      } else if ("_doc".equals(tmp)) {
        sortField = new SortField(null, SortField.Type.DOC, reverse);
      } else {
        final TypedField typedField = new TypedField(tmp);
        sortField = new SortField(typedField.getName(), typedField
            .toSortField(), reverse);
      }
      sort_fields[i] = sortField;
    }
    return new Sort(sort_fields);
  }
}

代码示例来源:origin: org.apache.lucene/lucene-core

sortFields[i] = new SortedNumericSortField(fieldName, sortType, reverse, sortedNumericSelector);
  } else {
   sortFields[i] = new SortField(fieldName, sortType, reverse);
 indexSort = new Sort(sortFields);
} else if (numSortFields < 0) {
 throw new CorruptIndexException("invalid index sort field count: " + numSortFields, input);

代码示例来源:origin: sanluan/PublicCMS

Sort sort = new Sort(new SortField("publishDate", SortField.Type.LONG, true));
query.setSort(sort);

代码示例来源:origin: sanluan/PublicCMS

Sort sort = new Sort(new SortField("publishDate", SortField.Type.LONG, true));
query.setSort(sort);

代码示例来源:origin: sanluan/PublicCMS

Sort sort = new Sort(new SortField("publishDate", SortField.Type.LONG, true));
query.setSort(sort);

代码示例来源:origin: sanluan/PublicCMS

Sort sort = new Sort(new SortField("publishDate", SortField.Type.LONG, true));
query.setSort(sort);

代码示例来源:origin: org.pageseeder.flint/pso-flint-lucene

/**
 * Creates new predicate search query.
 *
 * @param predicate The predicate for this query.
 * @param analyzer  The analyzer to use for the query, should be the same as the one used to write the Index.
 * @param sortField The field name to use to order the results.
 *
 * @throws IllegalArgumentException If the predicate is <code>null</code>.
 */
public PredicateSearchQuery(String predicate, Analyzer analyzer, String sortField) throws IllegalArgumentException {
 this(predicate, analyzer, sortField == null ? Sort.INDEXORDER : new Sort(new SortField(sortField, Type.STRING)));
}

代码示例来源:origin: org.kie.workbench.screens/kie-wb-common-library-backend

@Override
public Sort getSortOrder() {
  return new Sort(new SortField(FieldFactory.FILE_NAME_FIELD_SORTED,
                 SortField.Type.STRING));
}

代码示例来源:origin: org.pageseeder.flint/pso-flint-lucene

/**
 * Creates new predicate search query.
 *
 * @param predicate The predicate for this query.
 * @param sortField The field name to use to order the results.
 *
 * @throws IllegalArgumentException If the predicate is <code>null</code>.
 */
public PredicateSearchQuery(String predicate, String sortField) throws IllegalArgumentException {
 this(predicate, sortField == null ? Sort.INDEXORDER : new Sort(new SortField(sortField, Type.STRING)));
}

代码示例来源:origin: stackoverflow.com

Sort sorter = new Sort(); // new sort object

String field = "fieldName"; // enter the field to sort by
Type type = Type.Long; // since your field is long type
boolean descending = false; // ascending by default

SortField sortField = new SortField(field, type, descending);

sorter.setSort(sortField); // now set the sort field

相关文章