/** * Returns the identifier of this {@link Sorter}. * <p>This identifier is similar to {@link Object#hashCode()} and should be * chosen so that two instances of this class that sort documents likewise * will have the same identifier. On the contrary, this identifier should be * different on different {@link Sort sorts}. */ public String getID() { return sort.toString(); }
@Override public Explanation explain(IndexSearcher searcher, Explanation firstPassExplanation, int docID) throws IOException { TopDocs oneHit = new TopDocs(1, new ScoreDoc[] {new ScoreDoc(docID, firstPassExplanation.getValue())}); TopDocs hits = rescore(searcher, oneHit, 1); assert hits.totalHits == 1; List<Explanation> subs = new ArrayList<>(); // Add first pass: Explanation first = Explanation.match(firstPassExplanation.getValue(), "first pass score", firstPassExplanation); subs.add(first); FieldDoc fieldDoc = (FieldDoc) hits.scoreDocs[0]; // Add sort values: SortField[] sortFields = sort.getSort(); for(int i=0;i<sortFields.length;i++) { subs.add(Explanation.match(0.0f, "sort field " + sortFields[i].toString() + " value=" + fieldDoc.fields[i])); } // TODO: if we could ask the Sort to explain itself then // we wouldn't need the separate ExpressionRescorer... return Explanation.match(0.0f, "sort field values for sort=" + sort.toString(), subs); } }
/** * Returns the identifier of this {@link Sorter}. * <p>This identifier is similar to {@link Object#hashCode()} and should be * chosen so that two instances of this class that sort documents likewise * will have the same identifier. On the contrary, this identifier should be * different on different {@link Sort sorts}. */ public String getID() { return sort.toString(); }
/** * Returns the identifier of this {@link Sorter}. * <p>This identifier is similar to {@link Object#hashCode()} and should be * chosen so that two instances of this class that sort documents likewise * will have the same identifier. On the contrary, this identifier should be * different on different {@link Sort sorts}. */ public String getID() { return sort.toString(); }
/** * Returns the identifier of this {@link Sorter}. * <p>This identifier is similar to {@link Object#hashCode()} and should be * chosen so that two instances of this class that sort documents likewise * will have the same identifier. On the contrary, this identifier should be * different on different {@link Sort sorts}. */ public String getID() { return sort.toString(); }
/** Returns {@code true} if the given {@code reader} is sorted by the * {@code sort} given. Typically the given {@code sort} would be the * {@link SortingMergePolicy#getSort()} order of a {@link SortingMergePolicy}. */ public static boolean isSorted(LeafReader reader, Sort sort) { String description = getSortDescription(reader); if (description != null && description.equals(sort.toString())) { return true; } return false; }
/** Returns {@code true} if the given {@code reader} is sorted by the * {@code sort} given. Typically the given {@code sort} would be the * {@link SortingMergePolicy#getSort()} order of a {@link SortingMergePolicy}. */ public static boolean isSorted(LeafReader reader, Sort sort) { String description = getSortDescription(reader); if (description != null && description.equals(sort.toString())) { return true; } return false; }
@Override public Explanation explain(IndexSearcher searcher, Explanation firstPassExplanation, int docID) throws IOException { TopDocs oneHit = new TopDocs(1, new ScoreDoc[] {new ScoreDoc(docID, firstPassExplanation.getValue())}); TopDocs hits = rescore(searcher, oneHit, 1); assert hits.totalHits == 1; List<Explanation> subs = new ArrayList<>(); // Add first pass: Explanation first = Explanation.match(firstPassExplanation.getValue(), "first pass score", firstPassExplanation); subs.add(first); FieldDoc fieldDoc = (FieldDoc) hits.scoreDocs[0]; // Add sort values: SortField[] sortFields = sort.getSort(); for(int i=0;i<sortFields.length;i++) { subs.add(Explanation.match(0.0f, "sort field " + sortFields[i].toString() + " value=" + fieldDoc.fields[i])); } // TODO: if we could ask the Sort to explain itself then // we wouldn't need the separate ExpressionRescorer... return Explanation.match(0.0f, "sort field values for sort=" + sort.toString(), subs); } }
@Override public Explanation explain(IndexSearcher searcher, Explanation firstPassExplanation, int docID) throws IOException { TopDocs oneHit = new TopDocs(1, new ScoreDoc[] {new ScoreDoc(docID, firstPassExplanation.getValue())}); TopDocs hits = rescore(searcher, oneHit, 1); assert hits.totalHits == 1; List<Explanation> subs = new ArrayList<>(); // Add first pass: Explanation first = Explanation.match(firstPassExplanation.getValue(), "first pass score", firstPassExplanation); subs.add(first); FieldDoc fieldDoc = (FieldDoc) hits.scoreDocs[0]; // Add sort values: SortField[] sortFields = sort.getSort(); for(int i=0;i<sortFields.length;i++) { subs.add(Explanation.match(0.0f, "sort field " + sortFields[i].toString() + " value=" + fieldDoc.fields[i])); } // TODO: if we could ask the Sort to explain itself then // we wouldn't need the separate ExpressionRescorer... return Explanation.match(0.0f, "sort field values for sort=" + sort.toString(), subs); } }
@Override public Explanation explain(IndexSearcher searcher, Explanation firstPassExplanation, int docID) throws IOException { TopDocs oneHit = new TopDocs(1, new ScoreDoc[] {new ScoreDoc(docID, firstPassExplanation.getValue())}); TopDocs hits = rescore(searcher, oneHit, 1); assert hits.totalHits == 1; List<Explanation> subs = new ArrayList<>(); // Add first pass: Explanation first = Explanation.match(firstPassExplanation.getValue(), "first pass score", firstPassExplanation); subs.add(first); FieldDoc fieldDoc = (FieldDoc) hits.scoreDocs[0]; // Add sort values: SortField[] sortFields = sort.getSort(); for(int i=0;i<sortFields.length;i++) { subs.add(Explanation.match(0.0f, "sort field " + sortFields[i].toString() + " value=" + fieldDoc.fields[i])); } // TODO: if we could ask the Sort to explain itself then // we wouldn't need the separate ExpressionRescorer... return Explanation.match(0.0f, "sort field values for sort=" + sort.toString(), subs); } }