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


C# Search.Sort类代码示例

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


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

示例1: TestString

        public virtual void TestString()
        {
            Directory dir = NewDirectory();
            RandomIndexWriter writer = new RandomIndexWriter(Random(), dir);
            Document doc = new Document();
            doc.Add(NewStringField("value", "foo", Field.Store.YES));
            writer.AddDocument(doc);
            doc = new Document();
            doc.Add(NewStringField("value", "bar", Field.Store.YES));
            writer.AddDocument(doc);
            IndexReader ir = writer.Reader;
            writer.Dispose();

            IndexSearcher searcher = NewSearcher(ir);
            Sort sort = new Sort(new SortField("value", SortField.Type_e.STRING));

            TopDocs td = searcher.Search(new MatchAllDocsQuery(), 10, sort);
            Assert.AreEqual(2, td.TotalHits);
            // 'bar' comes before 'foo'
            Assert.AreEqual("bar", searcher.Doc(td.ScoreDocs[0].Doc).Get("value"));
            Assert.AreEqual("foo", searcher.Doc(td.ScoreDocs[1].Doc).Get("value"));

            ir.Dispose();
            dir.Dispose();
        }
开发者ID:joyanta,项目名称:lucene.net,代码行数:25,代码来源:TestSort.cs

示例2: BuildQuery

        /// <summary>
        /// 构建Query、Filter、Sort
        /// </summary>
        /// <param name="query"><see cref="Query"/></param>
        /// <param name="filter"><see cref="Filter"/></param>
        /// <param name="sort"><see cref="Sort"/></param>
        public void BuildQuery(out Query query, out Filter filter, out Sort sort)
        {
            BooleanQuery q = new BooleanQuery();
            foreach (var clause in clauses)
            {
                q.Add(clause);
            }
            query = q;

            if (filters.Count > 0)
            {
                BooleanQuery filterQuery = new BooleanQuery();
                foreach (var _filter in filters)
                    filterQuery.Add(_filter);

                filter = new QueryWrapperFilter(filterQuery);
            }
            else
            {
                filter = null;
            }

            if (sortFields.Count > 0)
                sort = new Sort(sortFields.ToArray());
            else
                sort = null;
        }
开发者ID:ClaytonWang,项目名称:Dw3cSNS,代码行数:33,代码来源:LuceneSearchBuilder.cs

示例3: TestReverse

        public void TestReverse()
        {
            Directory dir = NewDirectory();
            RandomIndexWriter writer = new RandomIndexWriter(Random(), dir, Similarity, TimeZone);
            Document doc = new Document();
            doc.Add(NewStringField("value", "foo", Field.Store.NO));
            doc.Add(NewStringField("value", "bar", Field.Store.NO));
            doc.Add(NewStringField("id", "1", Field.Store.YES));
            writer.AddDocument(doc);
            doc = new Document();
            doc.Add(NewStringField("value", "baz", Field.Store.NO));
            doc.Add(NewStringField("id", "2", Field.Store.YES));
            writer.AddDocument(doc);

            IndexReader ir = writer.Reader;
            writer.Dispose();

            IndexSearcher searcher = NewSearcher(ir);
            Sort sort = new Sort(new SortedSetSortField("value", true));

            TopDocs td = searcher.Search(new MatchAllDocsQuery(), 10, sort);
            assertEquals(2, td.TotalHits);
            // 'bar' comes before 'baz'
            assertEquals("2", searcher.Doc(td.ScoreDocs[0].Doc).Get("id"));
            assertEquals("1", searcher.Doc(td.ScoreDocs[1].Doc).Get("id"));

            ir.Dispose();
            dir.Dispose();
        }
开发者ID:apache,项目名称:lucenenet,代码行数:29,代码来源:TestSortedSetSortField.cs

示例4: TestReverseDateSort

		public virtual void  TestReverseDateSort()
		{
			IndexSearcher searcher = new IndexSearcher(directory);
			
			// Create a Sort object.  reverse is set to true.
			// problem occurs only with SortField.AUTO:
			Sort sort = new Sort(new SortField(DATE_TIME_FIELD, SortField.AUTO, true));
			
			QueryParser queryParser = new QueryParser(TEXT_FIELD, new WhitespaceAnalyzer());
			Query query = queryParser.Parse("Document");
			
			// Execute the search and process the search results.
			System.String[] actualOrder = new System.String[5];
			ScoreDoc[] hits = searcher.Search(query, null, 1000, sort).scoreDocs;
			for (int i = 0; i < hits.Length; i++)
			{
				Document document = searcher.Doc(hits[i].doc);
				System.String text = document.Get(TEXT_FIELD);
				actualOrder[i] = text;
			}
			searcher.Close();
			
			// Set up the expected order (i.e. Document 5, 4, 3, 2, 1).
			System.String[] expectedOrder = new System.String[5];
			expectedOrder[0] = "Document 5";
			expectedOrder[1] = "Document 4";
			expectedOrder[2] = "Document 3";
			expectedOrder[3] = "Document 2";
			expectedOrder[4] = "Document 1";
			
			Assert.AreEqual(new System.Collections.ArrayList(expectedOrder), new System.Collections.ArrayList(actualOrder));
		}
开发者ID:VirtueMe,项目名称:ravendb,代码行数:32,代码来源:TestDateSort.cs

示例5: TestOutOfOrderDocsScoringSort

        public virtual void TestOutOfOrderDocsScoringSort()
        {
            // Two Sort criteria to instantiate the multi/single comparators.
            Sort[] sort = new Sort[] { new Sort(SortField.FIELD_DOC), new Sort() };
            bool[][] tfcOptions = new bool[][] { new bool[] { false, false, false }, new bool[] { false, false, true }, new bool[] { false, true, false }, new bool[] { false, true, true }, new bool[] { true, false, false }, new bool[] { true, false, true }, new bool[] { true, true, false }, new bool[] { true, true, true } };
            string[] actualTFCClasses = new string[] { "OutOfOrderOneComparatorNonScoringCollector", "OutOfOrderOneComparatorScoringMaxScoreCollector", "OutOfOrderOneComparatorScoringNoMaxScoreCollector", "OutOfOrderOneComparatorScoringMaxScoreCollector", "OutOfOrderOneComparatorNonScoringCollector", "OutOfOrderOneComparatorScoringMaxScoreCollector", "OutOfOrderOneComparatorScoringNoMaxScoreCollector", "OutOfOrderOneComparatorScoringMaxScoreCollector" };

            BooleanQuery bq = new BooleanQuery();
            // Add a Query with SHOULD, since bw.Scorer() returns BooleanScorer2
            // which delegates to BS if there are no mandatory clauses.
            bq.Add(new MatchAllDocsQuery(), Occur.SHOULD);
            // Set minNrShouldMatch to 1 so that BQ will not optimize rewrite to return
            // the clause instead of BQ.
            bq.MinimumNumberShouldMatch = 1;
            for (int i = 0; i < sort.Length; i++)
            {
                for (int j = 0; j < tfcOptions.Length; j++)
                {
                    TopDocsCollector<Entry> tdc = TopFieldCollector.Create(sort[i], 10, tfcOptions[j][0], tfcOptions[j][1], tfcOptions[j][2], false);

                    Assert.IsTrue(tdc.GetType().Name.EndsWith(actualTFCClasses[j]));

                    @is.Search(bq, tdc);

                    TopDocs td = tdc.TopDocs();
                    ScoreDoc[] sd = td.ScoreDocs;
                    Assert.AreEqual(10, sd.Length);
                }
            }
        }
开发者ID:Cefa68000,项目名称:lucenenet,代码行数:30,代码来源:TestTopFieldCollector.cs

示例6: Search

        public SearchResult Search(Query searchQuery, int maxHits, string NameField = "Name", Sort sort = null)
        {
            SearchResult result = new SearchResult();
            TopDocs hits = null;
            result.SearchResultItems = new List<SearchResultItem>();
            if(sort != null)
            {
                hits = seacher.Search(searchQuery, null, maxHits, sort);
            }
            else
            {
                hits = seacher.Search(searchQuery, null, maxHits);
            }
            for (int i = 0; i < hits.ScoreDocs.Count(); i++)
            {
                Document doctemp = seacher.Doc(hits.ScoreDocs[i].Doc);
                result.SearchResultItems.Add(new SearchResultItem
                {
                    Id = int.Parse(doctemp.Get("Id")),
                    Name = doctemp.Get(NameField),
                    Type = (DocumentType) Enum.Parse(typeof(DocumentType), doctemp.Get("Type"))
                });
            }
            result.Hits = hits.ScoreDocs.Count();

            return result;
        }
开发者ID:ASbeletsky,项目名称:Cinema3D,代码行数:27,代码来源:Seacher.cs

示例7: TestReverseDateSort

        public virtual void TestReverseDateSort()
        {
            IndexSearcher searcher = NewSearcher(Reader);

            Sort sort = new Sort(new SortField(DATE_TIME_FIELD, SortField.Type_e.STRING, true));
            Query query = new TermQuery(new Term(TEXT_FIELD, "document"));

            // Execute the search and process the search results.
            string[] actualOrder = new string[5];
            ScoreDoc[] hits = searcher.Search(query, null, 1000, sort).ScoreDocs;
            for (int i = 0; i < hits.Length; i++)
            {
                Document document = searcher.Doc(hits[i].Doc);
                string text = document.Get(TEXT_FIELD);
                actualOrder[i] = text;
            }

            // Set up the expected order (i.e. Document 5, 4, 3, 2, 1).
            string[] expectedOrder = new string[5];
            expectedOrder[0] = "Document 5";
            expectedOrder[1] = "Document 4";
            expectedOrder[2] = "Document 3";
            expectedOrder[3] = "Document 2";
            expectedOrder[4] = "Document 1";

            Assert.AreEqual(Arrays.AsList(expectedOrder), Arrays.AsList(actualOrder));
        }
开发者ID:joyanta,项目名称:lucene.net,代码行数:27,代码来源:TestDateSort.cs

示例8: Search

        public SearchHits Search(PreparedQuery query, Sort sort, int maxResults = DefaultMaximumResults)
        {
#if FEATURE_CONTENT_SEARCH
          return new SearchHits(Searcher.Search(query.Query, null, maxResults, sort), Searcher.IndexReader);
#else
            return new SearchHits(Searcher.Search(query.Query, sort));
#endif
        }
开发者ID:KerwinMa,项目名称:WeBlog,代码行数:8,代码来源:SortableIndexSearchContext.cs

示例9: BuildSort

 public virtual void BuildSort()
 {
     if (SortFields.Count == 0)
     {
         return;
     }
     CurrentSort = new Sort(SortFields.ToArray());
 }
开发者ID:modulexcite,项目名称:Lucinq,代码行数:8,代码来源:QueryBuilderGroup.cs

示例10: Search

 public SearchHits Search(PreparedQuery query, Sort sort, int maxResults = DefaultMaximumResults)
 {
     #if SC62 || SC64 || SC66
     return new SearchHits(Searcher.Search(query.Query, sort));
     #else
     return new SearchHits(Searcher.Search(query.Query, null, maxResults, sort), Searcher.IndexReader);
     #endif
 }
开发者ID:Quatra,项目名称:WeBlog,代码行数:8,代码来源:SortableIndexSearchContext.cs

示例11: Hits

 internal Hits(Searcher s, Query q, Filter f, Sort o)
 {
     weight = q.Weight(s);
     searcher = s;
     filter = f;
     sort = o;
     GetMoreDocs(50); // retrieve 100 initially
 }
开发者ID:vineelkovvuri,项目名称:ExtendableDesktopSearch,代码行数:8,代码来源:Hits.cs

示例12: Search

 public SearchHits Search(Query query, Sort sort)
 {
     //Fix for #384289. Previous code line returned PreparedQuery. PreparedQuery made FullText queries from all queries,
     //for example _name:test query became _name:test*. It produced wrong search results, so I decided to remove
     //PreparedQuery part. If something wrong noticed during usage, PreparedQuery should be return
     //and other logic should be created for this part.
     //return Search(query, SearchContext.Empty, sort); - this returned PreparedQuery.
     return new SearchHits(Searcher.Search(query, sort));
 }
开发者ID:udt1106,项目名称:Sitecore-Item-Buckets,代码行数:9,代码来源:SortableIndexSearchContent.cs

示例13: DisplayResults

 public void DisplayResults(Query query, Sort sort)
 {
     using(var indexSearcher = new IndexSearcher(directory, true))
     {
         indexSearcher.SetDefaultFieldSortScoring(true, false);
         var results = indexSearcher.Search(query, null, 20, sort);
         Console.WriteLine("\nResults for: {0} sorted by {1}", query, sort);
         Console.WriteLine();
     }
 }
开发者ID:diegocaxito,项目名称:LuceneTest,代码行数:10,代码来源:SortingExemple.cs

示例14: Hits

		internal Hits(Searcher s, Query q, Filter f, Sort o)
		{
			weight = q.Weight(s);
			searcher = s;
			filter = f;
			sort = o;
			nDeletions = CountDeletions(s);
			GetMoreDocs(50); // retrieve 100 initially
			lengthAtStart = length;
		}
开发者ID:vikasraz,项目名称:indexsearchutils,代码行数:10,代码来源:Hits.cs

示例15: PreviousSearchState

 public PreviousSearchState(Query query, Sort sort, ScoreDoc searchAfterLocal, ScoreDoc searchAfterShard, long[] versions, int numHitsPaged)
 {
     this.Versions = (long[])versions.Clone();
     this.SearchAfterLocal = searchAfterLocal;
     this.SearchAfterShard = searchAfterShard;
     this.Sort = sort;
     this.Query = query;
     this.NumHitsPaged = numHitsPaged;
     SearchTimeNanos = TimeHelper.NanoTime();
 }
开发者ID:joyanta,项目名称:lucene.net,代码行数:10,代码来源:TestShardSearching.cs


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