public virtual void TestCustomIDF() { Directory indexStore = NewDirectory(); RandomIndexWriter writer = new RandomIndexWriter( #if FEATURE_INSTANCE_TESTDATA_INITIALIZATION this, #endif Random, indexStore); Add("this is a test", "object", writer); Add("a note", "note", writer); IndexReader reader = writer.GetReader(); IndexSearcher searcher = NewSearcher(reader); searcher.Similarity = new DefaultSimilarityAnonymousInnerClassHelper(this); MultiPhraseQuery query = new MultiPhraseQuery(); query.Add(new Term[] { new Term("body", "this"), new Term("body", "that") }); query.Add(new Term("body", "is")); Weight weight = query.CreateWeight(searcher); Assert.AreEqual(10f * 10f, weight.GetValueForNormalization(), 0.001f); writer.Dispose(); reader.Dispose(); indexStore.Dispose(); }
public override float GetValueForNormalization() { // we calculate sumOfSquaredWeights of the inner weight, but ignore it (just to initialize everything) if (innerWeight != null) { innerWeight.GetValueForNormalization(); } queryWeight = outerInstance.Boost; return(queryWeight * queryWeight); }
/// <summary> /// Creates a normalized weight for a top-level <see cref="Query"/>. /// The query is rewritten by this method and <see cref="Query.CreateWeight(IndexSearcher)"/> called, /// afterwards the <see cref="Weight"/> is normalized. The returned <see cref="Weight"/> /// can then directly be used to get a <see cref="Scorer"/>. /// <para/> /// @lucene.internal /// </summary> public virtual Weight CreateNormalizedWeight(Query query) { query = Rewrite(query); Weight weight = query.CreateWeight(this); float v = weight.GetValueForNormalization(); float norm = Similarity.QueryNorm(v); if (float.IsInfinity(norm) || float.IsNaN(norm)) { norm = 1.0f; } weight.Normalize(norm, 1.0f); return(weight); }
public override float GetValueForNormalization() { return(weight.GetValueForNormalization() * outerInstance.Boost * outerInstance.Boost); // boost sub-weight }
public override float GetValueForNormalization() { return(@in.GetValueForNormalization()); }
public override float GetValueForNormalization() => @in.GetValueForNormalization();