2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 package org.apache.lucene.spatial.tier;
19 import java.io.IOException;
20 import java.util.List;
22 import org.apache.lucene.index.IndexReader;
23 import org.apache.lucene.index.Term;
24 import org.apache.lucene.index.TermDocs;
25 import org.apache.lucene.search.Filter;
26 import org.apache.lucene.search.DocIdSet;
27 import org.apache.lucene.util.NumericUtils;
28 import org.apache.lucene.util.FixedBitSet;
31 * <p><font color="red"><b>NOTE:</b> This API is still in
32 * flux and might change in incompatible ways in the next
35 public class CartesianShapeFilter extends Filter {
37 private final Shape shape;
38 private final String fieldName;
40 CartesianShapeFilter(final Shape shape, final String fieldName){
42 this.fieldName = fieldName;
46 public DocIdSet getDocIdSet(final IndexReader reader) throws IOException {
47 final FixedBitSet bits = new FixedBitSet(reader.maxDoc());
48 final TermDocs termDocs = reader.termDocs();
49 final List<Double> area = shape.getArea();
52 final Term term = new Term(fieldName);
53 // iterate through each boxid
54 for (int i =0; i< sz; i++) {
55 double boxId = area.get(i).doubleValue();
56 termDocs.seek(term.createTerm(NumericUtils.doubleToPrefixCoded(boxId)));
57 // iterate through all documents
58 // which have this boxId
59 while (termDocs.next()) {
60 bits.set(termDocs.doc());