public FacetBasedBoostingScorer(FacetBasedBoostScorerBuilder parent, BoboSegmentReader reader, Scorer innerScorer) : base(innerScorer.Weight) { m_innerScorer = innerScorer; List <BoboDocScorer> list = new List <BoboDocScorer>(); foreach (var boostEntry in parent.m_boostMaps) { string facetName = boostEntry.Key; IFacetHandler handler = reader.GetFacetHandler(facetName); if (!(handler is IFacetScoreable)) { throw new ArgumentException(facetName + " does not implement IFacetScoreable"); } IFacetScoreable facetScoreable = (IFacetScoreable)handler; BoboDocScorer scorer = facetScoreable.GetDocScorer(reader, parent.m_scoringFunctionFactory, boostEntry.Value); if (scorer != null) { list.Add(scorer); } } m_facetScorers = list.ToArray(); m_docid = -1; }
public override Explanation Explain(AtomicReaderContext context, int docid) { BoboSegmentReader boboReader = (BoboSegmentReader)context.Reader; IFacetHandler fhandler = boboReader.GetFacetHandler(m_parent.m_name); if (fhandler != null) { BoboDocScorer scorer = null; if (fhandler is IFacetScoreable) { scorer = ((IFacetScoreable)fhandler).GetDocScorer(boboReader, m_parent.m_scoringFactory, m_parent.m_boostMap); Explanation exp1 = scorer.Explain(docid); Explanation exp2 = new Explanation(m_parent.Boost, "boost"); Explanation expl = new Explanation(); expl.Description = "product of:"; expl.Value = (exp1.Value * exp2.Value); expl.AddDetail(exp1); expl.AddDetail(exp2); return(expl); } else { return(null); } } return(null); }
public override FacetDataNone Load(BoboSegmentReader reader) { m_dataFacetHandler = reader.GetFacetHandler(m_dataHandlerName); if (m_dataFacetHandler is RangeFacetHandler) { if (((RangeFacetHandler)m_dataFacetHandler).HasPredefinedRanges) { throw new NotSupportedException("underlying range facet handler should not have the predefined ranges"); } } return(FacetDataNone.Instance); }
public override FacetDataNone Load(BoboSegmentReader reader) { IFacetHandler handler = reader.GetFacetHandler(m_inner); if (handler is RangeFacetHandler) { m_innerHandler = (RangeFacetHandler)handler; return(FacetDataNone.Instance); } else { throw new IOException("inner handler is not instance of RangeFacetHandler"); } }
public override FacetDataNone Load(BoboSegmentReader reader) { m_facetHandlers = new List <SimpleFacetHandler>(m_fieldsSet.Count); m_facetHandlerMap = new Dictionary <string, SimpleFacetHandler>(m_fieldsSet.Count); foreach (string name in m_fieldsSet) { IFacetHandler handler = reader.GetFacetHandler(name); if (handler == null || !(handler is SimpleFacetHandler)) { throw new InvalidOperationException("only simple facet handlers supported"); } SimpleFacetHandler sfh = (SimpleFacetHandler)handler; m_facetHandlers.Add(sfh); m_facetHandlerMap.Add(name, sfh); } return(FacetDataNone.Instance); }
// NOTE: The Weight.Scorer method lost the scoreDocsInOrder and topScorer parameters between // Lucene 4.3.0 and 4.8.0. They are not used by BoboBrowse anyway, so the code here diverges // from the original Java source to remove these two parameters. // public override Scorer Scorer(AtomicReaderContext context, bool scoreDocsInOrder, bool topScorer, Bits acceptDocs) public override Scorer GetScorer(AtomicReaderContext context, IBits acceptDocs) { AtomicReader reader = context.AtomicReader; if (reader is BoboSegmentReader) { BoboSegmentReader boboReader = (BoboSegmentReader)reader; IFacetHandler fhandler = boboReader.GetFacetHandler(m_parent.m_name); if (fhandler != null) { DocIdSetIterator dociter = null; RandomAccessFilter filter = fhandler.BuildFilter(m_parent.m_sel); if (filter != null) { RandomAccessDocIdSet docset = filter.GetRandomAccessDocIdSet(boboReader); if (docset != null) { dociter = BuildIterator(docset, boboReader, acceptDocs); } } if (dociter == null) { dociter = new MatchAllDocIdSetIterator(reader, acceptDocs); } BoboDocScorer scorer = null; if (fhandler is IFacetScoreable) { scorer = ((IFacetScoreable)fhandler).GetDocScorer(boboReader, m_parent.m_scoringFactory, m_parent.m_boostMap); } return(new FacetTermScorer(m_parent, m_similarity, dociter, scorer)); } else { logger.Error("FacetHandler is not defined for the field: " + m_parent.m_name); } return(null); } else { throw new IOException("index reader not instance of " + typeof(BoboSegmentReader)); } }
public virtual Explanation Explain(AtomicReader indexReader, int docid, Explanation innerExplaination) { if (!(indexReader is BoboSegmentReader)) { throw new ArgumentException("IndexReader is not BoboSegmentReader"); } BoboSegmentReader reader = (BoboSegmentReader)indexReader; Explanation exp = new Explanation(); exp.Description = "FacetBasedBoost"; float boost = 1.0f; foreach (var boostEntry in m_boostMaps) { string facetName = boostEntry.Key; IFacetHandler handler = reader.GetFacetHandler(facetName); if (!(handler is IFacetScoreable)) { throw new ArgumentException(facetName + " does not implement IFacetScoreable"); } IFacetScoreable facetScoreable = (IFacetScoreable)handler; BoboDocScorer scorer = facetScoreable.GetDocScorer(reader, m_scoringFunctionFactory, boostEntry.Value); float facetBoost = scorer.Score(docid); Explanation facetExp = new Explanation(); facetExp.Description = facetName; facetExp.Value = facetBoost; facetExp.AddDetail(scorer.Explain(docid)); boost *= facetBoost; exp.AddDetail(facetExp); } exp.Value = boost; exp.AddDetail(innerExplaination); return(exp); }