本文整理匯總了Java中org.apache.lucene.search.Sort.getSort方法的典型用法代碼示例。如果您正苦於以下問題:Java Sort.getSort方法的具體用法?Java Sort.getSort怎麽用?Java Sort.getSort使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.lucene.search.Sort
的用法示例。
在下文中一共展示了Sort.getSort方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getFullTextQueryList
import org.apache.lucene.search.Sort; //導入方法依賴的package包/類
private FullTextQuery getFullTextQueryList(Long offset, Long limit) {
FullTextQuery fullTextQuery = getFullTextQuery();
if (offset != null) {
fullTextQuery.setFirstResult(Ints.saturatedCast(offset));
}
if (limit != null) {
fullTextQuery.setMaxResults(Ints.saturatedCast(limit));
}
Sort sort = SortUtils.getLuceneSortWithDefaults(sortMap, defaultSorts);
if (sort != null && sort.getSort().length > 0) {
SortFieldUtil.setSort(fullTextQuery, fullTextEntityManager, mainClass, sort);
}
return fullTextQuery;
}
示例2: SortAndFormats
import org.apache.lucene.search.Sort; //導入方法依賴的package包/類
public SortAndFormats(Sort sort, DocValueFormat[] formats) {
if (sort.getSort().length != formats.length) {
throw new IllegalArgumentException("Number of sort field mismatch: "
+ sort.getSort().length + " != " + formats.length);
}
this.sort = sort;
this.formats = formats;
}
示例3: getSortScoreFieldPos
import org.apache.lucene.search.Sort; //導入方法依賴的package包/類
private int getSortScoreFieldPos(Sort sort) {
int sortScoreField = -1;
if (sort != null) {
for (int i = 0; i < sort.getSort().length; ++i) {
if (sort.getSort()[i].getType() == SortField.Type.SCORE) {
sortScoreField = i;
break;
}
}
}
return sortScoreField;
}
示例4: assertQuery
import org.apache.lucene.search.Sort; //導入方法依賴的package包/類
void assertQuery(Query query, Filter filter, Sort sort) throws Exception {
int size = TestUtil.nextInt(random(), 1, searcher.getIndexReader().maxDoc() / 5);
TopDocs expected = searcher.search(query, filter, size, sort, random().nextBoolean(), random().nextBoolean());
// make our actual sort, mutating original by replacing some of the
// sortfields with equivalent expressions
SortField original[] = sort.getSort();
SortField mutated[] = new SortField[original.length];
for (int i = 0; i < mutated.length; i++) {
if (random().nextInt(3) > 0) {
SortField s = original[i];
Expression expr = JavascriptCompiler.compile(s.getField());
SimpleBindings simpleBindings = new SimpleBindings();
simpleBindings.add(s);
boolean reverse = s.getType() == SortField.Type.SCORE || s.getReverse();
mutated[i] = expr.getSortField(simpleBindings, reverse);
} else {
mutated[i] = original[i];
}
}
Sort mutatedSort = new Sort(mutated);
TopDocs actual = searcher.search(query, filter, size, mutatedSort, random().nextBoolean(), random().nextBoolean());
CheckHits.checkEqual(query, expected.scoreDocs, actual.scoreDocs);
if (size < actual.totalHits) {
expected = searcher.searchAfter(expected.scoreDocs[size-1], query, filter, size, sort);
actual = searcher.searchAfter(actual.scoreDocs[size-1], query, filter, size, mutatedSort);
CheckHits.checkEqual(query, expected.scoreDocs, actual.scoreDocs);
}
}
示例5: FunctionAllGroupHeadsCollector
import org.apache.lucene.search.Sort; //導入方法依賴的package包/類
/**
* Constructs a {@link FunctionAllGroupHeadsCollector} instance.
*
* @param groupBy The {@link ValueSource} to group by
* @param vsContext The ValueSource context
* @param sortWithinGroup The sort within a group
*/
public FunctionAllGroupHeadsCollector(ValueSource groupBy, Map<?, ?> vsContext, Sort sortWithinGroup) {
super(sortWithinGroup.getSort().length);
groups = new HashMap<>();
this.sortWithinGroup = sortWithinGroup;
this.groupBy = groupBy;
this.vsContext = vsContext;
final SortField[] sortFields = sortWithinGroup.getSort();
for (int i = 0; i < sortFields.length; i++) {
reversed[i] = sortFields[i].getReverse() ? -1 : 1;
}
}
示例6: GroupHead
import org.apache.lucene.search.Sort; //導入方法依賴的package包/類
@SuppressWarnings({"unchecked","rawtypes"})
private GroupHead(MutableValue groupValue, Sort sort, int doc) throws IOException {
super(groupValue, doc + readerContext.docBase);
final SortField[] sortFields = sort.getSort();
comparators = new FieldComparator[sortFields.length];
for (int i = 0; i < sortFields.length; i++) {
comparators[i] = sortFields[i].getComparator(1, i).setNextReader(readerContext);
comparators[i].setScorer(scorer);
comparators[i].copy(0, doc);
comparators[i].setBottom(0);
}
}
示例7: GroupComparator
import org.apache.lucene.search.Sort; //導入方法依賴的package包/類
public GroupComparator(Sort groupSort) throws IOException {
final SortField[] sortFields = groupSort.getSort();
comparators = new FieldComparator<?>[sortFields.length];
reversed = new int[sortFields.length];
for (int compIDX = 0; compIDX < sortFields.length; compIDX++) {
final SortField sortField = sortFields[compIDX];
comparators[compIDX] = sortField.getComparator(1, compIDX);
reversed[compIDX] = sortField.getReverse() ? -1 : 1;
}
}
示例8: getComparator
import org.apache.lucene.search.Sort; //導入方法依賴的package包/類
private Comparator<GroupDoc> getComparator(Sort sort, final boolean sortByScoreOnly, final int[] fieldIdToDocID) {
final SortField[] sortFields = sort.getSort();
return new Comparator<GroupDoc>() {
@Override
public int compare(GroupDoc d1, GroupDoc d2) {
for (SortField sf : sortFields) {
final int cmp;
if (sf.getType() == SortField.Type.SCORE) {
if (d1.score > d2.score) {
cmp = -1;
} else if (d1.score < d2.score) {
cmp = 1;
} else {
cmp = sortByScoreOnly ? fieldIdToDocID[d1.id] - fieldIdToDocID[d2.id] : 0;
}
} else if (sf.getField().equals("sort1")) {
cmp = d1.sort1.compareTo(d2.sort1);
} else if (sf.getField().equals("sort2")) {
cmp = d1.sort2.compareTo(d2.sort2);
} else if (sf.getField().equals("sort3")) {
cmp = d1.sort3.compareTo(d2.sort3);
} else {
assertEquals(sf.getField(), "id");
cmp = d1.id - d2.id;
}
if (cmp != 0) {
return sf.getReverse() ? -cmp : cmp;
}
}
// Our sort always fully tie breaks:
fail();
return 0;
}
};
}
示例9: includesScore
import org.apache.lucene.search.Sort; //導入方法依賴的package包/類
public static boolean includesScore(Sort sort) {
if (sort==null) return true;
for (SortField sf : sort.getSort()) {
if (sf.getType() == SortField.Type.SCORE) return true;
}
return false;
}
示例10: searchAuditPhrase
import org.apache.lucene.search.Sort; //導入方法依賴的package包/類
public List<Audit> searchAuditPhrase(int fromRownum, int maxRownums, @NotNull UnaryOperator<Predicates> where) {
FullTextEntityManager fullTextEntityManager = getFullTextEntityManager(em);
QueryBuilder qb = fullTextEntityManager.getSearchFactory()
.buildQueryBuilder()
.forEntity(Audit.class)
.get();
Function<Matcher<?>, Query> query = m ->
qb.phrase()
.onField(m.getFieldName())
.sentence(m.getSearchedText() == null ? null : m.getSearchedText().toString())
.createQuery();
BiFunction<MustJunction, Matcher<?>, MustJunction> and = (j, m) -> j.must(query.apply(m));
Predicates p = where.apply(predicates());
MustJunction junction =
p.getMatchers()
.stream()
.reduce(null, (j, m) -> j == null ? qb.bool().must(query.apply(m)) : and.apply(j, m), (a, b) -> a);
Query luceneQuery = junction.createQuery();
FullTextQuery ftq = fullTextEntityManager.createFullTextQuery(luceneQuery, Audit.class);
Sort sort = toSort(p.getSorters());
if (sort.getSort().length != 0) {
ftq.setSort(sort);
}
return ftq.setFirstResult(fromRownum)
.setMaxResults(maxRownums)
.getResultList();
}
示例11: searchAuditLike
import org.apache.lucene.search.Sort; //導入方法依賴的package包/類
public List<Audit> searchAuditLike(int fromRownum, int maxRownums, @NotNull UnaryOperator<Predicates> where) {
FullTextEntityManager fullTextEntityManager = getFullTextEntityManager(em);
QueryBuilder qb = fullTextEntityManager.getSearchFactory()
.buildQueryBuilder()
.forEntity(Audit.class)
.get();
Function<Matcher<?>, Query> query = m -> {
Audit e = new Audit();
INVOKER.writeProperty(e, m.getFieldName(), m.getSearchedText());
return qb.moreLikeThis()
.comparingField(m.getFieldName())
.toEntity(e)
.createQuery();
};
BiFunction<MustJunction, Matcher<?>, MustJunction> and = (j, m) -> j.must(query.apply(m));
Predicates p = where.apply(predicates());
MustJunction junction =
p.getMatchers()
.stream()
.reduce(null, (j, m) -> j == null ? qb.bool().must(query.apply(m)) : and.apply(j, m), (a, b) -> a);
Query luceneQuery = junction.createQuery();
FullTextQuery ftq = fullTextEntityManager.createFullTextQuery(luceneQuery, Audit.class);
ftq.limitExecutionTimeTo(TIMEOUT, SECONDS);
Sort sort = toSort(p.getSorters());
if (sort.getSort().length != 0) {
ftq.setSort(sort);
}
return ftq.setFirstResult(fromRownum)
.setMaxResults(maxRownums)
.getResultList();
}
示例12: CursorMark
import org.apache.lucene.search.Sort; //導入方法依賴的package包/類
/**
* Generates an empty CursorMark bound for use with the
* specified schema and {@link SortSpec}.
*
* @param schema used for basic validation
* @param sortSpec bound to this totem (un)marshalling serialized values
*/
public CursorMark(IndexSchema schema, SortSpec sortSpec) {
final SchemaField uniqueKey = schema.getUniqueKeyField();
if (null == uniqueKey) {
throw new SolrException(ErrorCode.BAD_REQUEST,
"Cursor functionality is not available unless the IndexSchema defines a uniqueKey field");
}
final Sort sort = sortSpec.getSort();
if (null == sort) {
// pure score, by definition we don't include the mandatyr uniqueKey tie breaker
throw new SolrException(ErrorCode.BAD_REQUEST,
"Cursor functionality requires a sort containing a uniqueKey field tie breaker");
}
if (!sortSpec.getSchemaFields().contains(uniqueKey)) {
throw new SolrException(ErrorCode.BAD_REQUEST,
"Cursor functionality requires a sort containing a uniqueKey field tie breaker");
}
if (0 != sortSpec.getOffset()) {
throw new SolrException(ErrorCode.BAD_REQUEST,
"Cursor functionality requires start=0");
}
for (SortField sf : sort.getSort()) {
if (sf.getType().equals(SortField.Type.DOC)) {
throw new SolrException(ErrorCode.BAD_REQUEST,
"Cursor functionality can not be used with internal doc ordering sort: _docid_");
}
}
if (sort.getSort().length != sortSpec.getSchemaFields().size()) {
throw new SolrException(ErrorCode.SERVER_ERROR,
"Cursor SortSpec failure: sort length != SchemaFields: "
+ sort.getSort().length + " != " +
sortSpec.getSchemaFields().size());
}
this.sortSpec = sortSpec;
this.values = null;
}