public IActionResult Search(string searchString, int page = 1, int displayNum = DEFAULT_DISPLAY)
        {
            var categories = db.ProductCategory
                             .Where(c => c.ParentProductCategoryId != null)
                             .Select(c => new CategoryListModel
            {
                productCategoryId = c.ProductCategoryId,
                Name = c.Name
            }).ToList();

            var ret = new SearchResultModel
            {
                categories = categories,
            };

            List <BikeListModel> searchedBikes;

            if (searchString != null)
            {
                searchedBikes = db.VProductAndDescription
                                .Where(b => b.Culture == "en" && b.SellEndDate == null && (b.Name.Contains(searchString) || b.Description.Contains(searchString)))
                                .Select(b => new BikeListModel
                {
                    ProductModel   = b.Name,
                    Description    = b.Description,
                    ProductModelID = b.ProductModelId
                }).Distinct().ToList();
            }
            else
            {
                searchedBikes = db.VProductAndDescription
                                .Where(b => b.Culture == "en" && b.SellEndDate == null)
                                .Select(b => new BikeListModel
                {
                    ProductModel   = b.Name,
                    Description    = b.Description,
                    ProductModelID = b.ProductModelId
                }).Distinct().ToList();
            }

            decimal val     = (decimal)searchedBikes.Count / displayNum;
            int     maxPage = (int)Math.Ceiling(val);

            ViewBag.Page         = page;
            ViewBag.MaxPage      = maxPage;
            ViewBag.CategoryId   = null;
            ViewBag.SearchString = searchString;

            if (searchedBikes.Count() > 0)
            {
                int startDisplay = displayNum * (page - 1);
                searchedBikes = searchedBikes.Skip(startDisplay).Take(displayNum).ToList();

                ret.bikes = searchedBikes;
                return(View(ret));
            }

            ViewBag.Empty = "";
            return(View(ret));
        }
        public async Task <SearchResultModel> GetTextSearch(SearchModel model)
        {
            var client = Constants.Client;
            SearchResultModel resultModel = null;

            _googleMapsKey = "AIzaSyBgX5VRIZycIRFEZCJ6v1duVMsZfIbC14c";
            try
            {
                var response = await client.GetAsync($"api/place/findplacefromtext/json?" +
                                                     $"&input={model.Name}" +
                                                     $"&inputtype={model.InputType}" +
                                                     $"&fields={model.Fields}" +
                                                     $"&key={_googleMapsKey}");

                if (response.IsSuccessStatusCode)
                {
                    string content = await response.Content.ReadAsStringAsync();

                    resultModel = SearchResultModel.FromJson(content);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("\tERROR {0}", ex.Message);
            }
            return(resultModel);
        }
Ejemplo n.º 3
0
        public IActionResult Results(string searchQuery)
        {
            var mails        = _mailService.GetFilteredMails(searchQuery);
            var areNoResults = (!string.IsNullOrEmpty(searchQuery) && !mails.Any());

            var mailListings = mails.Select(mail => new MailListingModel
            {
                Id           = mail.Id,
                AuthorId     = mail.User.Id,
                AuthorName   = mail.User.UserName,
                AuthorRating = mail.User.Rating,
                Title        = mail.Title,
                DateMailed   = mail.DateOfCreation.ToString(),
                RepliesCount = mail.Replies.Count(),
                Platform     = BuildPltformListing(mail)
            });

            var model = new SearchResultModel
            {
                Mails             = mailListings,
                SearchQuery       = searchQuery,
                EmptySearchResult = areNoResults
            };

            return(View(model));
        }
Ejemplo n.º 4
0
        public ActionResult SearchFromBarId(int id)
        {
            throw new System.Exception("TODO");
            var model = new SearchResultModel(id);

            return(View("Search", model));
        }
Ejemplo n.º 5
0
        public IActionResult Results(string searchQuery)
        {
            var posts = _postService.GetFilteredPosts(searchQuery);

            var areNoResults = !string.IsNullOrEmpty(searchQuery) && !posts.Any();

            var postListings = posts.Select(p => new PostListingModel
            {
                Title        = p.Title,
                Author       = p.User.UserName,
                AuthorRating = p.User.Rating,
                AuthorId     = p.User.Id,
                DatePosted   = p.Created,
                Id           = p.Id,
                RepliesCount = p.PostReplies.Count,
                Forum        = BuildForumListingForPost(p)
            });

            var model = new SearchResultModel
            {
                Posts              = postListings,
                SearchQuery        = searchQuery,
                EmptySearchResults = areNoResults
            };

            return(View(model));
        }
Ejemplo n.º 6
0
        public IActionResult Search(string search)
        {
            if (string.IsNullOrWhiteSpace(search) || search.Length < 2)
            {
                return(Ok());
            }
            search = search.Trim();
            Func <string, bool> eq  = (a) => a.Trim().ToLowerInvariant().Contains(search.ToLowerInvariant());
            Func <string, bool> eq2 = (a) => a.IndexOf(search, StringComparison.OrdinalIgnoreCase) >= 0; // - a bit faster

            var something = _context.Subject
                            .Include(x => x.IdGroupNavigation)
                            .Include(x => x.SubjectProfessor)
                            .Where(x => eq2(x.SubjectFull) || eq2(x.SubjectShort) || x.SubjectProfessor.Any(y => eq2(y.IdProfessorNavigation.Professor1)))
                            .Distinct().Take(6)
                            .Select(x => new SearchResultSingleModel
            {
                IdSubject    = x.IdSubject,
                SubjectShort = x.SubjectShort,
                SubjectLong  = x.SubjectFull,

                IdGroup   = x.IdGroup,
                GroupName = x.IdGroupNavigation.GroupName,
                Lectors   = x.SubjectProfessor.Select(y => new SearchLectorModel {
                    Id = y.IdProfessor, Name = y.IdProfessorNavigation.Professor1
                }),
            })
                            .ToList();

            var model = new SearchResultModel {
                Results = something
            };

            return(Ok(model));
        }
Ejemplo n.º 7
0
 public ActionMethod Search(SearchModel searchCriteria)
 {
     SearchResultModel result =       //Get the search results from database
                                return(new JsonResult {
         Data = result
     });
 }
Ejemplo n.º 8
0
        private IList <ISearchResult> MapResponseValues(IRestResponse response, JsonDomainResponseModel domainResponseModel)
        {
            var termsList  = new List <ISearchResult>();
            var jObject    = JObject.Parse(response.Content);
            var itemTokens = (JArray)jObject.SelectToken("items");

            if (itemTokens != null)
            {
                foreach (var item in itemTokens)
                {
                    var itemId      = item.SelectToken("id").ToString();
                    var domainModel = domainResponseModel.Items.Where(i => i.Id == itemId).FirstOrDefault();
                    var domain      = SetTermDomain(domainModel);
                    SetTermSubdomains(domainModel);

                    _id++;
                    // get language childrens (source + target languages)
                    var languageTokens = item.SelectToken("language").Children().ToList();
                    if (languageTokens.Any())
                    {
                        // foreach language token get the terms
                        foreach (JProperty languageToken in languageTokens)
                        {
                            // Latin translations are automatically returned by IATE API response->"la" code
                            // Ignore the "la" translations
                            if (!languageToken.Name.Equals("la"))
                            {
                                var termEntry      = languageToken.FirstOrDefault().SelectToken("term_entries").Last;
                                var termValue      = termEntry.SelectToken("term_value").ToString();
                                var termType       = GetTermTypeByCode(termEntry.SelectToken("type").ToString());
                                var langTwoLetters = languageToken.Name;
                                var definition     = languageToken.Children().FirstOrDefault() != null
                                                                        ? languageToken.Children().FirstOrDefault().SelectToken("definition")
                                                                        : null;

                                var languageModel = new LanguageModel
                                {
                                    Name   = new Language(langTwoLetters).DisplayName,
                                    Locale = new Language(langTwoLetters).CultureInfo
                                };

                                var termResult = new SearchResultModel
                                {
                                    Text       = termValue,
                                    Id         = _id,
                                    Score      = 100,
                                    Language   = languageModel,
                                    Definition = definition != null?definition.ToString() : string.Empty,
                                                     Domain    = domain,
                                                     Subdomain = FormatSubdomain(),
                                                     TermType  = termType
                                };
                                termsList.Add(termResult);
                            }
                        }
                    }
                }
            }
            return(termsList);
        }
Ejemplo n.º 9
0
        public List <SearchResultModel> Search(string query)
        {
            if (!warm)
            {
                Warmup();
            }

            List <SearchResultModel> result = new List <SearchResultModel>();

            var parsed = queryParser.Parse(query);

            ScoreDoc[] hits = indexSearcher.Search(parsed, null, 40).ScoreDocs;

            foreach (var hit in hits)
            {
                var foundDoc = indexSearcher.Doc(hit.Doc);

                string name = foundDoc.Get("Name");

                // Console.WriteLine("Hit: {0}", name);
                // Console.WriteLine("Raw: {0}", hit);
                // Console.WriteLine("Score: {0}", hit.Score);

                var model = new SearchResultModel
                {
                    Name = foundDoc.Get("Name"),
                    Url  = foundDoc.Get("Url")
                };

                result.Add(model);
            }

            return(result);
        }
Ejemplo n.º 10
0
        public ActionResult SearchResult()
        {
            string query = string.Empty;

            if (Request.QueryString["q"] != null)
            {
                query = Request.QueryString["q"].Trim();
            }

            int pageNo = 1;

            if (Request.QueryString["page"] != null)
            {
                int.TryParse(Request.QueryString["page"].ToString(), out pageNo);
                if (pageNo == 0)
                {
                    pageNo = 1;
                }
            }

            query = Server.UrlDecode(query);

            SearchResultModel model = new SearchResultModel();

            model.Populate(query, pageNo);

            return(View("~/Views/Search/SearchResult.cshtml", model));
        }
Ejemplo n.º 11
0
        public ActionResult SearchResult(string looking)
        {
            if (!string.IsNullOrWhiteSpace(looking))
            {
                var model = (from a in db.Tbl_Book
                             where (a.Book_Name.Contains(looking) ||
                                    a.Tbl_BookDetails.BD_ISBN.Contains(looking) ||
                                    a.Tbl_BookDetails.BD_LCC.Contains(looking) ||
                                    a.Tbl_BookDetails.BD_Publishers.Contains(looking) ||
                                    a.Tbl_BookDetails.BD_Subject.Contains(looking) ||
                                    a.Tbl_BookDetails.BD_Titel.Contains(looking) ||
                                    a.Tbl_BookDetails.BD_Translator.Contains(looking) ||
                                    a.Tbl_BookTag.Any(b => b.Tbl_Tag.Tag_Name.Contains(looking)) ||
                                    a.Tbl_BookDetails.BD_WriterName.Contains(looking))
                             select a).ToList();

                SearchResultModel Result = new SearchResultModel();

                List <SearchResultItemModel> items = new List <SearchResultItemModel>();

                foreach (var item in model)
                {
                    items.Add(new SearchResultItemModel(item.Book_ID, item.Book_Name));
                }
                Result.looking = looking;
                Result.Items   = items;

                return(View(Result));
            }
            return(View(new SearchResultModel()
            {
                looking = "", Items = null
            }));
        }
Ejemplo n.º 12
0
        public IActionResult Results(string searchQuery)
        {
            var posts        = _postService.GetFilteredPosts(searchQuery);
            var areNoResults = (!string.IsNullOrEmpty(searchQuery) && !posts.Any());

            var postListingModel = posts.Select(post => new PostListingModel
            {
                Id           = post.Id,
                AuthorId     = post.User.Id,
                AuthorName   = post.User.UserName,
                AuthorRating = post.User.Rating,
                Title        = post.Title,
                DatePosted   = post.Created.ToString(),
                RepliesCount = post.Replies.Count(),
                Forum        = BuildForumListing(post)
            });
            var model = new SearchResultModel
            {
                Posts              = postListingModel,
                SearchQuery        = searchQuery,
                EmptySearchResults = areNoResults
            };

            return(View(model));
        }
Ejemplo n.º 13
0
        public IActionResult GetPermissionByPage(SearchModel searchModel)
        {
            if (searchModel != null)
            {
                if (searchModel.Start == 0)
                {
                    searchModel.PageIndex = 1;
                }
                if (searchModel.Start > 0)
                {
                    searchModel.PageIndex = searchModel.Start / 10 + 1;
                }
                if (searchModel.Search.Count != 0)
                {
                    foreach (var search in searchModel.Search)
                    {
                        if (search.Key == "value")
                        {
                            searchModel.SearchValue = search.Value;
                        }
                    }
                }

                var permissions = _permissionService.SearchPermissionListByPage(searchModel);
                var result      = new SearchResultModel
                {
                    Data            = permissions.ToList(),
                    Draw            = searchModel.Draw,
                    RecordsTotal    = permissions.TotalCount,
                    RecordsFiltered = permissions.TotalCount
                };
                return(Json(result));
            }
            return(ErrReturn("* 出现错误!"));
        }
        public void BuildBox(SearchResultModel model)
        {
            foreach (var item in model.Items)
            {
                ProcessItem(item);
            }
            var box = new StatBox()
            {
                Title = BoxTitle
            };

            model.StatBoxs.Add(box);
            foreach (var engine in Engines.OrderByDescending(o => o.Counter).Take(10))
            {
                var red = new StatItem()
                {
                    Title = engine.Name, Value = engine.Counter, Link = "#"
                };
                box.StatItems.Add(red);
                if (model.Items.Count > 0)
                {
                    red.ValueText    = ((decimal)engine.Counter / model.Items.Count * 100).ToString("f") + "%";
                    red.ValuePercent = ((decimal)engine.Counter / model.Items.Count * 100);
                }
                else
                {
                    red.ValueText    = "0%";
                    red.ValuePercent = 0;
                }
            }
        }
Ejemplo n.º 15
0
        public IActionResult Results(string searchQuery)
        {
            var posts        = _postService.FromAllSearchedPosts(searchQuery);
            var areNoResults = (!string.IsNullOrEmpty(searchQuery) && !posts.Any());

            var postViewModels = posts.Select(post => new PostViewModel
            {
                Id           = post.Id,
                AuthorId     = post.User.Id,
                AuthorRating = post.User.Rating,
                AuthorName   = post.User.UserName,
                Title        = post.Title,
                DatePosted   = post.Created.ToString("dd/MM/yyyy"),
                RepliesCount = post.Replies.Count(),
                Forum        = new ForumViewModel
                {
                    Id          = post.Forum.Id,
                    Name        = post.Forum.Title,
                    ImageUrl    = post.Forum.ImageUrl,
                    Description = post.Forum.Description
                }
            });
            var model = new SearchResultModel
            {
                Posts            = postViewModels,
                SearchQuery      = searchQuery,
                EmptySearchQuery = areNoResults
            };

            return(View(model));
        }
Ejemplo n.º 16
0
        public IActionResult Results(string searchQuery)
        {
            var posts = _postService.GetFIlteredPosts(searchQuery);

            var areNoResults =
                (!string.IsNullOrEmpty(searchQuery) && !posts.Any());

            var postListings = posts.Select(post => new PostListingModel
            {
                Id            = post.Id,
                IdPembuat     = post.User.Id,
                NamaPembuat   = post.User.UserName,
                RatingPembuat = post.User.Rating,
                Judul         = post.Judul,
                DatePosted    = post.Dibuat.ToString(),
                JumlahBalasan = post.balasan.Count(),
                Forum         = BuildForumListing(post)
            });

            var model = new SearchResultModel
            {
                Posts              = postListings,
                SearchQuery        = searchQuery,
                EmptySearchResults = areNoResults
            };

            return(View(model));
        }
Ejemplo n.º 17
0
        public HttpResponseMessage Search(string q)
        {
            var responseMsg = PerformOperation(() =>
            {
                var result = new SearchResultModel
                {
                    Courses = from c in context.Courses
                              where c.Name.Contains(q)
                              select new CourseSearchModel
                    {
                        Id   = c.Id,
                        Name = c.Name
                    },
                    Users = from u in context.Users
                            where u.Username.Contains(q) || u.Nickname.Contains(q)
                            select new UserSearchModel
                    {
                        Id              = u.Id,
                        Username        = u.Username,
                        Nickname        = u.Nickname,
                        PictureFileName = u.PictureFileName
                    }
                };
                return(result);
            });

            return(responseMsg);
        }
Ejemplo n.º 18
0
        public IActionResult Results(string searchQuery)
        {
            var posts = _postService.GetSearchedPosts(searchQuery);
            //  simple fallback for empty search.
            var noSearch  = (!string.IsNullOrEmpty(searchQuery) && !posts.Any());
            var postsList = posts.Select(p => new PostListItem
            {
                Id           = p.Id,
                Title        = p.Title,
                Body         = p.Body,
                Created      = p.Created,
                Author       = p.Instructor,
                StudentId    = p.StudentId,
                Student      = BuildStudentListItem(p),
                RepliesCount = p.Replies.Count(),
                StudentName  = p.Student.Name
            });
            var model = new SearchResultModel
            {
                Posts            = postsList,
                SearchQuery      = searchQuery,
                EmptySearchField = noSearch
            };

            return(View(model));
        }
        public async Task Update(SearchResultModel entity)
        {
            var result = _context.SearchResults.Attach(entity);

            result.State = Microsoft.EntityFrameworkCore.EntityState.Modified;
            await _context.SaveChangesAsync();
        }
Ejemplo n.º 20
0
        public SearchResultModel GetSearchResultAsync(string keyword, bool english, SearchResultModel result)
        {
            Task.Run(() =>
            {
                Parallel.ForEach(this.engines, engine =>
                {
                    base.SearchOnEngine(engine, keyword, english, result);
                });

                result.Finished = true;
            });

            SpinWait.SpinUntil(() => result.Searched > 0 || result.Finished);

            SearchResultModel newResult = null;

            try
            {
                lock (result)
                {
                    newResult = result.Copy();
                }
            }
            catch (Exception e)
            {
                Log.Error(e, "catched an exception when copying result.");
            }
            return(newResult);
        }
Ejemplo n.º 21
0
        public IActionResult Results(string searchQuery)
        {
            var posts     = _postService.GetFilteredPosts(searchQuery);
            var noResults = (!string.IsNullOrEmpty(searchQuery) && !posts.Any());

            var postListings = posts.Select(post => new PostListingModel
            {
                Id           = post.Id,
                Forum        = BuildForumListing(post),
                Author       = post.User.UserName,
                AuthorId     = post.User.Id,
                AuthorRating = post.User.Rating,
                Title        = post.Title,
                DatePosted   = post.Created.ToString(CultureInfo.InvariantCulture),
                RepliesCount = post.Replies.Count()
            }).OrderByDescending(post => post.DatePosted);

            var model = new SearchResultModel
            {
                EmptySearchResults = noResults,
                Posts       = postListings,
                SearchQuery = searchQuery,
            };

            return(View(model));
        }
Ejemplo n.º 22
0
        public IActionResult Results(string searchQuery)
        {
            var m_posts = m_postService.GetFilteredPosts(searchQuery);

            var m_noResults = (!string.IsNullOrEmpty(searchQuery) && !m_posts.Any());

            var m_postListings = m_posts.Select(post => new PostListingModel
            {
                Id           = post.Id,
                AuthorId     = post.User.Id,
                AuthorName   = post.User.UserName,
                Title        = post.Title,
                DatePosted   = post.Created.ToString(),
                RepliesCount = post.Replies.Count(),
                Project      = BuildProjectListing(post)
            });

            var m_model = new SearchResultModel
            {
                Posts              = m_postListings,
                SearchQuery        = searchQuery,
                EmptyStringResults = m_noResults
            };

            return(View(m_model));
        }
Ejemplo n.º 23
0
        public SearchResultModel GetSearchResult(string keyword, bool async = true)
        {
            if (string.IsNullOrWhiteSpace(keyword))
            {
                return(null);
            }
            if (this.cache.TryGetValue(keyword, out SearchResultModel result))
            {
                return(result);
            }

            var requestId = Guid.NewGuid().ToString();

            result = new SearchResultModel
            {
                RequestId = requestId
            };
            cache.Set(requestId, result, _expirationTime);
            this.cache.Set(keyword, result, _expirationTime);
            var english = !keyword.HasOtherLetter();

            result.Results = new List <SearchResult>();

            if (async)
            {
                return(this.GetSearchResultAsync(keyword, english, result));
            }
            else
            {
                return(this.GetSearchResultSync(keyword, english, result));
            }
        }
Ejemplo n.º 24
0
        public IHttpActionResult Get([FromUri] RestrictionSearchQueryModel searchQuery)
        {
            if (!ModelState.IsValid)
            {
                return(this.Error().InvalidParameters());
            }

            if (searchQuery == null)
            {
                searchQuery = new RestrictionSearchQueryModel();
            }

            searchQuery.DateRangeEnd   = searchQuery.DateRangeEnd?.ToUniversalTime();
            searchQuery.DateRangeStart = searchQuery.DateRangeStart?.ToUniversalTime();

            var restrictions = _restrictionRepository.Get(searchQuery);

            var searchModel = new SearchResultModel <RestrictionWithDescModel>
            {
                Items = restrictions?.Items != null && restrictions.Items.Any()
                    ? _mapper.Map <List <RestrictionWithDescModel> >(restrictions.Items) : null,
                TotalCount = restrictions?.TotalCount ?? 0
            };

            return(Ok(searchModel));
        }
        public IActionResult SearchResults(string searchQuery)
        {
            var posts = _postService.GetFilteredPosts(searchQuery).ToList();

            var postListings = posts.Select(post => new PostListingModel
            {
                Id           = post.Id,
                Title        = post.Title,
                Forum        = BuildForumListing(post),
                AuthorId     = post.User.Id,
                AuthorName   = post.User.UserName,
                AuthorRating = post.User.Rating,
                DatePosted   = post.Created.ToString(),
                RepliesCount = post.Replies.Count()
            }).OrderByDescending(post => post.DatePosted);

            var areAnyResults = string.IsNullOrWhiteSpace(searchQuery) || posts.Any();

            var model = new SearchResultModel
            {
                IsResultEmpty = !areAnyResults,
                Posts         = postListings,
                SearchQuery   = searchQuery,
            };

            return(View(model));
        }
        public ActionResult SearchGitHubResult(string search)
        {
            IGitHubSearch     service = new GitHubService();
            SearchResultModel result  = service.SearchGitHubResult(search) ?? new SearchResultModel();

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
        public void BuildBoxInModelWith3ItemsTest()
        {
            //arrange
            var item1 = new Post()
            {
                Content = "El puto."
            };
            var item2 = new Post()
            {
                Content = "El idolo."
            };
            var item3 = new Post()
            {
                Content = "asd asd as d"
            };
            var model = new SearchResultModel();

            model.Items.Add(item1);
            model.Items.Add(item2);
            model.Items.Add(item3);
            var controller        = new HomeController();
            var sentimentValuator = GetSentimentValuator();

            sentimentValuator.ProcessItems(model.Items);
            //act
            controller.BuildSentimentBox(model, sentimentValuator);
            //assert
            model.StatBoxs.Count.Should().Be.EqualTo(1);
            model.StatBoxs[0].StatItems.Count.Should().Be.EqualTo(3);
            model.StatBoxs[0].Title.Length.Should().Be.GreaterThan(3);
            foreach (var statItem in model.StatBoxs[0].StatItems)
            {
                statItem.ValueText.Should().Be.EqualTo("33,33%");
            }
        }
Ejemplo n.º 28
0
        public IActionResult Results(string searchQuery)
        {
            var threads = _threadService.GetFilteredThreads(searchQuery);

            var zeroResults = (!string.IsNullOrEmpty(searchQuery) && !threads.Any());

            var threadListings = threads.Select(thread => new ThreadListingModel
            {
                Id             = thread.Id,
                Title          = thread.Title,
                CreatedAt      = thread.CreatedAt.ToString(),
                ModifiedAt     = thread.ModifiedAt.ToString(),
                AuthorId       = thread.User.Id,
                AuthorName     = thread.User.UserName,
                AuthorImageUrl = thread.User.ProfileImageUrl,
                AuthorRating   = thread.User.Rating,
                PostCount      = thread.Posts.Count(),
                Forum          = BuildForumListing(thread)
            });

            var model = new SearchResultModel
            {
                Threads            = threadListings,
                SearchQuery        = searchQuery,
                EmptySerachResults = zeroResults
            };

            return(View(model));
        }
Ejemplo n.º 29
0
        public async Task <ActionResult> Index(string q = null, int p = 1)
        {
            ViewBag.Query = q;
            ViewBag.Title = string.Format("「{0}」の検索結果", q);

            var model = new SearchResultModel {
                Query = q
            };

            var condition = new SearchCondition(q);

            try
            {
                var skip = MaxItemsOnPage * (p - 1);
                var ids  = await _searchService.SearchItemIdAsync(condition);

                var count = ids.Count();

                ViewBag.CurrentPage     = p;
                ViewBag.HasPreviousPage = (p > 1);
                ViewBag.HasNextPage     = (count > MaxItemsOnPage * p);

                var items = await _itemDbCommand.GetByIdsAsync(ids, skip, MaxItemsOnPage);

                model.Items = Mapper.Map <IEnumerable <ItemIndexModel> >(items);
            }
            catch (Exception exception)
            {
                _logger.Error(exception);
                model.HasSearchServiceError = true;
            }

            return(View(model));
        }
Ejemplo n.º 30
0
        public ActionResult SearchIndex(string searchText)
        {
            // Displays the search page without any search results if the query is empty
            if (String.IsNullOrWhiteSpace(searchText))
            {
                // Creates a model representing empty search results
                SearchResultModel emptyModel = new SearchResultModel
                {
                    Items = new List <SearchResultItem>(),
                    Query = String.Empty
                };

                return(View(emptyModel));
            }

            // Searches the specified index and gets the matching results
            SearchParameters searchParameters = SearchParameters.PrepareForPages(searchText, searchIndexes, 1, PAGE_SIZE, MembershipContext.AuthenticatedUser, "en-us", true);
            SearchResult     searchResult     = SearchHelper.Search(searchParameters);

            // Creates a model with the search result items
            SearchResultModel model = new SearchResultModel
            {
                Items = searchResult.Items,
                Query = searchText
            };

            return(View(model));
        }
        public void BuildSentimentBox(SearchResultModel model, SentimentValuator sentimentValuator)
        {
            var sentimentBox = new StatBox() { Title = "Sentimiento" };
            model.StatBoxs.Add(sentimentBox);
            sentimentBox.StatItems.Add(new StatItem()
                                           {
                                               Title = "Positivas",
                                               Link = "#",
                                               Value = sentimentValuator.PositiveCount
                                           });
            sentimentBox.StatItems.Add(new StatItem()
                                           {
                                               Title = "Negativas",
                                               Link = "#",
                                               Value = sentimentValuator.NegativeCount
                                           });
            sentimentBox.StatItems.Add(new StatItem()
                                           {
                                               Title = "Neutras",
                                               Link = "#",
                                               Value = sentimentValuator.NeutralCount
                                           });
            if (model.Items.Count > 0)
            {
                sentimentBox.StatItems[0].ValueText =
                    ((decimal)sentimentValuator.PositiveCount / model.Items.Count * 100).ToString("f") + "%";
                sentimentBox.StatItems[1].ValueText =
                    ((decimal)sentimentValuator.NegativeCount / model.Items.Count * 100).ToString("f") + "%";
                sentimentBox.StatItems[2].ValueText =
                    ((decimal)sentimentValuator.NeutralCount / model.Items.Count * 100).ToString("f") + "%";
                sentimentBox.StatItems[0].ValuePercent =
                    ((decimal)sentimentValuator.PositiveCount / model.Items.Count * 100);
                sentimentBox.StatItems[1].ValuePercent =
                    ((decimal)sentimentValuator.NegativeCount / model.Items.Count * 100);
                sentimentBox.StatItems[2].ValuePercent =
                    ((decimal)sentimentValuator.NeutralCount / model.Items.Count * 100);

            }
            else
            {
                sentimentBox.StatItems[0].ValueText = "0%";
                sentimentBox.StatItems[1].ValueText = "0%";
                sentimentBox.StatItems[2].ValueText = "0%";
                sentimentBox.StatItems[0].ValuePercent = 0;
                sentimentBox.StatItems[1].ValuePercent = 0;
                sentimentBox.StatItems[2].ValuePercent = 0;
            }
        }
        public ActionResult Index(string text = null)
        {
            var model = new SearchResultModel();
            if (text == null || text.Length < WebConstants.MinTextLength)
            {
                this.TempData["Error"] = $"Type more than { WebConstants.MinTextLength } symbols for searching";
                return this.View(model);
            }

            text = text.ToLower();
            model.Courses = this.searchService.GetCourses(text).To<CourseViewModel>().ToList();
            model.Trainers = this.searchService.GetTrainers(text).To<UserViewModel>().ToList();
            model.News = this.searchService.GetNews(text).To<NewsViewModel>().ToList();
            model.ForumPosts = this.searchService.GetForumPosts(text).To<ForumPostViewModel>().ToList();
            model.Specialties = this.searchService.GetSpecialties(text).To<SpecialtyViewModel>().ToList();

            return this.View(model);
        }
        public void buildBoxWith2SearchEnginecon3y2ItemsTest()
        {
            //arrange
            SearchEngineBoxBuilder builder = new SearchEngineBoxBuilder();
            var model = new SearchResultModel();
            var item1 = new Post() { SocialNetworkName = "Twitter" };
            var item2 = new Post() { SocialNetworkName = "Twitter" };
            var item3 = new Post() { SocialNetworkName = "Twitter" };
            var item4 = new Post() { SocialNetworkName = "Facebook" };
            var item5 = new Post() { SocialNetworkName = "Facebook" };
            model.Items.AddRange(new List<Post>() { item1, item2, item3, item4, item5 });
            //act
            builder.BuildBox(model);

            //assert
            model.StatBoxs.Count.Should().Be.EqualTo(1);
            model.StatBoxs[0].StatItems.Count.Should().Be.EqualTo(2);
            model.StatBoxs[0].StatItems[0].Title.Should().Be.EqualTo("Twitter");
            model.StatBoxs[0].StatItems[1].Title.Should().Be.EqualTo("Facebook");
            model.StatBoxs[0].StatItems[0].ValueText.Should().Be.EqualTo("60,00%");
            model.StatBoxs[0].StatItems[1].ValueText.Should().Be.EqualTo("40,00%");
        }
 public void BuildBox(SearchResultModel model)
 {
     foreach (var item in model.Items)
     {
         ProcessItem(item);
     }
     var box = new StatBox() { Title = BoxTitle };
     model.StatBoxs.Add(box);
     foreach (var engine in Engines.OrderByDescending(o=>o.Counter).Take(10))
     {
         var red = new StatItem() { Title = engine.Name, Value = engine.Counter, Link = "#" };
         box.StatItems.Add(red);
         if (model.Items.Count > 0)
         {
             red.ValueText = ((decimal)engine.Counter / model.Items.Count * 100).ToString("f") + "%";
             red.ValuePercent = ((decimal)engine.Counter / model.Items.Count * 100);
         }
         else
         {
             red.ValueText = "0%";
             red.ValuePercent = 0;
         }
     }
 }
Ejemplo n.º 35
0
        public ViewResult Search(string searchTerm)
        {
            SearchResultModel result = new SearchResultModel();
            result.SearchTerm = searchTerm;
            result.Results = Session.Query<Term, SearchIndex>().Where(x => x.Title.StartsWith(searchTerm)).ToList();

            return View(result);
        }
        public JsonResult SearchResults(string parameters, string searchEngines, string sentiment, string socialNetworking, string userName)
        {
            var result = new List<Post>();
            var model = new SearchResultModel();

            if (ModelState.IsValid)
            {
                var searchEngineManager = new SearchEngineManager();
                result = searchEngineManager.Search(parameters, searchEngines.Split(',').ToList());
                result = result.OrderByDescending(o => o.CreatedAt).ToList();
                if (result.Count > 0)
                {
                    GetAllWords();

                    var sentimentValuator = new SentimentValuator
                    {
                        NegativeWords = negativeWords,
                        PositiveWords = positiveWords,
                        IgnoreChars = ignoreList
                    };

                    foreach (var item in result)
                    {
                        sentimentValuator.ProcessItem(item);

                        if (string.IsNullOrEmpty(sentiment) && string.IsNullOrEmpty(socialNetworking) && string.IsNullOrEmpty(userName))
                            model.Items.Add(item);

                        else if (ValidateFilters(sentiment, socialNetworking, userName, item))
                            model.Items.Add(item);
                    }

                    sentimentValuator.ResetCounters();

                    foreach (var item in model.Items)
                    {
                        sentimentValuator.ProcessItem(item);
                    }

                    BuildSentimentBox(model, sentimentValuator);
                    BuildEnginesBox(model);
                    BuildTopUsersBox(model);
                }
            }

            return Json(model, JsonRequestBehavior.AllowGet);
        }
 private void BuildEnginesBox(SearchResultModel model)
 {
     var builder = new SearchEngineBoxBuilder();
     builder.BuildBox(model);
 }
 private void BuildTopUsersBox(SearchResultModel model)
 {
     var builder = new TopUsersBoxBuilder();
     builder.BuildBox(model);
 }
Ejemplo n.º 39
0
        private void PerformSearch(SearchRequest request, SearchResultModel searchResultModel, bool refreshCache, Action<SearchResultModel> onComplete)
        {
            this._searchManager.PerformSearch(request,
                refreshCache,
                searchResult =>
                {
                    ObservableCollection<GlobalSearchGridRow> globalRows = searchResult.Results.Transform<ISearchRow, GlobalSearchGridRow>(row =>
                    {
                        return new GlobalSearchGridRow { ProviderName = ProviderName, SearchRow = row };
                    });

                    searchResultModel.GlobalSearchRows = globalRows;
                    searchResultModel.TotalRows = (int)searchResult.TotalResults;
                    searchResultModel.TimeOfSearch = searchResult.TimeOfSearch;
                    if (onComplete != null)
                    {
                        onComplete(searchResultModel);
                    }
                });
        }
Ejemplo n.º 40
0
        ////Binds the search grid with the model.
        public void BindSearchGrid(XIAPSearchResultGrid grid, SearchResultModel searchResultModel)
        {
            XIAPSearchResultGrid searchGrid = grid;
            grid.DataContext = searchResultModel;
            searchGrid.DataContext = searchResultModel;             
            searchResultModel.CloseButtonVisibility = Visibility.Visible;
            searchResultModel.CloseCommand = this.CloseCommand;
            searchResultModel.IsLoadingData = true;

            searchGrid.NeedData += (sender, args) =>
            {
                if (this.NeedDataCommand.CanExecute(args))
                {
                    args.GridID = searchResultModel.ProviderName;
                    this.NeedDataCommand.Execute(args);
                }
            };
           
            searchGrid.SetBinding(XIAPReadOnlyGrid.SelectedItemProperty,new Binding("SelectedRow")
            {
                Mode = BindingMode.TwoWay,
                Source = searchResultModel
            });

            searchGrid.AllowPaging = true;
            searchGrid.AutoAdjustPageSize = true;
            searchGrid.FooterVisibility = Visibility.Visible;
            searchGrid.SetBinding(XIAPReadOnlyGrid.ShowFooterInfoProperty, new Binding("IsInitialSearch")
            {   
                Converter = new InvertBooleanConverter(),
                Source = this               
            });

            searchGrid.ShowRefreshInfo = true;
            searchGrid.SetBinding(XIAPReadOnlyGrid.RefreshInfoTextProperty, new Binding("RefreshInfoText")
            {
                Source = searchResultModel
            });
            searchGrid.RefreshCommand = this.Refresh;
            this.BindColumnVisibility(searchGrid);        
        }