Esempio n. 1
0
 public int Compare(AbstractDistinctValuesCollector.IGroupCount <IComparable> groupCount1, AbstractDistinctValuesCollector.IGroupCount <IComparable> groupCount2)
 {
     if (groupCount1.GroupValue == null)
     {
         if (groupCount2.GroupValue == null)
         {
             return(0);
         }
         return(-1);
     }
     else if (groupCount2.GroupValue == null)
     {
         return(1);
     }
     else
     {
         return(groupCount1.GroupValue.CompareTo(groupCount2.GroupValue));
     }
 }
Esempio n. 2
0
        public virtual void TestRandom()
        {
            Random random       = Random;
            int    numberOfRuns = TestUtil.NextInt32(random, 3, 6);

            for (int indexIter = 0; indexIter < numberOfRuns; indexIter++)
            {
                IndexContext context = CreateIndexContext();
                for (int searchIter = 0; searchIter < 100; searchIter++)
                {
                    IndexSearcher searcher  = NewSearcher(context.indexReader);
                    bool          useDv     = context.dvType != DocValuesType.NONE && random.nextBoolean();
                    DocValuesType dvType    = useDv ? context.dvType : DocValuesType.NONE;
                    string        term      = context.contentStrings[random.nextInt(context.contentStrings.Length)];
                    Sort          groupSort = new Sort(new SortField("id", SortFieldType.STRING));
                    int           topN      = 1 + random.nextInt(10);

                    List <AbstractDistinctValuesCollector.IGroupCount <IComparable> > expectedResult = CreateExpectedResult(context, term, groupSort, topN);

                    IAbstractFirstPassGroupingCollector <IComparable> firstCollector = CreateRandomFirstPassCollector(dvType, groupSort, groupField, topN);
                    searcher.Search(new TermQuery(new Term("content", term)), firstCollector);
                    IAbstractDistinctValuesCollector <AbstractDistinctValuesCollector.IGroupCount <IComparable> > distinctValuesCollector
                        = CreateDistinctCountCollector(firstCollector, groupField, countField, dvType);
                    searcher.Search(new TermQuery(new Term("content", term)), distinctValuesCollector);

                    // LUCENENET TODO: Try to work out how to do this without an O(n) operation
                    List <AbstractDistinctValuesCollector.IGroupCount <IComparable> > actualResult = new List <AbstractDistinctValuesCollector.IGroupCount <IComparable> >(distinctValuesCollector.Groups);

                    if (VERBOSE)
                    {
                        Console.WriteLine("Index iter=" + indexIter);
                        Console.WriteLine("Search iter=" + searchIter);
                        Console.WriteLine("1st pass collector class name=" + firstCollector.GetType().Name);
                        Console.WriteLine("2nd pass collector class name=" + distinctValuesCollector.GetType().Name);
                        Console.WriteLine("Search term=" + term);
                        Console.WriteLine("DVType=" + dvType);
                        Console.WriteLine("1st pass groups=" + firstCollector.GetTopGroups(0, false).toString());
                        Console.WriteLine("Expected:");
                        PrintGroups(expectedResult);
                        Console.WriteLine("Actual:");
                        PrintGroups(actualResult);
                        Console.Out.Flush();
                    }

                    assertEquals(expectedResult.Count, actualResult.Count);
                    for (int i = 0; i < expectedResult.size(); i++)
                    {
                        AbstractDistinctValuesCollector.IGroupCount <IComparable> expected = expectedResult[i];
                        AbstractDistinctValuesCollector.IGroupCount <IComparable> actual   = actualResult[i];
                        AssertValues(expected.GroupValue, actual.GroupValue);
                        assertEquals(expected.UniqueValues.Count(), actual.UniqueValues.Count());
                        List <IComparable> expectedUniqueValues = new List <IComparable>(expected.UniqueValues);
                        expectedUniqueValues.Sort(nullComparer);
                        List <IComparable> actualUniqueValues = new List <IComparable>(actual.UniqueValues);
                        actualUniqueValues.Sort(nullComparer);
                        for (int j = 0; j < expectedUniqueValues.size(); j++)
                        {
                            AssertValues(expectedUniqueValues[j], actualUniqueValues[j]);
                        }
                    }
                }
                context.indexReader.Dispose();
                context.directory.Dispose();
            }
        }