You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@lucene.apache.org by aravinth thangasami <ar...@gmail.com> on 2019/09/20 16:18:11 UTC

Getting Matched Text and Field for a Document

Dear all,

Along with the search results, we are trying to find which text and field
gave the result.
For that, We have written a custom collector for collecting query from the
scorer along with the ScoreDoc.

Please clarify to us is there anything wrong/limitations in our approach.

Are there any other approaches for getting the matched query from the
results?


            ScoreDocExtended scoreDocExtended = new ScoreDocExtended(doc +
docBase , score);
            Object[] queries = getQueries(doc , baseScorer);
            scoreDocExtended.setQueriesMatched(queries);
            pq.add(scoreDocExtended);



    private Object[] getQueries(int docID , Scorer scorer)
    {
        Collection<Scorer.ChildScorer> children = scorer.getChildren();
        Object[] queries = new Object[children.size()];
        int i = 0;
        for (Scorer.ChildScorer childScorer : children)
        {
            Scorer child = childScorer.child;
            if(child != null)
            {
                if(child.docID() == docID)
                {
                    Query query = child.getWeight().getQuery();
                    queries[i++] = query;
                }
            }
        }
        return queries;
    }


Thanks
Aravinth.