Example #1
0
        public static SearchResults Query(HttpContext ctx, string query, int page = 1)
        {
            if (string.IsNullOrWhiteSpace(query))
            {
                return(new SearchResults {
                    Documents = new SearchResult[0],
                    TotalCount = 0
                });
            }
            var indexPath     = ctx.Server.MapPath("~/App_Data/Index");
            var indexSearcher = new DirectoryIndexSearcher(new DirectoryInfo(indexPath));

            using (var searchService = new SearchService(indexSearcher)) {
                var parser = new MultiFieldQueryParser(
                    Lucene.Net.Util.Version.LUCENE_29,
                    new[] { "Text" },
                    new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_29));
                Query multiQuery = parser.Parse(query);

                var result = searchService.SearchIndex(multiQuery);
                return(new SearchResults {
                    Documents = result.Results
                                .Skip(PageSize * (page - 1))
                                .Take(PageSize)
                                .Select(d => new SearchResult {
                        Url = d.Get("Url"),
                        Title = d.Get("Title"),
                        Summary = d.Get("Summary")
                    }),
                    TotalCount = result.Results.Count()
                });
            }
        }
Example #2
0
        public IEnumerable <T> Search(DefaultQuery query)
        {
            var indexSearcher = new DirectoryIndexSearcher(this.fsiLocation.GetDirectory());

            using (var searchService = new SearchService(indexSearcher))
            {
                var result = searchService.SearchIndex(query.Query, this.GetResultDefinition());

                return(result.Results);
            }
        }
 public static IEnumerable<Page> Find(String searchText)
 {
     if (!Directory.Exists(IndexDirectoryPath))
     {
         return new List<Page>();
     }
     DirectoryIndexSearcher indexSearcher = new DirectoryIndexSearcher(IndexDirectoryInfo);
     using (SearchService searchService = new SearchService(indexSearcher))
     {
         QueryBase query = new PageQuery().WithKeywords(searchText);
         SearchResult<Page> result = searchService.
                                         SearchIndex(query.Query,
                                                     new PageResultDefinition());
         return result.Results;
     }
 }
Example #4
0
        public ActionResult Search(string searchText, bool?orderByDate)
        {
            string IndexPath     = Server.MapPath("~/Index");
            var    indexSearcher = new DirectoryIndexSearcher(new DirectoryInfo(IndexPath), true);

            using (var searchService = new SearchService(indexSearcher))
            {
                var query  = new OfferQuery().WithKeywords(searchText);
                var result = searchService.SearchIndex <Offers>(query.Query, new OfferResultDefinition());

                if (orderByDate.HasValue)
                {
                    return(View(result.Results.OrderBy(x => x.DateAndTime).ToList()));
                }
                return(View("Search", result.Results.ToList()));
            }
        }
        public LuceneSearcher(string indexPath)
        {
            var searcher = new DirectoryIndexSearcher(new DirectoryInfo(indexPath));

            this.searchService = new SearchService(searcher);
        }