Github user laimis commented on a diff in the pull request:
https://github.com/apache/lucenenet/pull/64#discussion_r23741072
--- Diff: src/Lucene.Net.Expressions/ExpressionComparator.cs ---
@@ -0,0 +1,94 @@
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.IO;
+using Lucene.Net.Index;
+using Lucene.Net.Queries.Function;
+using Lucene.Net.Search;
+using Lucene.Net.Support;
+
+namespace Lucene.Net.Expressions
+{
+ /// <summary>A custom comparator for sorting documents by an
expression</summary>
+ internal class ExpressionComparator : FieldComparator<double>
+ {
+ private readonly double[] values;
+
+ private double bottom;
+
+ private double topValue;
+
+ private ValueSource source;
+
+ private FunctionValues scores;
+
+ private AtomicReaderContext readerContext;
+
+ public ExpressionComparator(ValueSource source, int numHits)
+ {
+ values = new double[numHits];
+ this.source = source;
+ }
+
+ // TODO: change FieldComparator.setScorer to throw IOException
and remove this try-catch
+ public override Scorer Scorer
+ {
+ set
+ {
+ base.Scorer = value;
+ // TODO: might be cleaner to lazy-init 'source' and set
scorer after?
+
+ Debug.Assert(readerContext != null);
+ var context = new Dictionary<string, object>();
+ Debug.Assert(value != null);
+ context["scorer"] = value;
+ scores = source.GetValues(context, readerContext);
+ }
+ }
+
+ public override int Compare(int slot1, int slot2)
+ {
+ return values[slot1].CompareTo(values[slot2]);
--- End diff --
indentation
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---