use of org.apache.lucene.search.join.ToParentBlockJoinQuery in project lucene-solr by apache.
the class SynonymTokenizer method testToParentBlockJoinQuery.
public void testToParentBlockJoinQuery() throws Exception {
BitSetProducer parentFilter = new QueryBitSetProducer(new TermQuery(new Term(FIELD_NAME, "parent")));
query = new ToParentBlockJoinQuery(new TermQuery(new Term(FIELD_NAME, "child")), parentFilter, ScoreMode.None);
searcher = newSearcher(reader);
hits = searcher.search(query, 100);
int maxNumFragmentsRequired = 2;
QueryScorer scorer = new QueryScorer(query, FIELD_NAME);
Highlighter highlighter = new Highlighter(this, scorer);
for (int i = 0; i < hits.totalHits; i++) {
String text = "child document";
TokenStream tokenStream = analyzer.tokenStream(FIELD_NAME, text);
highlighter.setTextFragmenter(new SimpleFragmenter(40));
highlighter.getBestFragments(tokenStream, text, maxNumFragmentsRequired, "...");
}
assertTrue("Failed to find correct number of highlights " + numHighlights + " found", numHighlights == 1);
}
use of org.apache.lucene.search.join.ToParentBlockJoinQuery in project lucene-solr by apache.
the class TestHierarchicalDocBuilder method createToParentQuery.
private ToParentBlockJoinQuery createToParentQuery(String parentType, String childField, String childFieldValue) {
BooleanQuery.Builder childQuery = new BooleanQuery.Builder();
childQuery.add(new TermQuery(new Term(childField, childFieldValue)), Occur.MUST);
ToParentBlockJoinQuery result = createToParentQuery(parentType, childQuery.build());
return result;
}
use of org.apache.lucene.search.join.ToParentBlockJoinQuery in project lucene-solr by apache.
the class BlockJoinDocSetFacetComponent method extractChildQuery.
private ToParentBlockJoinQuery extractChildQuery(Query query) {
if (!(query instanceof ToParentBlockJoinQuery)) {
if (query instanceof BooleanQuery) {
List<BooleanClause> clauses = ((BooleanQuery) query).clauses();
ToParentBlockJoinQuery once = null;
for (BooleanClause clause : clauses) {
if (clause.getQuery() instanceof ToParentBlockJoinQuery) {
if (once == null) {
once = (ToParentBlockJoinQuery) clause.getQuery();
} else {
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "can't choose between " + once + " and " + clause.getQuery());
}
}
}
if (once != null) {
return once;
}
}
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, NO_TO_PARENT_BJQ_MESSAGE);
} else {
return (ToParentBlockJoinQuery) query;
}
}
Aggregations