org.apache.lucene.spatial.prefix.TermQueryPrefixTreeStrategy Java Examples

The following examples show how to use org.apache.lucene.spatial.prefix.TermQueryPrefixTreeStrategy. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: QueryEqualsHashCodeTest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Test
public void testEqualsHashCode() {

  switch (random().nextInt(4)) {//0-3
    case 0: predicate = SpatialOperation.Contains; break;
    case 1: predicate = SpatialOperation.IsWithin; break;

    default: predicate = SpatialOperation.Intersects; break;
  }
  final SpatialPrefixTree gridQuad = new QuadPrefixTree(ctx,10);
  final SpatialPrefixTree gridGeohash = new GeohashPrefixTree(ctx,10);

  Collection<SpatialStrategy> strategies = new ArrayList<>();
  RecursivePrefixTreeStrategy recursive_geohash = new RecursivePrefixTreeStrategy(gridGeohash, "recursive_geohash");
  strategies.add(recursive_geohash);
  strategies.add(new TermQueryPrefixTreeStrategy(gridQuad, "termquery_quad"));
  strategies.add(PointVectorStrategy.newInstance(ctx, "pointvector"));
  strategies.add(BBoxStrategy.newInstance(ctx, "bbox"));
  final SerializedDVStrategy serialized = new SerializedDVStrategy(ctx, "serialized");
  strategies.add(serialized);
  strategies.add(new CompositeSpatialStrategy("composite", recursive_geohash, serialized));
  for (SpatialStrategy strategy : strategies) {
    testEqualsHashcode(strategy);
  }
}
 
Example #2
Source File: SpatialPrefixTreeTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
/**
 * A PrefixTree pruning optimization gone bad, applicable when optimize=true.
 * See <a href="https://issues.apache.org/jira/browse/LUCENE-4770">LUCENE-4770</a>.
 */
@Test
public void testBadPrefixTreePrune() throws Exception {

  trie = new QuadPrefixTree(ctx, 12);
  TermQueryPrefixTreeStrategy strategy = new TermQueryPrefixTreeStrategy(trie, "geo");
  Document doc = new Document();
  doc.add(new TextField("id", "1", Store.YES));

  Shape area = ctx.makeRectangle(-122.82, -122.78, 48.54, 48.56);

  Field[] fields = strategy.createIndexableFields(area, 0.025);
  for (Field field : fields) {
    doc.add(field);
  }
  addDocument(doc);

  Point upperleft = ctx.makePoint(-122.88, 48.54);
  Point lowerright = ctx.makePoint(-122.82, 48.62);

  Query query = strategy.makeQuery(new SpatialArgs(SpatialOperation.Intersects, ctx.makeRectangle(upperleft, lowerright)));

  commit();

  TopDocs search = indexSearcher.search(query, 10);
  ScoreDoc[] scoreDocs = search.scoreDocs;
  for (ScoreDoc scoreDoc : scoreDocs) {
    System.out.println(indexSearcher.doc(scoreDoc.doc));
  }

  assertEquals(1, search.totalHits.value);
}
 
Example #3
Source File: SpatialTermQueryPrefixTreeFieldType.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Override
protected TermQueryPrefixTreeStrategy newPrefixTreeStrategy(String fieldName) {
  return new TermQueryPrefixTreeStrategy(grid,fieldName);
}