Esempio n. 1
0
        private static IList<int> SearchCore(SearchFilter searchFilter, out int totalHits)
        {
            if (!Directory.Exists(LuceneCommon.IndexDirectory))
            {
                totalHits = 0;
                return new int[0];
            }

            SortField sortField = GetSortField(searchFilter);
            int numRecords = searchFilter.Skip + searchFilter.Take;

            using (var directory = new LuceneFileSystem(LuceneCommon.IndexDirectory))
            {
                var searcher = new IndexSearcher(directory, readOnly: true);
                var query = ParseQuery(searchFilter);
                var results = searcher.Search(query, filter: null, n: numRecords, sort: new Sort(sortField));
                var keys = results.ScoreDocs.Skip(searchFilter.Skip)
                    .Select(c => ParseKey(searcher.Doc(c.Doc).Get("MediaID")))
                    .ToList();
                totalHits = results.TotalHits;
                searcher.Close();
                return keys;
            }
        }
Esempio n. 2
0
        private static List<HttpLinkItem> SearchCore(ListSearchItemViewModel queryParams, SearchFilter searchFilter, out int totalHits)
        {
            if (!Directory.Exists(LuceneCommon.IndexDirectory))
            {
                totalHits = 0;
                return new List<HttpLinkItem>();
            }

            SortField sortField = GetSortField(searchFilter);

            int numRecords = searchFilter.Skip + searchFilter.Take;

            using (var directory = new LuceneFileSystem(LuceneCommon.IndexDirectory))
            {
                var searcher = new IndexSearcher(directory, readOnly: true);

                var query = ParseQuery(queryParams, searchFilter);

                var results = searcher.Search(query, filter: null, n: numRecords, sort: new Sort(sortField));

                var keys = results.ScoreDocs.Skip(searchFilter.Skip)
                    .Select(c => GetMediaItem(searcher.Doc(c.Doc)))
                    .ToList();

                totalHits = results.TotalHits;

                searcher.Close();

                return keys;
            }
        }
Esempio n. 3
0
        public List<HttpLinkItem> Search(List<int> Keys)
        {
            if (!Directory.Exists(LuceneCommon.IndexDirectory))
            {
                return new List<HttpLinkItem>();
            }

            using (var directory = new LuceneFileSystem(LuceneCommon.IndexDirectory))
            {
                var searcher = new IndexSearcher(directory, readOnly: true);

                var combineQuery = new BooleanQuery();

                foreach (var key in Keys)
                {

                    combineQuery.Add(NumericRangeQuery.NewIntRange(OutDoorIndexFields.MediaID, key, key, true, true), Occur.SHOULD);
                }

                var searchResults = searcher.Search(combineQuery, filter: null, n: Keys.Count);

                if (searchResults.TotalHits == 0)
                {
                    searcher.Close();
                    return new List<HttpLinkItem>();
                }

                var results = searchResults.ScoreDocs.Select(c => GetMediaItem(searcher.Doc(c.Doc)))
                    .ToList();

                searcher.Close();

                return results;
            }
        }