本文整理了Java中org.apache.lucene.search.Sort.rewrite()
方法的一些代码示例,展示了Sort.rewrite()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Sort.rewrite()
方法的具体详情如下:
包路径:org.apache.lucene.search.Sort
类名称:Sort
方法名:rewrite
[英]Rewrites the SortFields in this Sort, returning a new Sort if any of the fields changes during their rewriting.
[中]以这种排序方式重写SortFields,如果任何字段在重写过程中发生更改,则返回新的排序。
代码示例来源:origin: org.apache.lucene/lucene-core
private TopFieldDocs searchAfter(FieldDoc after, Query query, int numHits, Sort sort,
boolean doDocScores, boolean doMaxScore) throws IOException {
final int limit = Math.max(1, reader.maxDoc());
if (after != null && after.doc >= limit) {
throw new IllegalArgumentException("after.doc exceeds the number of documents in the reader: after.doc="
+ after.doc + " limit=" + limit);
}
final int cappedNumHits = Math.min(numHits, limit);
final Sort rewrittenSort = sort.rewrite(this);
final CollectorManager<TopFieldCollector, TopFieldDocs> manager = new CollectorManager<TopFieldCollector, TopFieldDocs>() {
@Override
public TopFieldCollector newCollector() throws IOException {
final boolean fillFields = true;
// TODO: don't pay the price for accurate hit counts by default
return TopFieldCollector.create(rewrittenSort, cappedNumHits, after, fillFields, doDocScores, doMaxScore, true);
}
@Override
public TopFieldDocs reduce(Collection<TopFieldCollector> collectors) throws IOException {
final TopFieldDocs[] topDocs = new TopFieldDocs[collectors.size()];
int i = 0;
for (TopFieldCollector collector : collectors) {
topDocs[i++] = collector.topDocs();
}
return TopDocs.merge(rewrittenSort, 0, cappedNumHits, topDocs, true);
}
};
return search(query, manager);
}
代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.lucene
private TopFieldDocs searchAfter(FieldDoc after, Query query, int numHits, Sort sort,
boolean doDocScores, boolean doMaxScore) throws IOException {
final int limit = Math.max(1, reader.maxDoc());
if (after != null && after.doc >= limit) {
throw new IllegalArgumentException("after.doc exceeds the number of documents in the reader: after.doc="
+ after.doc + " limit=" + limit);
}
final int cappedNumHits = Math.min(numHits, limit);
final Sort rewrittenSort = sort.rewrite(this);
final CollectorManager<TopFieldCollector, TopFieldDocs> manager = new CollectorManager<TopFieldCollector, TopFieldDocs>() {
@Override
public TopFieldCollector newCollector() throws IOException {
final boolean fillFields = true;
// TODO: don't pay the price for accurate hit counts by default
return TopFieldCollector.create(rewrittenSort, cappedNumHits, after, fillFields, doDocScores, doMaxScore, true);
}
@Override
public TopFieldDocs reduce(Collection<TopFieldCollector> collectors) throws IOException {
final TopFieldDocs[] topDocs = new TopFieldDocs[collectors.size()];
int i = 0;
for (TopFieldCollector collector : collectors) {
topDocs[i++] = collector.topDocs();
}
return TopDocs.merge(rewrittenSort, 0, cappedNumHits, topDocs, true);
}
};
return search(query, manager);
}
代码示例来源:origin: renekrie/querqy
public ReRankCollector(final int reRankNumDocs,
final int length,
final Query reRankQuery,
final double reRankWeight,
final QueryCommand cmd,
final IndexSearcher searcher) throws IOException {
super(null);
this.reRankQuery = reRankQuery;
this.reRankNumDocs = reRankNumDocs;
this.length = length;
Sort sort = cmd.getSort();
if (sort == null) {
this.mainCollector = TopScoreDocCollector.create(Math.max(reRankNumDocs, length));
} else {
sort = sort.rewrite(searcher);
this.mainCollector = TopFieldCollector.create(sort, Math.max(reRankNumDocs, length), false, true, true,
true);
}
this.searcher = searcher;
this.reRankWeight = reRankWeight;
}
代码示例来源:origin: com.orientechnologies/orientdb-lucene
@Override
public OSpatialQueryContext build(Map<String, Object> query) throws Exception {
Shape shape = parseShape(query);
double distance = Optional.ofNullable(query.get(MAX_DISTANCE)).map(Number.class::cast).map(n -> n.doubleValue()).orElse(0D);
Point p = (Point) shape;
SpatialArgs args = new SpatialArgs(SpatialOperation.Intersects,
factory.context().makeCircle(p.getX(), p.getY(), DistanceUtils.dist2Degrees(distance, DistanceUtils.EARTH_MEAN_RADIUS_KM)));
Query filterQuery = manager.strategy().makeQuery(args);
DoubleValuesSource valueSource = manager.strategy().makeDistanceValueSource(p);
IndexSearcher searcher = manager.searcher();
Sort distSort = new Sort(valueSource.getSortField(false)).rewrite(searcher);
BooleanQuery q = new BooleanQuery.Builder().add(filterQuery, BooleanClause.Occur.MUST)
.add(new MatchAllDocsQuery(), BooleanClause.Occur.SHOULD).build();
return new OSpatialQueryContext(null, searcher, q, Arrays.asList(distSort.getSort())).setSpatialArgs(args);
}
代码示例来源:origin: orientechnologies/orientdb-lucene
public Object searchIntersect(OCompositeKey key, double distance, OCommandContext context) throws IOException {
double lat = ((Double) OType.convert(((OCompositeKey) key).getKeys().get(0), Double.class)).doubleValue();
double lng = ((Double) OType.convert(((OCompositeKey) key).getKeys().get(1), Double.class)).doubleValue();
SpatialOperation operation = SpatialOperation.Intersects;
Point p = ctx.makePoint(lng, lat);
SpatialArgs args = new SpatialArgs(operation, ctx.makeCircle(lng, lat,
DistanceUtils.dist2Degrees(distance, DistanceUtils.EARTH_MEAN_RADIUS_KM)));
Filter filter = strategy.makeFilter(args);
IndexSearcher searcher = getSearcher();
ValueSource valueSource = strategy.makeDistanceValueSource(p);
Sort distSort = new Sort(valueSource.getSortField(false)).rewrite(searcher);
return new LuceneResultSet(this,
new SpatialQueryContext(context, searcher, new MatchAllDocsQuery(), filter, distSort).setSpatialArgs(args));
}
代码示例来源:origin: com.orientechnologies/orientdb-lucene
public Set<OIdentifiable> searchIntersect(OCompositeKey key, double distance, OCommandContext context, OLuceneTxChanges changes)
throws IOException {
double lat = ((Double) OType.convert(((OCompositeKey) key).getKeys().get(0), Double.class)).doubleValue();
double lng = ((Double) OType.convert(((OCompositeKey) key).getKeys().get(1), Double.class)).doubleValue();
SpatialOperation operation = SpatialOperation.Intersects;
Point p = ctx.makePoint(lng, lat);
SpatialArgs args = new SpatialArgs(operation,
ctx.makeCircle(lng, lat, DistanceUtils.dist2Degrees(distance, DistanceUtils.EARTH_MEAN_RADIUS_KM)));
Query filterQuery = strategy.makeQuery(args);
IndexSearcher searcher = searcher();
DoubleValuesSource valueSource = strategy.makeDistanceValueSource(p);
Sort distSort = new Sort(valueSource.getSortField(false)).rewrite(searcher);
BooleanQuery q = new BooleanQuery.Builder().add(filterQuery, BooleanClause.Occur.MUST)
.add(new MatchAllDocsQuery(), BooleanClause.Occur.SHOULD).build();
OLuceneQueryContext queryContext = new OSpatialQueryContext(context, searcher, q, Arrays.asList(distSort.getSort()))
.setSpatialArgs(args).withChanges(changes);
return new OLuceneResultSet(this, queryContext, EMPTY_METADATA);
}
代码示例来源:origin: com.orientechnologies/orientdb-lucene
@Override
public OSpatialQueryContext build(Map<String, Object> query) throws Exception {
Shape shape = parseShape(query);
SpatialStrategy strategy = manager.strategy();
Number distance = (Number) query.get("distance");
// SpatialArgs args1 = new SpatialArgs(SpatialOperation.Intersects, shape);
//
// Filter filter = strategy.makeFilter(args1);
// return new OSpatialQueryContext(null, manager.searcher(), new MatchAllDocsQuery(), filter);
SpatialArgs args = new SpatialArgs(SpatialOperation.Intersects, factory.context()
.makeCircle((Point) shape, DistanceUtils.dist2Degrees(distance.doubleValue() / 1000, DistanceUtils.EARTH_MEAN_RADIUS_KM)));
// Filter filter = strategy.makeFilter(args);
Query filterQuery = strategy.makeQuery(args);
IndexSearcher searcher = manager.searcher();
DoubleValuesSource valueSource = strategy.makeDistanceValueSource((Point) shape);
Sort distSort = new Sort(valueSource.getSortField(false)).rewrite(searcher);
BooleanQuery q = new BooleanQuery.Builder().add(filterQuery, BooleanClause.Occur.MUST)
.add(new MatchAllDocsQuery(), BooleanClause.Occur.SHOULD).build();
return new OSpatialQueryContext(null, searcher, q, Arrays.asList(distSort.getSort())).setSpatialArgs(args);
}
内容来源于网络,如有侵权,请联系作者删除!