@Override public void indexingDone() { try { spellChecker = new DirectSpellChecker(); spellChecker.setMaxEdits(2); spellChecker.setAccuracy(0.1f); spellChecker.setMinPrefix(0); reader = DirectoryReader.open(writer); fuzzySuggester = new FuzzySuggester(directory, "", writer.getAnalyzer()); Dictionary dict = new DocumentValueSourceDictionary(reader, WORD_FIELD, new LongValuesSource() { @Override public boolean needsScores() { return false; } @Override public LongValues getValues(LeafReaderContext ctx, DoubleValues scores) throws IOException { return null; } }); fuzzySuggester.build(dict); writer.close(); searcher = new IndexSearcher(DirectoryReader.open(directory)); } catch (IOException e) { throw new RuntimeException(e); } }
@Override public Scorer scorer(LeafReaderContext context, Supplier<LtrRanker.FeatureVector> vectorSupplier) throws IOException { Bindings bindings = new Bindings(){ @Override public DoubleValuesSource getDoubleValuesSource(String name) { return new FVDoubleValuesSource(vectorSupplier, features.featureOrdinal(name)); } }; DocIdSetIterator iterator = DocIdSetIterator.all(context.reader().maxDoc()); DoubleValuesSource src = expression.getDoubleValuesSource(bindings); DoubleValues values = src.getValues(context, null); return new DValScorer(this, iterator, values); }
@Override public Explanation explain(LeafReaderContext context, LtrRanker.FeatureVector vector, int doc) throws IOException { Bindings bindings = new Bindings(){ @Override public DoubleValuesSource getDoubleValuesSource(String name) { return new FVDoubleValuesSource(() -> vector, features.featureOrdinal(name)); } }; DoubleValuesSource src = expression.getDoubleValuesSource(bindings); DoubleValues values = src.getValues(context, null); values.advanceExact(doc); return Explanation.match((float) values.doubleValue(), "Evaluation of derived expression: " + expression.sourceText); }
@Override public DoubleValues getValues(LeafReaderContext ctx, DoubleValues scores) throws IOException { return new DoubleValues() { @Override public double doubleValue() throws IOException { assert vectorSupplier.get() != null; return vectorSupplier.get().getFeatureScore(ordinal); } @Override public boolean advanceExact(int doc) throws IOException { return true; } }; }
@Override public DoubleValues getValues(LeafReaderContext ctx, DoubleValues scores) throws IOException { return fv; }
DValScorer(Weight weight, DocIdSetIterator iterator, DoubleValues values) { super(weight); this.iterator = iterator; this.values = values; }