/// <summary> /// /// </summary> /// <returns></returns> //[Route("SearchPageAdmin/Search")] public ActionResult Search() { var viewModel = new SearchPageAdminViewModel <SearchDocAdmin>(); var client = SearchFactory <SearchDocAdmin> .SearchClient; var req = new SearchRequest() { QueryText = Request["q"], CurrentPage = TypeParser.ParseInt(Request["p"], 1), Refinements = Request["r"], PageSize = 10, EnableHighlighting = true, }; foreach (var category in EpiHelper.GetRootCategories()) { req.Facets.Add(new CategoryFacet("categories", category.Name, category.Name)); } viewModel.Response = client.Search(req); viewModel.QueryText = Request["q"]; return(View("~/MissionSearchEpi/UI/Views/SearchPageAdmin/index.cshtml", viewModel)); }
/// <summary> /// /// </summary> /// <returns></returns> public static List <SortOrder> ReturnCurrentSort(this ISearchPage srchPage, string currentSort) { var sorts = new List <SortOrder>(); if (!string.IsNullOrEmpty(currentSort)) { // TO DO 01: not loading correct sort order sorts.Add(new SortOrder(currentSort, SortOrder.SortOption.Descending)); return(sorts); } if (srchPage.Sort == null) { return(sorts); } //var sortSettings = srchPage.Sort.FilteredContents.OfType<SortBlock>(); var sortSettings = EpiHelper.GetContentAreaContent <SortBlock>(srchPage.Sort.Items); foreach (var s in sortSettings) { sorts.Add(new SortOrder(s.FieldName, s.SortOrder)); } return(sorts); }
/// <summary> /// /// </summary> /// <returns></returns> public static List <IFacet> ReturnFacetSettings(this ISearchPage srchPage) { var facets = new List <IFacet>(); if (srchPage.Facets == null) { return(facets); } var facetBlocks = EpiHelper.GetContentAreaContent <BlockData>(srchPage.Facets.Items); foreach (var facetBlock in facetBlocks) { if (facetBlock is FieldFacetBlock) { var fieldFacet = facetBlock as FieldFacetBlock; facets.Add(new FieldFacet(fieldFacet.FieldName, fieldFacet.Label) { Sort = fieldFacet.SortOption, Order = facetBlocks.IndexOf(facetBlock), RefinementOption = fieldFacet.RefinementType, }); } else if (facetBlock is CategoryFacetBlock) { var categoryFacet = facetBlock as CategoryFacetBlock; var list = categoryFacet.CategoryName; if (list.Any()) { var categoryName = EpiHelper.GetCategoryName(list.First()); facets.Add(new CategoryFacet("categories", categoryName, categoryFacet.Label) { Sort = categoryFacet.SortOption, Order = facetBlocks.IndexOf(facetBlock), RefinementOption = categoryFacet.RefinementType, }); } } else if (facetBlock is DateRangeFacetBlock) { var dateFacetBlock = facetBlock as DateRangeFacetBlock; var dateFacet = ProcessDateFacetBlock(dateFacetBlock, facetBlocks.IndexOf(facetBlock)); facets.Add(dateFacet); } else if (facetBlock is RangeFacetBlock) { var rangeFacetBlock = facetBlock as RangeFacetBlock; var rangeFacet = ProcessRangeFacetBlock(rangeFacetBlock, facetBlocks.IndexOf(facetBlock)); facets.Add(rangeFacet); } } return(facets); }
/// <summary> /// /// </summary> /// <param name="srchPage"></param> /// <returns></returns> /// public static List <SortOrder> GetSortSettings(this ISearchPage srchPage) { var sorts = new List <SortOrder>(); if (srchPage.Sort == null) { return(sorts); } //var sortSettings = srchPage.Sort.Items.OfType<SortBlock>(); var sortSettings = EpiHelper.GetContentAreaContent <SortBlock>(srchPage.Sort.Items); foreach (var s in sortSettings) { sorts.Add(new SortOrder(s.FieldName, s.SortOrder)); } return(sorts); }
/// <summary> /// /// </summary> /// <param name="mediaItem"></param> /// <returns></returns> public ContentCrawlProxy BuildSearchableAsset(MediaData mediaItem) { var searchableAsset = mediaItem as ISearchableAsset; if (searchableAsset == null) { return(null); } var url = UrlResolver.Current.GetUrl(mediaItem.ContentLink); if (url == null) { return(null); } searchableAsset._ContentID = string.Format("{0}", mediaItem.ContentGuid); try { searchableAsset.AssetBlob = EpiHelper.ReadEpiBlob(mediaItem.BinaryData); } catch (Exception ex) { if (_logger != null) { _logger.Error(string.Format("Asset Crawler: Error Retrieving Asset {0} {1}", ex.Message, ex.StackTrace)); } } var pageCrawlParameters = new ContentCrawlProxy(); pageCrawlParameters.Content.Add(new CrawlerContent() { Name = "title", Value = mediaItem.Name, }); pageCrawlParameters.Content.Add(new CrawlerContent() { Name = "url", Value = url.Replace("?epslanguage=en", string.Format("?epslanguage={0}", mediaItem.Language.Name)), }); pageCrawlParameters.Content.Add(new CrawlerContent() { Name = "pagetype", Value = "Media", }); pageCrawlParameters.Content.Add(new CrawlerContent() { Name = "mimetype", Value = mediaItem.MimeType, }); pageCrawlParameters.Content.Add(new CrawlerContent() { Name = "contenttype", Value = MimeType.GetDisplayName(mediaItem.MimeType), }); pageCrawlParameters.Content.Add(new CrawlerContent() { Name = "language", Value = Languages, }); pageCrawlParameters.Content.Add(new CrawlerContent() { Name = "folder", Value = EpiHelper.GetParentFolderName(mediaItem.ParentLink.ToPageReference()), }); pageCrawlParameters.Content.Add(new CrawlerContent() { Name = "paths", Value = EpiHelper.GetPageTreePaths(mediaItem.ParentLink.ToPageReference()), }); pageCrawlParameters.Content.Add(new CrawlerContent() { Name = "path", Value = EpiHelper.GetFolderPath(mediaItem.ParentLink.ToPageReference()), }); //searchableAsset.CrawlProperties = pageCrawlMetadata; pageCrawlParameters.ContentItem = searchableAsset; return(pageCrawlParameters); }
/// <summary> /// /// </summary> /// <param name="srchPage"></param> /// <param name="queryText"></param> /// <returns></returns> public static List <T> ReturnSuggestedResults <T>(this ISearchPage srchPage, string queryText) where T : ISearchDocument { var suggResults = new List <T>(); if (srchPage.SuggestedResults == null) { return(suggResults); } var suggestedResultBlocks = EpiHelper.GetContentAreaContent <SuggestedResultsBlock>(srchPage.SuggestedResults.Items); var guidList = new List <string>(); var queryIntercept = queryText.ToLower(); foreach (var suggestedBlock in suggestedResultBlocks) { if (string.IsNullOrEmpty(suggestedBlock.Terms)) { continue; } var suggestedTerms = suggestedBlock.Terms.ToLower().Split(',') .Select(str => str.Trim()); if (suggestedTerms.Contains(queryIntercept)) { var results = EpiHelper.GetContentAreaContent <IContent>(suggestedBlock.SuggestedResults.Items); foreach (var result in results) { var id = result.ContentLink.ID.ToString(); if (!guidList.Contains(id)) { guidList.Add(id); } } } } if (guidList.Any()) { var srchClient = SearchFactory <T> .SearchClient; foreach (var guid in guidList) { var req = new SearchRequest(); req.EnableHighlighting = true; req.QueryText = string.Format("contentid:\"{0}\"", guid); var resp = srchClient.Search(req); if (resp.Results.Any()) { suggResults.Add(resp.Results.First()); } } } return(suggResults); }
/// <summary> /// /// </summary> /// <param name="srchPage"></param> /// <returns></returns> public static List <IQueryOption> ReturnQueryOptions(this ISearchPage srchPage) { var extraParms = new List <IQueryOption>(); if (srchPage.QueryOptions != null) { var boostParms = EpiHelper.GetContentAreaContent <BoostQueryBlock> (srchPage.QueryOptions.Items); foreach (var bst in boostParms) { extraParms.Add(new BoostQuery(bst.FieldName, bst.FieldValue, bst.Boost)); } var filterParms = EpiHelper.GetContentAreaContent <FieldQueryBlock>(srchPage.QueryOptions.Items); foreach (var filterBlock in filterParms) { var fieldValue = filterBlock.FieldValue; if (filterBlock.FieldName == "pagetype") { if (filterBlock.FieldValue.Contains((" OR "))) { var replaced = filterBlock.FieldValue.Replace(" OR ", "%OR%"); fieldValue = replaced.Replace(" ", "").Replace("%OR%", " OR "); } else { fieldValue = filterBlock.FieldValue.Replace(" ", ""); } } if (filterBlock.FieldName == "path" && filterBlock.FieldValue.Contains('\\')) { fieldValue = filterBlock.FieldValue.Replace('\\', '/'); } if (filterBlock.FieldName == "path" && filterBlock.Condition == FilterQuery.ConditionalTypes.Contains) { extraParms.Add(new FilterQuery("paths", FilterQuery.ConditionalTypes.Equals, fieldValue)); } else { extraParms.Add(new FilterQuery(filterBlock.FieldName, filterBlock.Condition, fieldValue)); } } //var queryOptions = srchPage.QueryOptions.FilteredContents.OfType<QueryOptionBlock>(); var queryOptions = EpiHelper.GetContentAreaContent <QueryOptionBlock>(srchPage.QueryOptions.Items); foreach (var option in queryOptions) { if (!string.IsNullOrEmpty(option.mm)) { extraParms.Add(new DisMaxQueryParm("mm", option.mm)); } if (!string.IsNullOrEmpty(option.ps)) { extraParms.Add(new DisMaxQueryParm("ps", option.ps)); } if (!string.IsNullOrEmpty(option.pf)) { extraParms.Add(new DisMaxQueryParm("pf", option.pf)); } if (!string.IsNullOrEmpty(option.qf)) { extraParms.Add(new DisMaxQueryParm("qf", option.qf)); } //extraParms.Add(new QueryParm("qs", option.qs.ToString())); } } return(extraParms); }
/// <summary> /// /// </summary> /// <param name="e"></param> private void PublishToIndex(ContentEventArgs e) { var configData = MissionConfig.GetConfigData(); if (configData.IndexOnPublishContent && e.Content.GetType().IsSubclassOf(typeof(BlockData))) { var repository = ServiceLocator.Current.GetInstance <IContentRepository>(); var pages = repository.GetReferencesToContent(e.Content.ContentLink, false); if (pages == null) { return; } var contentCrawler = new ContentCrawler <SearchDocument>(new CrawlerSettings()); foreach (var pageRef in pages) { var page = repository.Get <IContent>(pageRef.OwnerID); if (page != null) { var pageData = page as PageData; if (pageData != null) { var searchableContent = contentCrawler.BuildSearchablePage(pageData); if (searchableContent != null) { SearchFactory <SearchDocument> .ContentIndexer.Update(searchableContent); } } } } } else if (configData.IndexOnPublishAsset && e.Content is ISearchableAsset) { var mediaData = e.Content as MediaData; var crawler = new AssetCrawler <SearchDocument>(); var searchableContent = crawler.BuildSearchableAsset(mediaData); if (searchableContent != null) { SearchFactory <SearchDocument> .AssetIndexer.Update(searchableContent); } } else if (configData.IndexOnPublishContent && e.Content is ISearchableContent) { var pageData = e.Content as PageData; var contentCrawler = new ContentCrawler <SearchDocument>(new CrawlerSettings()); var searchableContent = contentCrawler.BuildSearchablePage(pageData); if (searchableContent == null) { return; } // if moving item then use target link instead of parent link if (e.TargetLink != null && e.TargetLink.ID != 0) { var pageCrawlMetadata = searchableContent as ContentCrawlProxy; if (pageCrawlMetadata != null) { pageCrawlMetadata.Content.Add(new CrawlerContent() { Name = "parent", Value = EpiHelper.GetParentName(e.TargetLink.ToPageReference()), }); pageCrawlMetadata.Content.Add(new CrawlerContent() { Name = "path", Value = EpiHelper.GetPageTreePath(e.TargetLink.ToPageReference()), }); pageCrawlMetadata.Content.Add(new CrawlerContent() { Name = "paths", Value = EpiHelper.GetPageTreePaths(e.TargetLink.ToPageReference()), }); pageCrawlMetadata.Content.Add(new CrawlerContent() { Name = "folder", Value = EpiHelper.GetParentName(e.TargetLink.ToPageReference()), }); } } SearchFactory <SearchDocument> .ContentIndexer.Update(searchableContent); } }
/// <summary> /// Used to intialize default properties /// </summary> /// <param name="page"></param> /// <returns></returns> public ContentCrawlProxy BuildSearchablePage(PageData page) { var searchablePage = page as ISearchableContent; if (searchablePage == null) { return(null); } searchablePage._ContentID = string.Format("{0}-{1}", page.ContentGuid, page.Language.Name); var pageProps = new ContentCrawlProxy(); pageProps.Content.Add(new CrawlerContent() { Name = "title", Value = page.Name, }); pageProps.Content.Add(new CrawlerContent() { Name = "timestamp", Value = page.Changed, }); pageProps.Content.Add(new CrawlerContent() { Name = "url", Value = page.LinkURL.Replace("epslanguage=en", string.Format("epslanguage={0}", page.Language.Name)), }); pageProps.Content.Add(new CrawlerContent() { Name = "contentid", Value = page.ContentLink.ID.ToString(), }); pageProps.Content.Add(new CrawlerContent() { Name = "categories", Value = EpiHelper.GetCategoryPaths(page.Category), }); pageProps.Content.Add(new CrawlerContent() { Name = "hostname", Value = EpiHelper.GetSitePath(page.ContentLink), }); pageProps.Content.Add(new CrawlerContent() { Name = "folder", Value = EpiHelper.GetParentName(page.ParentLink.ToPageReference()), }); pageProps.Content.Add(new CrawlerContent() { Name = "path", Value = EpiHelper.GetPageTreePath(page.ParentLink.ToPageReference()), }); pageProps.Content.Add(new CrawlerContent() { Name = "paths", Value = EpiHelper.GetPageTreePaths(page.ParentLink.ToPageReference()), }); pageProps.Content.Add(new CrawlerContent() { Name = "pagetype", Value = page.PageTypeName, }); pageProps.Content.Add(new CrawlerContent() { Name = "mimetype", Value = "text/html", }); pageProps.Content.Add(new CrawlerContent() { Name = "contenttype", Value = "HTML", }); pageProps.Content.Add(new CrawlerContent() { Name = "language", Value = new List <string>() { page.Language.Name, }, }); // if enabled scrape page content if (_crawlSettings.PageScrapper != null) { var scrapContent = _crawlSettings.PageScrapper.ScrapPage(EpiHelper.GetExternalURL(page)); pageProps.Content.Add(new CrawlerContent() { Name = MissionSearch.Global.ContentField, Value = scrapContent, }); } // parse searchable block data and add to content var parsedBlockText = ProcessContentReferences(page); if (parsedBlockText.Any()) { pageProps.Content.AddRange(parsedBlockText); } //searchablePage.CrawlProperties = pageCrawlMetadata; pageProps.ContentItem = searchablePage; return(pageProps); }