Exemple #1
0
        // todo refractor
        public async Task <SearchResponseDto> SearchAsync(int currentPage, string query)
        {
            query = query.RemoveDiacritics().ToLower();
            var results = await this.postRepository.SearchAsync(query, currentPage, ItemsPerPage);

            var posts = this.mapper.Map <IEnumerable <PostDto> >(results).ToArray();

            var response = new SearchResponseDto(currentPage, ItemsPerPage, posts);

            return(response);
        }
        public async Task <IActionResult> SearchAsync([FromBody] SearchDto searchDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(searchDto));
            }

            var result = new SearchResponseDto {
                Results = await _companyService.SearchAsync(searchDto)
            };

            return(Json(result));
        }
Exemple #3
0
        // GET api/values
        public SearchResponseDto <BookDto> Get(
            [CsvToArrayModelBinder] int[] author      = null,
            [CsvToArrayModelBinder] int[] protagonist = null,
            [CsvToArrayModelBinder] int[] country     = null,
            BookOrderBy?orderBy = null,
            int?page            = null,
            int?count           = null,
            bool?orderDesc      = null
            )
        {
            var query = _bookStore.Search(author, protagonist, country, page, count, orderBy, orderDesc);

            var bookDtos = query.Results.ToList().Select(b => new BookDto(b)).ToList();

            var dtos = new SearchResponseDto <BookDto>
            {
                Results    = bookDtos,
                TotalCount = query.TotalCount
            };

            return(dtos);
        }
        public async Task <SearchResponseDto> Search(string queryString)
        {
            var products =
                await UnitOfWork.ProductRepository.GetAsync(x => x.Name.Contains(queryString) ||
                                                            x.ShortDescription.Contains(queryString) ||
                                                            x.ProductCode.Contains(queryString));

            var productCategories =
                await UnitOfWork.ProductCategoryRepository.GetAsync(x => x.Title.Contains(queryString) ||
                                                                    x.Slug.Contains(queryString) ||
                                                                    x.Keywords.Contains(queryString));

            var tariffs =
                await UnitOfWork.TariffRepository.GetAsync(x => x.TariffName.Contains(queryString));

            var tariffCategories =
                await UnitOfWork.TariffCategoryRepository.GetAsync(x => x.Title.Contains(queryString) ||
                                                                   x.Slug.Contains(queryString) ||
                                                                   x.Description.Contains(queryString));

            var pages =
                await UnitOfWork.PageRepository.GetAsync(x => x.Title.Contains(queryString) ||
                                                         x.Slug.Contains(queryString) ||
                                                         x.Keywords.Contains(queryString) ||
                                                         x.Description.Contains(queryString));

            var result = new SearchResponseDto
            {
                Tariffs           = tariffs.MapTo <List <TariffDto> >(),
                TariffCategories  = tariffCategories.MapTo <List <TariffCategoryDto> >(),
                Pages             = pages.MapTo <List <PageDto> >(),
                Products          = products.MapTo <List <ProductDto> >(),
                ProductCategories = productCategories.MapTo <List <ProductCategoryDto> >()
            };

            return(result);
        }
        public async Task <SearchResponseDto> FindMatchesAsync(SearchRequestDto searchData)
        {
            var item1 = new SearchResponseItemDto()
            {
                FirstName     = "Kenny",
                MiddleName    = "Alan",
                LastName      = "Long",
                ConstituentId = "DEB850E7-4ACC-4BA5-9282-83E268EA03FA",
                Street1       = "2017 Cowden Ave.",
                Street2       = "",
                City          = "Memphis",
                State         = "TN",
                Zip           = "38104",
                PhoneNumber   = "901-463-7727",
                Email         = "*****@*****.**"
            };

            var item2 = new SearchResponseItemDto()
            {
                FirstName     = "Sharon",
                MiddleName    = "Andrews",
                LastName      = "Long",
                ConstituentId = "1BB7022F-6A5D-4B26-9027-36B3C74DE290",
                Street1       = "2017 Cowden Ave.",
                Street2       = "",
                City          = "Memphis",
                State         = "TN",
                Zip           = "38104",
                PhoneNumber   = "901-414-6323",
                Email         = "*****@*****.**"
            };

            var item3 = new SearchResponseItemDto()
            {
                FirstName     = "Summer",
                MiddleName    = "Renee",
                LastName      = "Smith",
                ConstituentId = "7E36F2CD-31C5-4D2D-80ED-F50B8E22C15A",
                Street1       = "2017 Cowden Ave.",
                Street2       = "",
                City          = "Memphis",
                State         = "TN",
                Zip           = "38111",
                PhoneNumber   = "901-389-2409",
                Email         = "*****@*****.**"
            };

            var item4 = new SearchResponseItemDto()
            {
                FirstName     = "Jodi",
                MiddleName    = "Rose",
                LastName      = "Smith",
                ConstituentId = "A4638643-B876-4F69-B551-19996E27FC04",
                Street1       = "2017 Cowden Ave.",
                Street2       = "",
                City          = "Memphis",
                State         = "TN",
                Zip           = "38111",
                PhoneNumber   = "901-846-4895",
                Email         = "*****@*****.**"
            };

            var item5 = new SearchResponseItemDto()
            {
                FirstName     = "Melissa",
                MiddleName    = "June",
                LastName      = "Smith",
                ConstituentId = "DC37B468-825D-4F9A-86D2-11F30BA8DCAA",
                Street1       = "2017 Cowden Ave.",
                Street2       = "",
                City          = "Memphis",
                State         = "TN",
                Zip           = "38111",
                PhoneNumber   = "901-553-7879",
                Email         = "*****@*****.**"
            };

            var item6 = new SearchResponseItemDto()
            {
                FirstName     = "Leroy",
                MiddleName    = "Flapjack",
                LastName      = "Griddlecakes",
                ConstituentId = "E6F56F1D-7FFB-4D81-94A1-BE2B8B3CEF5C",
                Street1       = "555 Quick St.",
                Street2       = "",
                City          = "Memphis",
                State         = "TN",
                Zip           = "38119",
                PhoneNumber   = "901-555-4363",
                Email         = "*****@*****.**"
            };

            var item7 = new SearchResponseItemDto
            {
                FirstName     = "Billy",
                MiddleName    = "Brooks",
                LastName      = "Greene",
                ConstituentId = "B35CEBFD-867B-4272-B72F-5B091C9CE3BE",
                Street1       = "1257 Oakridge Rd.",
                Street2       = "",
                City          = "Memphis",
                State         = "TN",
                Zip           = "38108",
                PhoneNumber   = "901-634-2849",
                Email         = "*****@*****.**"
            };

            var inMemoryData = new SearchResponseDto {
                Matches = new List <SearchResponseItemDto>()
            };

            inMemoryData.Matches.Add(item1);
            inMemoryData.Matches.Add(item2);
            inMemoryData.Matches.Add(item3);
            inMemoryData.Matches.Add(item4);
            inMemoryData.Matches.Add(item5);
            inMemoryData.Matches.Add(item6);
            inMemoryData.Matches.Add(item7);

            var matchingRows = new SearchResponseDto {
                Matches = new List <SearchResponseItemDto>()
            };

            foreach (var row in inMemoryData.Matches)
            {
                if (!string.IsNullOrEmpty(searchData.FirstName) && !string.IsNullOrEmpty(row.FirstName))
                {
                    if (!row.FirstName.StartsWith(searchData.FirstName.Trim()))
                    {
                        break;
                    }
                }

                if (!string.IsNullOrEmpty(searchData.MiddleName) && !string.IsNullOrEmpty(row.MiddleName))
                {
                    if (!row.MiddleName.StartsWith(searchData.MiddleName.Trim()))
                    {
                        break;
                    }
                }

                if (!string.IsNullOrEmpty(searchData.LastName) && !string.IsNullOrEmpty(row.LastName))
                {
                    if (!row.LastName.StartsWith(searchData.LastName.Trim()))
                    {
                        break;
                    }
                }

                if (!string.IsNullOrEmpty(searchData.Street1) && !string.IsNullOrEmpty(row.Street1))
                {
                    if (!row.Street1.StartsWith(searchData.Street1.Trim()))
                    {
                        break;
                    }
                }

                if (!string.IsNullOrEmpty(searchData.Street2) && !string.IsNullOrEmpty(row.Street2))
                {
                    if (!row.Street2.StartsWith(searchData.Street2.Trim()))
                    {
                        break;
                    }
                }

                if (!string.IsNullOrEmpty(searchData.City) && !string.IsNullOrEmpty(row.City))
                {
                    if (!row.City.StartsWith(searchData.City.Trim()))
                    {
                        break;
                    }
                }

                if (!string.IsNullOrEmpty(searchData.State) && !string.IsNullOrEmpty(row.State))
                {
                    if (!row.State.StartsWith(searchData.State.Trim()))
                    {
                        break;
                    }
                }

                if (!string.IsNullOrEmpty(searchData.Zip) && !string.IsNullOrEmpty(row.Zip))
                {
                    if (!row.Zip.StartsWith(searchData.Zip.Trim()))
                    {
                        break;
                    }
                }

                if (!string.IsNullOrEmpty(searchData.PhoneNumber) && !string.IsNullOrEmpty(row.PhoneNumber))
                {
                    if (!row.PhoneNumber.StartsWith(searchData.PhoneNumber.Trim()))
                    {
                        break;
                    }
                }

                if (!string.IsNullOrEmpty(searchData.Email) && !string.IsNullOrEmpty(row.Email))
                {
                    if (!row.Email.StartsWith(searchData.Email.Trim()))
                    {
                        break;
                    }
                }

                if (!string.IsNullOrEmpty(searchData.ConstituentId) && !string.IsNullOrEmpty(row.ConstituentId))
                {
                    if (!row.ConstituentId.StartsWith(searchData.ConstituentId.Trim()))
                    {
                        break;
                    }
                }

                matchingRows.Matches.Add(row);
            }
            return(matchingRows);
        }
Exemple #6
0
        /*private static string GetContentSourcesSearchCondition(string contentSources)
         * {
         *  var contentSourcesSearchConditions = string.Empty;
         *  var sources = contentSources.Split(',');
         *
         *  foreach (var source in sources)
         *  {
         *      if (contentSourcesSearchConditions.Length > 0)
         *          contentSourcesSearchConditions += " OR ";
         *      contentSourcesSearchConditions += Settings.Default.SP2013ContentSourceName + "=\"" + source + "\"";
         *  }
         *
         *  if (contentSourcesSearchConditions.Length > 0)
         *      contentSourcesSearchConditions = " AND (" + contentSourcesSearchConditions + ")";
         *
         *  return contentSourcesSearchConditions;
         * }*/

        public SearchResponseDto GetSearchResults(string searchTerm, Dictionary <string, string> sources, Dictionary <string, string> refiners, String enabledRefiners, int skip, int take, Dictionary <String, SortDirection> sorts)
        {
            SearchResponseDto             retVal = null;
            List <SearchContentSourceDto> srcs   = null;

            using (var ctx = new ClientContext(Settings.Default.SP2013SearchUrl))
            {
                //// get the content sources for the query
                //var contentSources = string.Empty;
                //if (!string.IsNullOrEmpty(Settings.Default.SP2013ContentSources))
                //{
                //    srcs = GetContentSourcesList(Settings.Default.SP2013ContentSources);
                //    if ((sources != null) && (sources.Count > 0))
                //        srcs = SetSearchedContentSourcesList(sources, srcs);
                //    contentSources = GetContentSourcesSearchCondition(srcs);
                //}

                var query = new KeywordQuery(ctx)
                {
                    QueryText = searchTerm,
                    StartRow  = skip,
                    RowLimit  = take, TrimDuplicates = false
                };

                query.Refiners        = enabledRefiners;
                query.ProcessBestBets = true;

                if (refiners != null)
                {
                    foreach (var refiner in refiners)
                    {
                        var s = refiner.Value.Split(new Char[] { ',' }).Count();
                        if (s > 1)
                        {
                            query.RefinementFilters.Add(String.Format("{0}:or({1})", refiner.Key, refiner.Value));
                        }
                        else
                        {
                            query.RefinementFilters.Add(String.Format("{0}:{1}", refiner.Key, refiner.Value));
                        }
                        //foreach (var item in refiner.Value.Split(new Char[] {','}))
                        //{
                        //    query.RefinementFilters.Add(String.Format("{0}:{1}", refiner.Key, item));
                        //}
                    }
                }


                if (sorts != null)
                {
                    query.EnableSorting = true;
                    foreach (var item in sorts)
                    {
                        query.SortList.Add(item.Key, item.Value);//Requires sorting enabled in search
                    }
                }

                var returnProps = Settings.Default.SP2013Properties.Split(',');

                foreach (var prop in returnProps)
                {
                    query.SelectProperties.Add(prop);
                }

                var executor = new SearchExecutor(ctx);

                var results = executor.ExecuteQuery(query);

                ctx.ExecuteQuery();

                var relevantResults = results.Value.FirstOrDefault(v => v.TableType == "RelevantResults");

                if (relevantResults != null)
                {
                    retVal = new SearchResponseDto(skip + 1, take, relevantResults.TotalRowsIncludingDuplicates);
                    if (results.Value.Properties.ContainsKey("piPageImpression"))
                    {
                        retVal.pageinfo = results.Value.Properties["piPageImpression"].ToString();
                    }

                    if (relevantResults.Properties.ContainsKey("piPageImpressionBlockType"))
                    {
                        retVal.blockType = Int32.Parse(relevantResults.Properties["piPageImpressionBlockType"].ToString());
                    }

                    retVal.queryText = query.QueryText;

                    if (results.Value.Properties.ContainsKey("SourceId"))
                    {
                        retVal.sourceId = results.Value.Properties["SourceId"].ToString();
                    }

                    if (srcs != null)
                    {
                        retVal.ContentSources = srcs;
                    }
                    retVal.SearchResults.AddRange(
                        relevantResults.ResultRows.Select(GetSearchContentDto).Where(contentDto => contentDto != null));

                    retVal.Properties = returnProps;
                    retVal.Refiners   = results.Value.FirstOrDefault(v => v.TableType == "RefinementResults");
                }
            }

            return(retVal);
        }