Exemplo n.º 1
0
        public IActionResult Search(string searchQuery)
        {
            if (!string.IsNullOrEmpty(searchQuery))
            {
                var products       = _productService.GetAllFiltered(searchQuery);
                var productListing = products.Select(product => new ProductListingModel
                {
                    Id       = product.Id,
                    Name     = product.Name,
                    ImageURL = product.ImageURL,
                    Price    = product.Price
                });

                var model = new SearchIndexModel
                {
                    ProductList = productListing,
                    SearchQuery = searchQuery
                };
                return(View(model));
            }
            else
            {
                return(RedirectToAction("Index"));
            }
        }
        public IActionResult Search(string searchQuery)
        {
            if (!string.IsNullOrEmpty(searchQuery))
            {
                var products       = _productService.GetAllFiltered(searchQuery);
                var productListing = products.Select(product => new ProductListingModel
                {
                    Id       = product.Id,
                    Name     = product.Name,
                    ImageURL = product.ImageURL,
                    Price    = product.Price,
                    Type     = product.Type,
                    Style    = product.Style,
                    Country  = product.Country,
                    City     = product.City,
                    Adress   = product.Adress,
                    Date     = product.Date,
                    Time     = product.Time,
                    Age      = product.Age,
                    Accepted = product.Accepted
                });

                var model = new SearchIndexModel
                {
                    ProductList = productListing,
                    SearchQuery = searchQuery
                };
                return(View(model));
            }
            else
            {
                return(RedirectToAction("Index"));
            }
        }
Exemplo n.º 3
0
        public IActionResult SearchResults(string searchText)
        {
            var posts       = _postService.TakeSpecificPosts(searchText);
            var noResults   = (!posts.Any() || !string.IsNullOrEmpty(searchText));
            var listedPosts = posts.Select(x => new ListPostsModel
            {
                Id            = x.Id,
                Title         = x.Title,
                PostedOn      = x.CreatedOn.ToString(),
                AuthorRating  = x.User.Rating,
                AuthorId      = x.User.Id,
                Author        = x.User.UserName,
                RepliesNumber = x.PostReplies.Count(),
                Forum         = GenerateForum(x)
            });

            var searchModel = new SearchIndexModel
            {
                SearchText      = searchText,
                Posts           = listedPosts,
                NoSearchResults = noResults
            };

            return(View());
        }
Exemplo n.º 4
0
        public async Task <IActionResult> Index(string q = "", int page = 1)
        {
            this.ViewData["IsHideSearch"] = true;
            PagingResult <PostView> pagingResult = await this.postService.SearchAsync(Guid.Empty, FilterType.New, q, page);

            SearchIndexModel model = new SearchIndexModel {
                q = q, PagingResult = pagingResult
            };

            return(View(model));
        }
        public IActionResult Index(SearchIndexModel model)
        {
            var users    = _userService.GetFilteredUsers(model.QueryString);
            var noResult = (!string.IsNullOrEmpty(model.QueryString) && (!users.Any()));

            var model1 = new SearchIndexModel
            {
                QueryString = model.QueryString,
                QueryResult = users,
                IsNoResult  = noResult
            };

            return(View(model1));
        }
Exemplo n.º 6
0
        // GET: /<controller>/
        public IActionResult Index(string search)
        {
            SearchResults results = new SearchResults();

            if (!string.IsNullOrEmpty(search))
            {
                results = _engine.Search(search);
            }
            SearchIndexModel model = new SearchIndexModel
            {
                Results = results,
                Search  = search
            };

            return(View(model));
        }
 public IActionResult Search(SearchIndexModel model)
 {
     return(RedirectToAction("Index", new { model.QueryString }));
 }
Exemplo n.º 8
0
        public SearchModel Search(string searchText)
        {
            var result = new SearchModel();

            if (string.IsNullOrEmpty(searchText))
            {
                result.Message = "Įveskite paieškos užklausą.";
                return(result);
            }

            var stemmedSearchText = new LithuanianStemmer().Stem(searchText.Trim());

            if (string.IsNullOrEmpty(stemmedSearchText))
            {
                result.Message = "Įveskite paieškos užklausą.";
                return(result);
            }

            Lucene.Net.Search.Hits hits = null;
            try
            {
                if (char.IsLetter(stemmedSearchText[stemmedSearchText.Length - 1]))
                {
                    stemmedSearchText += "*";
                }

                query = parser.Parse(stemmedSearchText);

                if (searcher == null)
                {
                    searcher = new Lucene.Net.Search.IndexSearcher(CustomAppSettings.SearchIndexFolder);
                }

                hits = searcher.Search(query);
            }
            catch (Exception e)
            {
                result.Message = "Paieška nepavyko. Pataisykite užklausą. Klaidos pranešimas: " + e.Message;
                return(result);
            }

            Lucene.Net.Highlight.Formatter formatter = new Lucene.Net.Highlight.SimpleHTMLFormatter(
                "<span class=\"highlightResult\">",
                "</span>");

            var fragmenter  = new Lucene.Net.Highlight.SimpleFragmenter(100);
            var scorer      = new Lucene.Net.Highlight.QueryScorer(searcher.Rewrite(query));
            var highlighter = new Lucene.Net.Highlight.Highlighter(formatter, scorer);

            highlighter.SetTextFragmenter(fragmenter);

            Dictionary <string, int> dict_already_seen_ids = new Dictionary <string, int>();

            var list = new List <SearchIndexModel>();

            // insert the search results into a temp table which we will join with what's in the database
            for (int i = 0; i < hits.Length(); i++)
            {
                if (dict_already_seen_ids.Count < 100)
                {
                    Lucene.Net.Documents.Document doc = hits.Doc(i);
                    string id = doc.Get("id");
                    if (!dict_already_seen_ids.ContainsKey(id))
                    {
                        dict_already_seen_ids[id] = 1;
                        var model = new SearchIndexModel();
                        model.Id      = id;
                        model.Score   = hits.Score(i);
                        model.Subject = doc.Get("subject");
                        model.Type    = (EntryTypes)Enum.Parse(typeof(EntryTypes), doc.Get("type"));

                        string raw_text = HttpUtility.HtmlEncode(doc.Get("raw_text"));
                        //string raw_text = doc.Get("raw_text");

                        Lucene.Net.Analysis.TokenStream stream = analyzer.TokenStream("text",
                                                                                      new System.IO.StringReader(
                                                                                          raw_text));
                        string highlighted_text = highlighter.GetBestFragments(stream, raw_text, 3, "...").Replace("'",
                                                                                                                   "''");


                        if (highlighted_text == "") // someties the highlighter fails to emit text...
                        {
                            highlighted_text = raw_text.Replace("'", "''");
                        }
                        if (highlighted_text.Length > 3000)
                        {
                            highlighted_text = highlighted_text.Substring(0, 3000);
                        }

                        model.HighlightedText = highlighted_text;

                        list.Add(model);
                    }
                }
                else
                {
                    break;
                }
            }

            result.List         = list;
            result.SearchPhrase = searchText;
            if (list.Count == 0)
            {
                result.Message = string.Format("Įrašų pagal užklausą '{0}' nerasta. Patikslinkite paieškos duomenis.", searchText);
            }

            return(result);
        }