Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Search: Allow to pass a search filter, applying only on the query (an…
…d not on facets for example), closes #650.
- Loading branch information
Showing
12 changed files
with
297 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
...elasticsearch/src/main/java/org/elasticsearch/common/lucene/search/FilteredCollector.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Licensed to Elastic Search and Shay Banon under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. Elastic Search licenses this | ||
* file to you 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. | ||
*/ | ||
|
||
package org.elasticsearch.common.lucene.search; | ||
|
||
import org.apache.lucene.index.IndexReader; | ||
import org.apache.lucene.search.Collector; | ||
import org.apache.lucene.search.Filter; | ||
import org.apache.lucene.search.Scorer; | ||
import org.elasticsearch.common.lucene.docset.DocSet; | ||
import org.elasticsearch.common.lucene.docset.DocSets; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* @author kimchy (shay.banon) | ||
*/ | ||
public class FilteredCollector extends Collector { | ||
|
||
private final Collector collector; | ||
|
||
private final Filter filter; | ||
|
||
private DocSet docSet; | ||
|
||
public FilteredCollector(Collector collector, Filter filter) { | ||
this.collector = collector; | ||
this.filter = filter; | ||
} | ||
|
||
@Override public void setScorer(Scorer scorer) throws IOException { | ||
collector.setScorer(scorer); | ||
} | ||
|
||
@Override public void collect(int doc) throws IOException { | ||
if (docSet.get(doc)) { | ||
collector.collect(doc); | ||
} | ||
} | ||
|
||
@Override public void setNextReader(IndexReader reader, int docBase) throws IOException { | ||
docSet = DocSets.convert(reader, filter.getDocIdSet(reader)); | ||
} | ||
|
||
@Override public boolean acceptsDocsOutOfOrder() { | ||
return collector.acceptsDocsOutOfOrder(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
.../elasticsearch/src/main/java/org/elasticsearch/search/query/FilterBinaryParseElement.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Licensed to Elastic Search and Shay Banon under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. Elastic Search licenses this | ||
* file to you 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. | ||
*/ | ||
|
||
package org.elasticsearch.search.query; | ||
|
||
import org.elasticsearch.common.xcontent.XContentFactory; | ||
import org.elasticsearch.common.xcontent.XContentParser; | ||
import org.elasticsearch.index.query.xcontent.XContentIndexQueryParser; | ||
import org.elasticsearch.search.SearchParseElement; | ||
import org.elasticsearch.search.internal.SearchContext; | ||
|
||
/** | ||
* @author kimchy (shay.banon) | ||
*/ | ||
public class FilterBinaryParseElement implements SearchParseElement { | ||
|
||
@Override public void parse(XContentParser parser, SearchContext context) throws Exception { | ||
XContentIndexQueryParser indexQueryParser = (XContentIndexQueryParser) context.queryParser(); | ||
byte[] filterSource = parser.binaryValue(); | ||
XContentParser fSourceParser = XContentFactory.xContent(filterSource).createParser(filterSource); | ||
try { | ||
context.parsedFilter(indexQueryParser.parseInnerFilter(fSourceParser)); | ||
} finally { | ||
fSourceParser.close(); | ||
} | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
modules/elasticsearch/src/main/java/org/elasticsearch/search/query/FilterParseElement.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Licensed to Elastic Search and Shay Banon under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. Elastic Search licenses this | ||
* file to you 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. | ||
*/ | ||
|
||
package org.elasticsearch.search.query; | ||
|
||
import org.elasticsearch.common.xcontent.XContentParser; | ||
import org.elasticsearch.index.query.xcontent.XContentIndexQueryParser; | ||
import org.elasticsearch.search.SearchParseElement; | ||
import org.elasticsearch.search.internal.SearchContext; | ||
|
||
/** | ||
* @author kimchy (shay.banon) | ||
*/ | ||
public class FilterParseElement implements SearchParseElement { | ||
|
||
@Override public void parse(XContentParser parser, SearchContext context) throws Exception { | ||
XContentIndexQueryParser indexQueryParser = (XContentIndexQueryParser) context.queryParser(); | ||
context.parsedFilter(indexQueryParser.parseInnerFilter(parser)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.