package org.apache.lucene.search; /** * Copyright 2007 The Apache Software Foundation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.apache.lucene.index.IndexReader; import org.apache.lucene.search.spans.SpanQuery; import org.apache.lucene.search.spans.Spans; import org.apache.lucene.util.OpenBitSet; import java.io.IOException; import java.util.ArrayList; import java.util.List; /** * Constrains search results to only match those which also match a provided * query. Also provides position information about where each document matches * at the cost of extra space compared with the QueryWrapperFilter. * There is an added cost to this above what is stored in a {@link QueryWrapperFilter}. Namely, * the position information for each matching document is stored. *
* This filter does not cache. See the {@link org.apache.lucene.search.CachingSpanFilter} for a wrapper that * caches. * * * @version $Id:$ */ public class SpanQueryFilter extends SpanFilter { protected SpanQuery query; protected SpanQueryFilter() { } /** Constructs a filter which only matches documents matching *query.
* @param query The {@link org.apache.lucene.search.spans.SpanQuery} to use as the basis for the Filter.
*/
public SpanQueryFilter(SpanQuery query) {
this.query = query;
}
@Override
public DocIdSet getDocIdSet(IndexReader reader) throws IOException {
SpanFilterResult result = bitSpans(reader);
return result.getDocIdSet();
}
@Override
public SpanFilterResult bitSpans(IndexReader reader) throws IOException {
final OpenBitSet bits = new OpenBitSet(reader.maxDoc());
Spans spans = query.getSpans(reader);
List