Пример #1
0
        public void TestDateRange()
        {
            String startDate = getLocalizedDate(2002, 1, 1, false);
            String endDate   = getLocalizedDate(2002, 1, 4, false);
            // we use the default Locale/TZ since LuceneTestCase randomizes it
            //Calendar endDateExpected = new GregorianCalendar(TimeZone.getDefault(), Locale.getDefault());
            //endDateExpected.set(2002, 1, 4, 23, 59, 59);
            //endDateExpected.set(Calendar.MILLISECOND, 999);
            DateTime endDateExpected = new GregorianCalendar().ToDateTime(2002, 1, 4, 23, 59, 59, 999);


            String defaultField      = "default";
            String monthField        = "month";
            String hourField         = "hour";
            PrecedenceQueryParser qp = new PrecedenceQueryParser(new MockAnalyzer(Random));

            IDictionary <string, DateTools.Resolution?> fieldMap = new JCG.Dictionary <string, DateTools.Resolution?>();

            // set a field specific date resolution
            fieldMap.Put(monthField, DateTools.Resolution.MONTH);
#pragma warning disable 612, 618
            qp.SetDateResolution(fieldMap);
#pragma warning restore 612, 618

            // set default date resolution to MILLISECOND
            qp.SetDateResolution(DateTools.Resolution.MILLISECOND);

            // set second field specific date resolution
            fieldMap.Put(hourField, DateTools.Resolution.HOUR);
#pragma warning disable 612, 618
            qp.SetDateResolution(fieldMap);
#pragma warning restore 612, 618

            // for this field no field specific date resolution has been set,
            // so verify if the default resolution is used
            assertDateRangeQueryEquals(qp, defaultField, startDate, endDate,
                                       endDateExpected, DateTools.Resolution.MILLISECOND);

            // verify if field specific date resolutions are used for these two fields
            assertDateRangeQueryEquals(qp, monthField, startDate, endDate,
                                       endDateExpected, DateTools.Resolution.MONTH);

            assertDateRangeQueryEquals(qp, hourField, startDate, endDate,
                                       endDateExpected, DateTools.Resolution.HOUR);
        }
Пример #2
0
        private int[] CreateExpectedGroupHeads(string searchTerm, GroupDoc[] groupDocs, Sort docSort, bool sortByScoreOnly, int[] fieldIdToDocID)
        {
            IDictionary <BytesRef, JCG.List <GroupDoc> > groupHeads = new JCG.Dictionary <BytesRef, JCG.List <GroupDoc> >();

            foreach (GroupDoc groupDoc in groupDocs)
            {
                if (!groupDoc.content.StartsWith(searchTerm, StringComparison.Ordinal))
                {
                    continue;
                }

                if (!groupHeads.TryGetValue(groupDoc.group, out JCG.List <GroupDoc> grouphead))
                {
                    JCG.List <GroupDoc> list = new JCG.List <GroupDoc>();
                    list.Add(groupDoc);
                    groupHeads[groupDoc.group] = list;
                    continue;
                }
                grouphead.Add(groupDoc);
            }

            int[] allGroupHeads = new int[groupHeads.Count];
            int   i             = 0;

            foreach (BytesRef groupValue in groupHeads.Keys)
            {
                JCG.List <GroupDoc> docs = groupHeads[groupValue];
                // LUCENENET TODO: The original API Collections.Sort does not currently exist.
                // This call ultimately results in calling TimSort, which is why this line was replaced
                // with CollectionUtil.TimSort(IList<T>, IComparer<T>).
                //
                // NOTE: List.Sort(comparer) won't work in this case because it calls the comparer when the
                // values are the same, which results in this test failing. TimSort only calls the comparer
                // when the values differ.
                //Collections.Sort(docs, GetComparer(docSort, sortByScoreOnly, fieldIdToDocID));
                CollectionUtil.TimSort(docs, GetComparer(docSort, sortByScoreOnly, fieldIdToDocID));
                allGroupHeads[i++] = docs[0].id;
            }

            return(allGroupHeads);
        }