当前位置: 首页>>代码示例>>C#>>正文


C# Sort.GetSort方法代码示例

本文整理汇总了C#中Lucene.Net.Search.Sort.GetSort方法的典型用法代码示例。如果您正苦于以下问题:C# Sort.GetSort方法的具体用法?C# Sort.GetSort怎么用?C# Sort.GetSort使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Lucene.Net.Search.Sort的用法示例。


在下文中一共展示了Sort.GetSort方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetOldSort

		private Sort GetOldSort(Sort sort)
		{
			SortField[] fields = sort.GetSort();
			SortField[] oldFields = new SortField[fields.Length];
			for (int i = 0; i < fields.Length; i++)
			{
				int sortType;
				if (fields[i].GetField() != null && fields[i].GetField().Equals("string"))
				{
					sortType = SortField.STRING;
				}
				else
				{
					sortType = fields[i].GetType();
				}
				oldFields[i] = new SortField(fields[i].GetField(), sortType, fields[i].GetReverse());
				oldFields[i].SetUseLegacySearch(true);
			}
			return new Sort(oldFields);
		}
开发者ID:Rationalle,项目名称:ravendb,代码行数:20,代码来源:TestStressSort.cs

示例2: ToParentBlockJoinCollector

 /// <summary>
 ///  Creates a ToParentBlockJoinCollector.  The provided sort must
 ///  not be null.  If you pass true trackScores, all
 ///  ToParentBlockQuery instances must not use
 ///  ScoreMode.None. 
 /// </summary>
 public ToParentBlockJoinCollector(Sort sort, int numParentHits, bool trackScores, bool trackMaxScore)
 {
     // TODO: allow null sort to be specialized to relevance
     // only collector
     this.sort = sort;
     this.trackMaxScore = trackMaxScore;
     if (trackMaxScore)
     {
         maxScore = float.MinValue;
     }
     //System.out.println("numParentHits=" + numParentHits);
     this.trackScores = trackScores;
     this.numParentHits = numParentHits;
     queue = FieldValueHitQueue.Create<OneGroup>(sort.GetSort(), numParentHits);
     comparators = queue.Comparators;
     reverseMul = queue.ReverseMul;
     compEnd = comparators.Length - 1;
 }
开发者ID:Cefa68000,项目名称:lucenenet,代码行数:24,代码来源:ToParentBlockJoinCollector.cs

示例3: AccumulateGroups

        /// <summary>
        ///  Accumulates groups for the BlockJoinQuery specified by its slot.
        /// </summary>
        /// <param name="slot"> Search query's slot </param>
        /// <param name="offset"> Parent docs offset </param>
        /// <param name="maxDocsPerGroup"> Upper bound of documents per group number </param>
        /// <param name="withinGroupOffset"> Offset within each group of child docs </param>
        /// <param name="withinGroupSort"> Sort criteria within groups </param>
        /// <param name="fillSortFields"> Specifies whether to add sort fields or not </param>
        /// <returns> TopGroups for the query specified by slot </returns>
        /// <exception cref="IOException"> if there is a low-level I/O error </exception>
        private TopGroups<int> AccumulateGroups(int slot, int offset, int maxDocsPerGroup, int withinGroupOffset, Sort withinGroupSort, bool fillSortFields)
        {
            var groups = new GroupDocs<int>[sortedGroups.Length - offset];
            var fakeScorer = new FakeScorer();

            int totalGroupedHitCount = 0;
            //System.out.println("slot=" + slot);

            for (int groupIdx = offset; groupIdx < sortedGroups.Length; groupIdx++)
            {
                OneGroup og = sortedGroups[groupIdx];
                int numChildDocs;
                if (slot == -1 || slot >= og.counts.Length)
                {
                    numChildDocs = 0;
                }
                else
                {
                    numChildDocs = og.counts[slot];
                }

                // Number of documents in group should be bounded to prevent redundant memory allocation
                int numDocsInGroup = Math.Max(1, Math.Min(numChildDocs, maxDocsPerGroup));
                //System.out.println("parent doc=" + og.doc + " numChildDocs=" + numChildDocs + " maxDocsPG=" + maxDocsPerGroup);

                // At this point we hold all docs w/ in each group, unsorted; we now sort them:
                Collector collector;
                if (withinGroupSort == null)
                {
                    //System.out.println("sort by score");
                    // Sort by score
                    if (!trackScores)
                    {
                        throw new ArgumentException("cannot sort by relevance within group: trackScores=false");
                    }
                    collector = TopScoreDocCollector.Create(numDocsInGroup, true);
                }
                else
                {
                    // Sort by fields
                    collector = TopFieldCollector.Create(withinGroupSort, numDocsInGroup, fillSortFields, trackScores, trackMaxScore, true);
                }

                collector.Scorer = fakeScorer;
                collector.NextReader = og.readerContext;
                for (int docIdx = 0; docIdx < numChildDocs; docIdx++)
                {
                    //System.out.println("docIDX=" + docIDX + " vs " + og.docs[slot].length);
                    int doc = og.docs[slot][docIdx];
                    fakeScorer.doc = doc;
                    if (trackScores)
                    {
                        fakeScorer._score = og.scores[slot][docIdx];
                    }
                    collector.Collect(doc);
                }
                totalGroupedHitCount += numChildDocs;

                object[] groupSortValues;

                if (fillSortFields)
                {
                    groupSortValues = new object[comparators.Length];
                    for (int sortFieldIdx = 0; sortFieldIdx < comparators.Length; sortFieldIdx++)
                    {
                        groupSortValues[sortFieldIdx] = comparators[sortFieldIdx].Value(og.Slot);
                    }
                }
                else
                {
                    groupSortValues = null;
                }

                TopDocs topDocs;
                if (withinGroupSort == null)
                {
                    var tempCollector = (TopScoreDocCollector) collector;
                    topDocs = tempCollector.TopDocs(withinGroupOffset, numDocsInGroup);
                }
                else
                {
                    var tempCollector = (TopFieldCollector) collector;
                    topDocs = tempCollector.TopDocs(withinGroupOffset, numDocsInGroup);
                }

                groups[groupIdx - offset] = new GroupDocs<int>(og.Score, topDocs.MaxScore, numChildDocs, topDocs.ScoreDocs, og.Doc, groupSortValues);
            }

            return new TopGroups<int>(new TopGroups<int>(sort.GetSort(), withinGroupSort == null ? null : withinGroupSort.GetSort(), 0, totalGroupedHitCount, groups, maxScore), totalHitCount);
//.........这里部分代码省略.........
开发者ID:Cefa68000,项目名称:lucenenet,代码行数:101,代码来源:ToParentBlockJoinCollector.cs

示例4: AssertQuery

 internal virtual void AssertQuery(Query query, Filter filter, Sort sort)
 {
     int size = TestUtil.NextInt(Random(), 1, searcher.IndexReader.MaxDoc / 5);
     TopDocs expected = searcher.Search(query, filter, size, sort, Random().NextBoolean
         (), Random().NextBoolean());
     // make our actual sort, mutating original by replacing some of the 
     // sortfields with equivalent expressions
     SortField[] original = sort.GetSort();
     SortField[] mutated = new SortField[original.Length];
     for (int i = 0; i < mutated.Length; i++)
     {
         if (Random().Next(3) > 0)
         {
             SortField s = original[i];
             Expression expr = JavascriptCompiler.Compile(s.Field);
             SimpleBindings simpleBindings = new SimpleBindings();
             simpleBindings.Add(s);
             bool reverse = s.Type == SortField.Type_e.SCORE || s.Reverse;
             mutated[i] = expr.GetSortField(simpleBindings, reverse);
         }
         else
         {
             mutated[i] = original[i];
         }
     }
     Sort mutatedSort = new Sort(mutated);
     TopDocs actual = searcher.Search(query, filter, size, mutatedSort, Random().NextBoolean
         (), Random().NextBoolean());
     CheckHits.CheckEqual(query, expected.ScoreDocs, actual.ScoreDocs);
     if (size < actual.TotalHits)
     {
         expected = searcher.SearchAfter(expected.ScoreDocs[size - 1], query, filter, size
             , sort);
         actual = searcher.SearchAfter(actual.ScoreDocs[size - 1], query, filter, size, mutatedSort
             );
         CheckHits.CheckEqual(query, expected.ScoreDocs, actual.ScoreDocs);
     }
 }
开发者ID:ChristopherHaws,项目名称:lucenenet,代码行数:38,代码来源:TestExpressionSorts.cs


注:本文中的Lucene.Net.Search.Sort.GetSort方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。