コード例 #1
0
ファイル: LuceneSearcher.cs プロジェクト: wrohrbach/n2cms
        public Result Search(N2.Persistence.Search.Query query)
        {
            if (!query.IsValid())
                return Result.Empty;

            var s = accessor.GetSearcher();
            try
            {
                var q = CreateQuery(query);
                var hits = s.Search(q, query.SkipHits + query.TakeHits);

                var result = new Result();
                result.Total = hits.totalHits;
                var resultHits = hits.scoreDocs.Skip(query.SkipHits).Take(query.TakeHits).Select(hit =>
                {
                    var doc = s.Doc(hit.doc);
                    int id = int.Parse(doc.Get("ID"));
                    ContentItem item = persister.Get(id);
                    return new Hit { Content = item, Score = hit.score };
                }).Where(h => h.Content != null).ToList();
                result.Hits = resultHits;
                result.Count = resultHits.Count;
                return result;
            }
            finally
            {
                //s.Close();
            }
        }
コード例 #2
0
ファイル: LuceneSearcher.cs プロジェクト: navneetccna/n2cms
		public Result Search(N2.Persistence.Search.Query query)
		{
			if (!query.IsValid())
				return Result.Empty;

			var s = accessor.GetSearcher();
			try
			{
				var q = CreateQuery(query);
				//new TopFieldDocCollector(s.GetIndexReader(), new Sort(
				TopDocs hits;
				if (string.IsNullOrEmpty(query.SortField))
					hits = s.Search(q, query.SkipHits + query.TakeHits);
				else
					hits = s.Search(
						query: q,
						filter: null,
						n: query.SkipHits + query.TakeHits,
						sort: new Sort(
							query.SortFields.Select(
								field => new SortField(field.SortField, GetSortFieldType(field.SortField), field.SortDescending)).ToArray()));

				var result = new Result();
				result.Total = hits.TotalHits;
				var resultHits = hits.ScoreDocs.Skip(query.SkipHits).Take(query.TakeHits).Select(hit =>
				{
					var doc = s.Doc(hit.Doc);
					int id = int.Parse(doc.Get("ID"));
					ContentItem item = persister.Get(id);
					return new Hit { Content = item, Score = hit.Score };
				}).Where(h => h.Content != null).ToList();
				result.Hits = resultHits;
				result.Count = resultHits.Count;
				return result;
			}
			finally
			{
				//s.Close();
			}
		}