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); }
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); }
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; }
@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); }
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)); }
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); }
@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); }