• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Search.Sort类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: GetHitsByFiled

 private Hits GetHitsByFiled(string filedname,Analyzer analyzer, string searchStr, IndexSearcher searcher)
 {
     MultiFieldQueryParser parser = new MultiFieldQueryParser(Lucene.Net.Util.Version.LUCENE_CURRENT, new string[] { filedname}, analyzer);
     Query query = parser.Parse(searchStr);
     Sort sort = new Sort();
     SortField f = new SortField("publish_time", SortField.STRING, true);//按照publish_time字段排序,true表示降序
     sort.SetSort(f);
     Hits hits = searcher.Search(query, sort);
     return hits;
 }
开发者ID:andylaudotnet,项目名称:StockFoo,代码行数:10,代码来源:search1.aspx.cs


示例17: Search

        public Item[] Search(string index, string[] areas, int maxItems)
        {
            List<Item> searchResults = new List<Item>();

            var searchIndex = Sitecore.Search.SearchManager.GetIndex(index);
            using (IndexSearchContext context = searchIndex.CreateSearchContext())
            {

                /***********/
                /* First we need to create a BooleanQuery so we can concatenate the different queries */

                BooleanQuery completeQuery = new BooleanQuery();
                //completeQuery.SetMinimumNumberShouldMatch(2);

                /* search only in current language */
                completeQuery.Add(new TermQuery(new Lucene.Net.Index.Term("_language", Sitecore.Context.Language.Name)), BooleanClause.Occur.MUST);

                Sort sort = new Sort(new SortField("publish date", true));

                Lucene.Net.Search.Searcher searcher = context.Searcher;
                try
                {
                    Hits hits = context.Searcher.Search(completeQuery, sort);
                    SearchHits searchHits = new SearchHits(hits);

                    // assuming, no more than every second result is a null-item, that is why the maxItems parameter is multiplied by 2
                    var results = searchHits.FetchResults(0, maxItems * 2);
                    int count = 0;
                    foreach (SearchResult result in results)
                    {
                        try
                        {
                            Item item = result.GetObject<Item>();
                            if (item != null)
                            {
                                count++;
                                searchResults.Add(item);
                            }
                        }
                        catch (Exception e)
                        {
                            Log.Error("error while converting lucene search hit in NewsSearcher.cs", e, searchIndex);
                        }

                        if (count >= maxItems) break;
                    }
                }
                catch (Exception e)
                {
                    Log.Error("error while performing a lucene search in NewsSearcher.cs", e, searchIndex);
                }
            }

            return searchResults.ToArray();
        }
开发者ID:nleSitecore,项目名称:Roadshow,代码行数:55,代码来源:NewsSearcher.cs


示例18: BeforeClassSorterUtilTest

        public void BeforeClassSorterUtilTest()
        {
            // only read the values of the undeleted documents, since after addIndexes,
            // the deleted ones will be dropped from the index.
            Bits liveDocs = reader.LiveDocs;
            List<int> values = new List<int>();
            for (int i = 0; i < reader.MaxDoc; i++)
            {
                if (liveDocs == null || liveDocs.Get(i))
                {
                    values.Add(int.Parse(reader.Document(i).Get(ID_FIELD), CultureInfo.InvariantCulture));
                }
            }
            int idx = Random().nextInt(SORT.Length);
            Sort sorter = SORT[idx];
            if (idx == 1)
            { // reverse doc sort
                values.Reverse();
            }
            else
            {
                values.Sort();
                if (Random().nextBoolean())
                {
                    sorter = new Sort(new SortField(NUMERIC_DV_FIELD, SortField.Type_e.LONG, true)); // descending
                    values.Reverse();
                }
            }
            sortedValues = values.ToArray();
            if (VERBOSE)
            {
                Console.WriteLine("sortedValues: " + sortedValues);
                Console.WriteLine("Sorter: " + sorter);
            }

            Directory target = NewDirectory();
            using (IndexWriter writer = new IndexWriter(target, NewIndexWriterConfig(TEST_VERSION_CURRENT, null)))
            {
                using (reader = SortingAtomicReader.Wrap(reader, sorter))
                {
                    writer.AddIndexes(reader);
                }
            }
            dir.Dispose();

            // CheckIndex the target directory
            dir = target;
            TestUtil.CheckIndex(dir);

            // set reader for tests
            reader = SlowCompositeReaderWrapper.Wrap(DirectoryReader.Open(dir));
            assertFalse("index should not have deletions", reader.HasDeletions);
        }
开发者ID:ChristopherHaws,项目名称:lucenenet,代码行数:53,代码来源:IndexSortingTest.cs


示例19: LuceneQueryStatistics

 public LuceneQueryStatistics(Query query, Filter filter, Sort sort, TimeSpan elapsedPreparationTime, TimeSpan elapsedSearchTime, TimeSpan elapsedRetrievalTime, int totalHits, int skippedHits, int retrievedDocuments)
 {
     this.totalHits = totalHits;
     this.query = query;
     this.filter = filter;
     this.sort = sort;
     this.elapsedPreparationTime = elapsedPreparationTime;
     this.elapsedSearchTime = elapsedSearchTime;
     this.elapsedRetrievalTime = elapsedRetrievalTime;
     this.skippedHits = skippedHits;
     this.retrievedDocuments = retrievedDocuments;
 }
开发者ID:Zaixu,项目名称:Lucene.Net.Linq,代码行数:12,代码来源:LuceneQueryStatistics.cs


示例20: Application_Start

        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);
            CreateLuceneIndexFolder();
            string rebuildEvery = ConfigurationManager.AppSettings["RebuildLuceneIndexEveryXDays"];

            int rebuildEveryXDays = Convert.ToInt32(rebuildEvery);

            string path = HttpContext.Current.Server.MapPath("~/App_Data/LuceneIndex");
            try
            {
                FSDirectory fsd = FSDirectory.Open(new DirectoryInfo(path));
                var indexSearcher = new IndexSearcher(fsd, true);

                var termQuery = new MatchAllDocsQuery();
                var sort = new Sort(new SortField(LuceneIndexFieldMap.LastModifiedField, SortField.STRING));
                TopDocs topDocs = indexSearcher.Search(termQuery, null, 1, sort);
                DateTime lastUpdateDate = DateTime.MinValue;
                foreach (ScoreDoc match in topDocs.ScoreDocs)
                {
                    Document doc = indexSearcher.Doc(match.doc);
                    string lastUpdate = doc.Get(LuceneIndexFieldMap.LastModifiedField);

                    if (lastUpdate != null)
                    {
                        lastUpdateDate = DateTools.StringToDate(lastUpdate);
                        Debug.WriteLine(lastUpdate);
                    }
                }

                TimeSpan ts = DateTime.Now - lastUpdateDate;

                if (ts.TotalDays > rebuildEveryXDays)
                {
                    var generator = new DataGenerator(path);
                    generator.WriteIndex();
                }
            }
            catch (FileNotFoundException exception)
            {
                CreateLuceneIndexFolder();
                var generator = new DataGenerator(path);
                generator.WriteIndex();

            }
        }
开发者ID:davidpellerin,项目名称:LuceneExample,代码行数:49,代码来源:Global.asax.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Search.SortField类代码示例发布时间:2022-05-26
下一篇:
C# Search.Similarity类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap