Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here's my solution that so far has proven to avoid duplicate results. It's in C# (for Lucene.Net) but I've started it from the Java sample so it should be easily converted back.</p> <p>The trick I used was a unique ID per search that stays unchanged while the user clicks on pagination. I already had this unique ID that I used for reporting purposes. I initialize it when the user clicks the search button and then I pass it encrypted in the query string. It's finally passed as the seed parameter in RandomOrderFieldComparatorSource (actually it's ID.GetHashCode()).</p> <p>What this means is I use the same series of random numbers for same search, so each docId gets the same sorting index even when users navigate to other result pages.</p> <p>One more note, <em>slots</em> could probably be a vector equal to pagesize.</p> <pre><code>public class RandomOrderFieldComparator : FieldComparator { Random random; List&lt;int&gt; slots = new List&lt;int&gt;(); Dictionary&lt;int, int&gt; docSortIndeces = new Dictionary&lt;int, int&gt;(); public RandomOrderFieldComparator(int? seed) { random = seed == null ? new Random() : new Random(seed.Value); } private int bottom; // Value of bottom of queue public override int Compare(int slot1, int slot2) { // TODO: there are sneaky non-branch ways to compute // -1/+1/0 sign // Cannot return values[slot1] - values[slot2] because that // may overflow int v1 = slots[slot1]; int v2 = slots[slot2]; if (v1 &gt; v2) { return 1; } else if (v1 &lt; v2) { return -1; } else { return 0; } } public override int CompareBottom(int doc) { // TODO: there are sneaky non-branch ways to compute // -1/+1/0 sign // Cannot return bottom - values[slot2] because that // may overflow int v2 = GetDocSortingIndex(doc); if (bottom &gt; v2) { return 1; } else if (bottom &lt; v2) { return -1; } else { return 0; } } public override void Copy(int slot, int doc) { if (slots.Count &gt; slot) { slots[slot] = GetDocSortingIndex(doc); } else { slots.Add(GetDocSortingIndex(doc)); } //slots[slot] = GetDocSortingIndex(doc); } public override void SetBottom(int bottom) { this.bottom = slots[bottom]; } public override System.IComparable Value(int slot) { return (System.Int32)slots[slot]; } public override void SetNextReader(IndexReader reader, int docBase) { } int GetDocSortingIndex(int docId) { if (!docSortIndeces.ContainsKey(docId)) docSortIndeces[docId] = random.Next(int.MinValue, int.MaxValue); return docSortIndeces[docId]; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload