Exemplo n.º 1
0
        public TagResults GetTags(int page = 1, int perPage = 0)
        {
            if (page < 1)
            {
                page = 1;
            }

            if (perPage < 1)
            {
                perPage = _totalTags;
            }

            var start = (page - 1) * perPage;
            var end   = Math.Min(page * perPage, _totalTags);

            var reader = this.GetIndexReader();

            var results = new TagResults();

            results.Page           = page;
            results.PerPage        = perPage;
            results.PageCount      = (_totalTags + 1) / perPage;
            results.ResultsCount   = _totalTags;
            results.TotalTagsCount = _totalTags;
            results.Tags           = this.GetAllTagsFromReader(reader, start, end)
                                     .ToList();

            return(results);
        }
Exemplo n.º 2
0
        public TagResults SearchTags(string query, int page = 1, int perPage = 0)
        {
            // If there is no query, don't search just return all the tags.
            if (String.IsNullOrWhiteSpace(query))
            {
                return(this.GetTags(page, perPage));
            }

            if (page < 1)
            {
                page = 1;
            }

            if (perPage < 1)
            {
                perPage = _totalTags;
            }

            var start = (page - 1) * perPage;
            var end   = Math.Min(page * perPage, _totalTags);

            var reader = this.GetIndexReader();

            using (var searcher = new IndexSearcher(reader))
            {
                var parsedQuery = new MultiFieldQueryParser(Lucene.Net.Util.Version.LUCENE_30, _fields, new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_30))
                                  .Parse(query);

                var searchResults = searcher.Search(parsedQuery, end);

                var results = new TagResults();
                results.Query          = query;
                results.Page           = page;
                results.PerPage        = perPage;
                results.PageCount      = (_totalTags + 1) / perPage;
                results.ResultsCount   = searchResults.TotalHits;
                results.TotalTagsCount = _totalTags;
                results.Tags           = GetAllTagsFromSearchResults(searcher, searchResults, start, end)
                                         .ToList();

                return(results);
            }
        }