Search in sources :

Example 11 with ToParentBlockJoinQuery

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);
}
Also used : MultiTermQuery(org.apache.lucene.search.MultiTermQuery) SpanTermQuery(org.apache.lucene.search.spans.SpanTermQuery) TermQuery(org.apache.lucene.search.TermQuery) CannedTokenStream(org.apache.lucene.analysis.CannedTokenStream) TokenStream(org.apache.lucene.analysis.TokenStream) QueryBitSetProducer(org.apache.lucene.search.join.QueryBitSetProducer) BitSetProducer(org.apache.lucene.search.join.BitSetProducer) ToParentBlockJoinQuery(org.apache.lucene.search.join.ToParentBlockJoinQuery) QueryBitSetProducer(org.apache.lucene.search.join.QueryBitSetProducer) Term(org.apache.lucene.index.Term) IntPoint(org.apache.lucene.document.IntPoint)

Example 12 with ToParentBlockJoinQuery

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;
}
Also used : BooleanQuery(org.apache.lucene.search.BooleanQuery) TermQuery(org.apache.lucene.search.TermQuery) ToParentBlockJoinQuery(org.apache.lucene.search.join.ToParentBlockJoinQuery) Term(org.apache.lucene.index.Term)

Example 13 with ToParentBlockJoinQuery

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;
    }
}
Also used : BooleanClause(org.apache.lucene.search.BooleanClause) BooleanQuery(org.apache.lucene.search.BooleanQuery) ToParentBlockJoinQuery(org.apache.lucene.search.join.ToParentBlockJoinQuery) SolrException(org.apache.solr.common.SolrException)

Aggregations

ToParentBlockJoinQuery (org.apache.lucene.search.join.ToParentBlockJoinQuery)13 Query (org.apache.lucene.search.Query)10 TermQuery (org.apache.lucene.search.TermQuery)10 ConstantScoreQuery (org.apache.lucene.search.ConstantScoreQuery)9 QueryBitSetProducer (org.apache.lucene.search.join.QueryBitSetProducer)8 Term (org.apache.lucene.index.Term)7 BooleanQuery (org.apache.lucene.search.BooleanQuery)7 Sort (org.apache.lucene.search.Sort)6 SortField (org.apache.lucene.search.SortField)6 ArrayList (java.util.ArrayList)5 MultiValueMode (org.elasticsearch.search.MultiValueMode)5 XFieldComparatorSource (org.elasticsearch.index.fielddata.IndexFieldData.XFieldComparatorSource)4 Document (org.apache.lucene.document.Document)3 StringField (org.apache.lucene.document.StringField)3 DirectoryReader (org.apache.lucene.index.DirectoryReader)3 BooleanClause (org.apache.lucene.search.BooleanClause)3 BoostQuery (org.apache.lucene.search.BoostQuery)3 IndexSearcher (org.apache.lucene.search.IndexSearcher)3 MatchAllDocsQuery (org.apache.lucene.search.MatchAllDocsQuery)3 MultiTermQuery (org.apache.lucene.search.MultiTermQuery)3