public virtual void TestEquals() { Expression expr = JavascriptCompiler.Compile("sqrt(_score) + ln(popularity)"); SimpleBindings bindings = new SimpleBindings(); bindings.Add(new SortField("_score", SortFieldType.SCORE)); bindings.Add(new SortField("popularity", SortFieldType.INT32)); SimpleBindings otherBindings = new SimpleBindings(); otherBindings.Add(new SortField("_score", SortFieldType.INT64)); otherBindings.Add(new SortField("popularity", SortFieldType.INT32)); SortField sf1 = expr.GetSortField(bindings, true); // different order SortField sf2 = expr.GetSortField(bindings, false); Assert.IsFalse(sf1.Equals(sf2)); // different bindings sf2 = expr.GetSortField(otherBindings, true); Assert.IsFalse(sf1.Equals(sf2)); // different expression Expression other = JavascriptCompiler.Compile("popularity/2"); sf2 = other.GetSortField(bindings, true); Assert.IsFalse(sf1.Equals(sf2)); // null Assert.IsFalse(sf1.Equals(null)); // same instance: Assert.AreEqual(sf1, sf1); }
/// <summary> /// Uses the provided /// <see cref="Lucene.Net.Queries.Function.ValueSource">Lucene.Net.Queries.Function.ValueSource /// </see> /// to assign second /// pass scores. /// </summary> public ExpressionRescorer(Expression expression, Bindings bindings) : base(new Sort (expression.GetSortField(bindings, true))) { this.expression = expression; this.bindings = bindings; }
internal virtual void AssertQuery(Query query, Filter filter, Sort sort) { int size = TestUtil.NextInt(Random(), 1, searcher.IndexReader.MaxDoc / 5); TopDocs expected = searcher.Search(query, filter, size, sort, Random().NextBoolean (), Random().NextBoolean()); // make our actual sort, mutating original by replacing some of the // sortfields with equivalent expressions SortField[] original = sort.GetSort(); SortField[] mutated = new SortField[original.Length]; for (int i = 0; i < mutated.Length; i++) { if (Random().Next(3) > 0) { SortField s = original[i]; Expression expr = JavascriptCompiler.Compile(s.Field); SimpleBindings simpleBindings = new SimpleBindings(); simpleBindings.Add(s); bool reverse = s.Type == SortFieldType.SCORE || s.IsReverse; mutated[i] = expr.GetSortField(simpleBindings, reverse); } else { mutated[i] = original[i]; } } Sort mutatedSort = new Sort(mutated); TopDocs actual = searcher.Search(query, filter, size, mutatedSort, Random().NextBoolean (), Random().NextBoolean()); CheckHits.CheckEqual(query, expected.ScoreDocs, actual.ScoreDocs); if (size < actual.TotalHits) { expected = searcher.SearchAfter(expected.ScoreDocs[size - 1], query, filter, size , sort); actual = searcher.SearchAfter(actual.ScoreDocs[size - 1], query, filter, size, mutatedSort ); CheckHits.CheckEqual(query, expected.ScoreDocs, actual.ScoreDocs); } }