lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aravinth thangasami <aravinththangas...@gmail.com>
Subject Getting Matched Text and Field for a Document
Date Fri, 20 Sep 2019 16:18:11 GMT
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.

Mime
View raw message