Sort() public method

Returns the values array sorted by the referenced byte values.

Note: this is a destructive operation. #clear() must be called in order to reuse this BytesRefHash instance.

public Sort ( IComparer comp ) : int[]
comp IComparer /// the used for sorting
return int[]
コード例 #1
0
ファイル: TermsQuery.cs プロジェクト: Cefa68000/lucenenet
 /// <summary>
 /// 
 /// </summary>
 /// <param name="field">The field that should contain terms that are specified in the previous parameter.</param>
 /// <param name="fromQuery"></param>
 /// <param name="terms">The terms that matching documents should have. The terms must be sorted by natural order.</param>
 internal TermsQuery(string field, Query fromQuery, BytesRefHash terms)
     : base(field)
 {
     _fromQuery = fromQuery;
     _terms = terms;
     _ords = terms.Sort(BytesRef.UTF8SortedAsUnicodeComparer);
 }
コード例 #2
0
ファイル: TestBytesRefHash.cs プロジェクト: zfxsss/lucenenet
        public virtual void TestSort()
        {
            BytesRef @ref = new BytesRef();
            int      num  = AtLeast(2);

            for (int j = 0; j < num; j++)
            {
                SortedSet <string> strings = new SortedSet <string>();
                for (int k = 0; k < 797; k++)
                {
                    string str;
                    do
                    {
                        str = TestUtil.RandomRealisticUnicodeString(Random(), 1000);
                    } while (str.Length == 0);
                    @ref.CopyChars(str);
                    Hash.Add(@ref);
                    strings.Add(str);
                }
                // We use the UTF-16 comparator here, because we need to be able to
                // compare to native String.CompareTo() [UTF-16]:
                int[] sort = Hash.Sort(BytesRef.UTF8SortedAsUTF16Comparer);
                Assert.IsTrue(strings.Count < sort.Length);
                int      i       = 0;
                BytesRef scratch = new BytesRef();
                foreach (string @string in strings)
                {
                    @ref.CopyChars(@string);
                    Assert.AreEqual(@ref, Hash.Get(sort[i++], scratch));
                }
                Hash.Clear();
                Assert.AreEqual(0, Hash.Size());
                Hash.Reinit();
            }
        }
コード例 #3
0
 internal TermsIncludingScoreQuery(string field, bool multipleValuesPerDocument, BytesRefHash terms,
     float[] scores, Query originalQuery)
 {
     _field = field;
     _multipleValuesPerDocument = multipleValuesPerDocument;
     _terms = terms;
     _scores = scores;
     _originalQuery = originalQuery;
     _ords = terms.Sort(BytesRef.UTF8SortedAsUnicodeComparer);
     _unwrittenOriginalQuery = originalQuery;
 }
コード例 #4
0
ファイル: TestBytesRefHash.cs プロジェクト: clieben/lucenenet
        public virtual void TestSort()
        {
            BytesRef @ref = new BytesRef();
            int      num  = AtLeast(2);

            for (int j = 0; j < num; j++)
            {
                // LUCENENET specific - to ensure sorting strings works the same in the SortedSet,
                // we need to use StringComparer.Ordinal, which compares strings the same
                // way they are done in Java.
                JCG.SortedSet <string> strings = new JCG.SortedSet <string>(StringComparer.Ordinal);
                for (int k = 0; k < 797; k++)
                {
                    string str;
                    do
                    {
                        str = TestUtil.RandomRealisticUnicodeString(Random, 1000);
                    } while (str.Length == 0);
                    @ref.CopyChars(str);
                    Hash.Add(@ref);
                    strings.Add(str);
                }
                // We use the UTF-16 comparer here, because we need to be able to
                // compare to native String.CompareTo() [UTF-16]:
#pragma warning disable 612, 618
                int[] sort = Hash.Sort(BytesRef.UTF8SortedAsUTF16Comparer);
#pragma warning restore 612, 618
                Assert.IsTrue(strings.Count < sort.Length);
                int      i       = 0;
                BytesRef scratch = new BytesRef();
                foreach (string @string in strings)
                {
                    @ref.CopyChars(@string);
                    Assert.AreEqual(@ref, Hash.Get(sort[i++], scratch));
                }
                Hash.Clear();
                Assert.AreEqual(0, Hash.Count);
                Hash.Reinit();
            }
        }