public static AutocompleteResult AutoComplete(this IProviderSearchContext context, AzureSuggestQuery q, string suggeterName, AutocompleteParameters options) { ICloudSearchIndex index = context.Index as CloudSearchProviderSuggestionIndex; Assert.IsNotNull(index, "index"); return(((CompositeSearchService)index.SearchService).Autocomplete(q, suggeterName, options)); }
public static Author GetAuthorByName(Item currentItem, string authorName) { try { BlogSettings settingsItem = General.DataManager.GetBlogSettingsItem(currentItem); ISearchIndex index = ContentSearchManager.GetIndex(new SitecoreIndexableItem(settingsItem.AuthorFolder)); using (IProviderSearchContext context = index.CreateSearchContext()) { Expression <Func <SearchResultItem, bool> > predicate = PredicateBuilder.True <SearchResultItem>(); predicate = predicate.And(item => item.TemplateId == ID.Parse(Author.AuthorTemplateId) && item.Paths.Contains(settingsItem.AuthorFolder.ID)); predicate = predicate.And(c => c[Author.AuthorFullNameField] == authorName); IQueryable <SearchResultItem> results = context.GetQueryable <SearchResultItem>().Where(predicate).OrderBy(t => t.Name); if (results.Any()) { return(results.FirstOrDefault().GetItem().CreateAs <Author>()); } } } catch (Exception ex) { Log.Error("XBlog GetCategory error", ex, new object()); } return(null); }
public new IEnumerable <TestingSearchResultItem> GetRunningTestsWithDataSourceItem(Item dataSourceItem) { ISearchIndex testingSearchIndex = GetTestingSearchIndex(); if (testingSearchIndex == null) { return(Enumerable.Empty <Models.TestingSearchResultItem>()); } using (IProviderSearchContext providerSearchContext = testingSearchIndex.CreateSearchContext(SearchSecurityOptions.DisableSecurityCheck)) { Expression <Func <Models.TestingSearchResultItem, bool> > predicate = PredicateBuilder.True <Models.TestingSearchResultItem>(); predicate = AddDatesSearchCriteria(predicate); predicate = AddDefaultSearchCriteria(predicate); // Querying our new field that is TriState compatible predicate = predicate.And((Models.TestingSearchResultItem x) => x.IsRunningString == "1"); // https://doc.sitecore.com/developers/90/platform-administration-and-architecture/en/support-reference-for-azure-search.html // Quote: You must not apply queries such as StartsWith, Contains to fields with of type EDM.String that contain paths (such as /sitecore/content/home) or collections of GUIDs. // This is because Azure Search matches regular expression searches to single words. // // Alright then we must fix this. DataSourceItems contains path like content... // "datasourceitems_s": "sitecore://{B765C5DD-E0AD-4D91-BA63-B082656ED909}?lang=en&ver=1|sitecore://{C547CF9A-D9CC-42D7-A1D5-B14AB9BBD870}?lang=en&ver=1" // Therefore I introduced a new field with a propper value in it that won't need any special escape characters string dataSourceId = dataSourceItem.ID.ToShortID().ToString().Replace("-", string.Empty); predicate = predicate.And((Models.TestingSearchResultItem x) => x.DataSourceItemsTidy.Contains(dataSourceId)); var result = providerSearchContext.GetQueryable <Models.TestingSearchResultItem>().Where(predicate).ToArray(); return(result); } }
public static IEnumerable <BlogPost> GetBlogPostsMK([NotNull] Item blogRoot, int startRowIndex, int maximumRows, bool descending) { try { ISearchIndex index = ContentSearchManager.GetIndex(new SitecoreIndexableItem(blogRoot)); using (IProviderSearchContext context = index.CreateSearchContext()) { Expression <Func <SearchResultItem, bool> > predicate = GetBlogItemsQueryPredicate(blogRoot); if (descending) { //.Slice(startRowIndex, maximumRows) return(context.GetQueryable <SearchResultItem>().Where(predicate) .OrderByDescending(result => result["TODO REPLACE THIS WITH THE PUBLISH DATE FIELD THAT LUCENE HAS"]) .CreateAs <BlogPost>()); } else { return(context.GetQueryable <SearchResultItem>().Where(predicate) .OrderBy(result => result["TODO REPLACE THIS WITH THE PUBLISH DATE FIELD THAT LUCENE HAS"]) .CreateAs <BlogPost>()); } } } catch (Exception ex) { Log.Error("XBlog GetBlogPosts error", ex, new object()); } return(Enumerable.Empty <BlogPost>()); }
private SearchItems QueryBanner(IProviderSearchContext searchContext, string path, int page = 0, int pageSize = 100) { var query = PredicateBuilder.True <BannerIndex>(); if (!string.IsNullOrEmpty(path)) { query = query.And(x => x.Path.Contains(path).Boost(DefaultBoost)); } var today = DateUtil.ToUniversalTime(DateTime.Now); query = query.And(x => !x.ExpiryDateHasValue || (x.ExpiryDateHasValue && x.ExpiryDate >= today)); query = query.And(x => !x.PostDateHasValue || (x.PostDateHasValue && x.PostDate <= today)); var results = searchContext.GetQueryable <BannerIndex>() .Where(query) .Page(page, pageSize) .Filter(x => x.IsLatestVersion) .Filter(x => x.Language == this._sitecoreContext.Language.Name) .Filter(x => x.AllTemplates.Contains(IdHelper.NormalizeGuid(FrasersContent.Templates.Banner.ID))) .GetResults(); var items = this.BuildResultModel(results); var hits = results.TotalSearchResults; return(new SearchItems(items, hits)); }
public static IQueryable<T> ProcessScopeQuery<T>(IQueryable<T> query, IProviderSearchContext context, string scope) where T : ISearchResult { var searchStringModel = SearchStringModel.ParseDatasourceString(scope).ToList(); query = LinqHelper.CreateQuery<T>(context, searchStringModel); query = AddSorting(query, searchStringModel); return query; }
/// <summary>Gets the Children of the result</summary> /// <returns>IQueryable<TResult></returns> public IQueryable <TResult> GetChildren <TResult>(IProviderSearchContext context) where TResult : SearchResultItem, new() { Item sitecoreItem = this.GetItem(); var query = context.GetQueryable <TResult>(new CultureExecutionContext(new CultureInfo(this.Language))).Where(i => i.Parent == sitecoreItem.ID); return(query); }
private static IQueryable <T> SetupSearchCriteria <T>(Func <IQueryable <T>, IQueryable <T> > whereSnippet, Func <IQueryable <T>, IQueryable <T> > facetSnippet, Func <IQueryable <T>, IQueryable <T> > sortSnippet, SearchQuery query, IProviderSearchContext context) where T : class, IPageBase, ISearchableContent { IQueryable <T> queryable = context.GetQueryable <T>(); //Make sure only items marked a Searchable are searched queryable = queryable.Where(s => s.BaseTemplates.Contains(ISearchableContentConstants.TemplateId.Guid)); //Make sure you return results only for the type requested Guid templateId = typeof(T).GetTemplateIdFromType(); if (!templateId.Equals(Guid.Empty)) { //Apply the template filter so that only items of the specified type will be returned queryable = queryable.Where(s => s.BaseTemplates.Contains(templateId)); } if (!string.IsNullOrEmpty(query.Keyword)) { queryable = queryable.Where(s => s.Title.Like(query.Keyword, 0f).Boost(5) || s.Description.Like(query.Keyword, 0f)); } //Apply the where conditions that we passed in queryable = whereSnippet.Invoke(queryable); //apply the facets that were requested queryable = facetSnippet.Invoke(queryable); //apply any sorting rules specified queryable = sortSnippet.Invoke(queryable); return(queryable); }
public string AutoComplete(string querytext) { var indexName = String.Format("sitecore_{0}_index", Sitecore.Context.Database.Name); ISearchIndex index = ContentSearchManager.GetIndex(indexName); var tID = new ID("{766464BE-12CA-4441-8DF2-2D3865B57B23}"); List <string> Listtm = new List <string>(); using (IProviderSearchContext context = index.CreateSearchContext()) { var query = context.GetQueryable <TestModel>();//.Where(x => x.title.Contains("News")); query = query.Filter(x => x.TemplateId == tID); var results = query.GetResults(); var finalresult = results.Hits.Select(h => GetSiteCoreItem(h.Document.ItemId)).ToArray(); foreach (var Item in finalresult) { JsonModel tm = new JsonModel(); Listtm.Add(Item.Fields["title"].ToString()); // tm.title = Item.Fields["title"].ToString(); // Listtm.Add(tm); } } return(JsonConvert.SerializeObject(Listtm)); }
/// <summary> /// Gets a queryable for Synthesis items /// </summary> /// <typeparam name="TResult">The type of the result item to bind to.</typeparam> /// <param name="context">The search context to use</param> /// <param name="applyStandardFilters">Controls whether results will be auto-filtered to context language, correct template, and latest version</param> /// <param name="executionContext">The execution context to run the query under</param> /// <returns>A queryable item that standard Sitecore LINQ can be used on</returns> public static IQueryable <TResult> GetSynthesisQueryable <TResult>(this IProviderSearchContext context, bool applyStandardFilters, params IExecutionContext[] executionContext) where TResult : IStandardTemplateItem { IQueryable <TResult> queryable; var luceneContext = context as LuceneSearchContext; if (luceneContext != null) { var overrideMapper = new SynthesisLuceneDocumentTypeMapper(); overrideMapper.Initialize(context.Index); var mapperExecutionContext = new OverrideExecutionContext <IIndexDocumentPropertyMapper <Document> >(overrideMapper); var executionContexts = new List <IExecutionContext>(); if (executionContext != null) { executionContexts.AddRange(executionContext); } executionContexts.Add(mapperExecutionContext); queryable = GetLuceneQueryable <TResult>(luceneContext, executionContexts.ToArray()); } else { // TODO: possible SOLR support with different mapper throw new NotImplementedException("At this time Synthesis only supports Lucene indexes."); } if (applyStandardFilters) { queryable = queryable.ApplyStandardFilters(); } return(queryable); }
/// <summary> /// If the datasource is based on our query template or is a query, we can execute the search here and return a list of items. /// </summary> protected List <Item> GetDataSourceItemsFromQuery(string query) { try { //Open search context based off the current item using (IProviderSearchContext context = ContentSearchManager.CreateSearchContext((SitecoreIndexableItem)(Sitecore.Context.Item))) { string languageCode = Sitecore.Context.Language.CultureInfo.TwoLetterISOLanguageName.ToString(); IQueryable <Item> queryable = (from toItem in LinqHelper.CreateQuery <SitecoreItem>(context, SearchStringModel.ParseDatasourceString(query)) where toItem.Language == languageCode select toItem.GetItem()); // the master index will have each version so we need to remove the duplicates. if (Sitecore.Context.Item.Database.Name.ToLower() == "master") { return(queryable.ToList <Item>().Distinct(new ItemIDComparer()).ToList <Item>()); } else { return(queryable.ToList <Item>()); } } } catch { return(new List <Item>()); } }
public IEnumerable <Suggestion> GetSuggestions(SuggesterModel model, out XA.Foundation.Search.Timer queryTimer, out string indexName) { bool fuzzy = Configuration.Settings.GetBoolSetting("AzureSearchSuggesterFuzzy", false); bool highlights = Configuration.Settings.GetBoolSetting("AzureSearchSuggesterHighlight", false); ISearchIndex searchIndex = IndexResolver.ResolveIndex(!model.ContextItemID.IsNull ? ContentRepository.GetItem(model.ContextItemID) : null); indexName = searchIndex.Name; searchIndex.Initialize(); using (IProviderSearchContext searchContext = searchIndex.CreateSearchContext(SearchSecurityOptions.Default)) { SuggestParameters sp = new SuggestParameters() { UseFuzzyMatching = fuzzy, Top = 5 }; if (highlights) { string tag = Configuration.Settings.GetSetting("AzureSearchSuggesterHighlightTag"); sp.HighlightPreTag = $"<{tag}>"; sp.HighlightPostTag = $"</{tag}>"; } AzureSuggestQuery term = model.Term; DocumentSuggestResult <Document> handlerQueryResults; using (queryTimer = new XA.Foundation.Search.Timer()) handlerQueryResults = searchContext.Suggest(term, Configuration.Settings.GetSetting("AzureSearchSuggesterName"), sp); return(handlerQueryResults.Results.Select(a => new Suggestion() { Term = a.Text, Payload = JsonConvert.SerializeObject(a.Document) })); } }
protected virtual IQueryable <SitecoreUISearchResultItem> CreateQuery(IProviderSearchContext context, string query) { var parsedQuery = UIFilterHelpers.ParseDatasourceString(query); var linqQuery = LinqHelper.CreateQuery(context, parsedQuery); return(FilterQuery(linqQuery)); }
/// <summary> /// Method is used for getting direct facets without getting search results /// </summary> /// <param name="requestModel">Request Models</param> /// <param name="searchConfiguration">Search Configuration (Required)</param> /// <returns>List of facets</returns> public IEnumerable <FacetModel> GetFacets(TRequest requestModel, ISearchConfiguration searchConfiguration) { try { if (searchConfiguration != null) { SetIndexConfiguration(searchConfiguration); } Assert.IsNotNull(Index, "Index"); Assert.IsNotNull(SearchConfiguration, "SearchConfiguration is null"); if (!EnsureIndexExistence(Index)) { return(new List <FacetModel>()); } using (IProviderSearchContext searchContext = Index.CreateSearchContext()) { var items = searchContext.GetQueryable <TIndexModel>( new CultureExecutionContext(Context.Language.CultureInfo)); return(GetFacets(items, requestModel)); } } catch (Exception ex) { Logging.Log.Error("Error occurred during getting facets: Error message:" + ex.ToString(), ex); } return(new List <FacetModel>()); }
public new IEnumerable <TestingSearchResultItem> GetRunningTestsInAllLanguages(Item hostItem) { Assert.ArgumentNotNull(hostItem, "hostItem"); ISearchIndex testingSearchIndex = GetTestingSearchIndex(); if (testingSearchIndex == null) { return(Enumerable.Empty <Models.TestingSearchResultItem>()); } List <Models.TestingSearchResultItem> list = new List <Models.TestingSearchResultItem>(); using (IProviderSearchContext providerSearchContext = testingSearchIndex.CreateSearchContext(SearchSecurityOptions.DisableSecurityCheck)) { Expression <Func <Models.TestingSearchResultItem, bool> > first = PredicateBuilder.True <Models.TestingSearchResultItem>(); Language[] languages = hostItem.Languages; foreach (Language language in languages) { Item itemInLanguage = hostItem.Database.GetItem(hostItem.ID, language); // This is de wrong implementation because it only focusses on if the current item is the initiator/host of the test. first = first.Or((Models.TestingSearchResultItem x) => x.HostItemPartial == FieldFormattingHelper.FormatUriForSearch(itemInLanguage)); // It should focus on if the current item is subject of the actual test. string dataSourceId = itemInLanguage.ID.ToShortID().ToString().Replace("-", string.Empty); first = first.Or((Models.TestingSearchResultItem x) => x.DataSourceItemsTidy.Contains(dataSourceId)); } // Querying our new field that is TriState compatible first = first.And((Models.TestingSearchResultItem x) => x.IsRunningString == "1"); list.AddRange(providerSearchContext.GetQueryable <Models.TestingSearchResultItem>().Where(first).ToArray()); return(list); } }
public static DocumentSuggestResult <Document> Suggest(this IProviderSearchContext context, AzureSuggestQuery q, string suggeterName, SuggestParameters options) { ICloudSearchIndex index = context.Index as CloudSearchProviderSuggestionIndex; Assert.IsNotNull(index, "index"); return(((CompositeSearchService)index.SearchService).Suggest(q, suggeterName, options)); }
private IQueryable <SearchResultItem> CreateAndInitializeQuery(IProviderSearchContext context) { var queryable = context.GetQueryable <SearchResultItem>(); queryable = this.InitializeQuery(queryable); return(queryable); }
public void Setup() { this.fakeIndex = A.Fake <ISearchIndex>(); this.fakeSearchContext = A.Fake <IProviderSearchContext>(); A.CallTo(() => this.fakeIndex.CreateSearchContext(SearchSecurityOptions.DisableSecurityCheck)).Returns(this.fakeSearchContext); }
private UrlString GetRedirectUrl(Uri returnUrl) { // NOTE [ILs] Don't redirect to absolute uris for redirectUrl after login, this may be a nefarious attempt to steal user information string result = returnUrl != null && returnUrl.IsAbsoluteUri ? string.Empty : returnUrl?.OriginalString; if (string.IsNullOrWhiteSpace(result)) { SearchResultItem searchResult; using (IProviderSearchContext searchContext = _searchIndex.CreateSearchContext()) { searchResult = searchContext.GetQueryable <SearchResultItem>() .FirstOrDefault( i => i.Paths.Contains(_siteRoot) && i.TemplateId == Templates.LoginSettings.Id); } Item loginSettingsItem = searchResult?.GetItem(); if (loginSettingsItem != null) { LinkField linkField = loginSettingsItem.Fields[Templates.LoginSettings.Fields.PostLoginRedirect]; Item targetItem = linkField.TargetID != (ID)null && linkField.TargetID != ID.Null ? _db.GetItem(linkField.TargetID) : null; result = targetItem != null?LinkManager.GetItemUrl(targetItem) : null; } } return(new UrlString(result ?? "/")); }
private List<Item> GetLinkedSitecoreItems(string gcId) { var result = new List<Item>(); ISearchIndex index = ContentSearchManager.Indexes.SingleOrDefault(i => i.Name.Equals(IndexName)); if (index == null) { Log.Warn("Index " + IndexName + " not found!", this); return result; } using (IProviderSearchContext context = index.CreateSearchContext()) { var query = context.GetQueryable<SearchResultItem>() .Where(i => i.Path.StartsWith("/sitecore/content/") && i["gc_content_id"] == gcId ); query = query.Filter(i => i.Language == Context.Language.Name); var res = query.GetResults(); if (res.TotalSearchResults == 0) { return result; } result = res.Hits .Select(h => h.Document.GetItem()) .Where(i => i != null) .ToList(); return result; } }
public ActionResult AutoComplete(string searchText) { var q = new List <JsonItem>(); var contextItem = PageContext.Current.Item; using (IProviderSearchContext searchContext = SearchIndex.CreateSearchContext(SearchSecurityOptions.EnableSecurityCheck)) { var contextItemShortId = contextItem.ID.ToShortID().ToString().ToLowerInvariant(); var queryable = searchContext.GetQueryable <CustomSearchResultItem>(); queryable = queryable.Where(i => i.GuidPath.Equals(contextItemShortId) && ( i.Name.StartsWith(searchText) || i.Content.Contains(searchText) )).Take(100); queryable.ToList().ForEach(r => { var i = r.GetItem(); q.Add(new JsonItem() { ID = i.ID.Guid, Name = i.Name, DisplayName = i.DisplayName, Path = i.Paths.FullPath, RelativeLink = Sitecore.Links.LinkManager.GetItemUrl(i), PageTitle = !string.IsNullOrEmpty(i["PageTitle"]) ? i["PageTitle"] : i.DisplayName, ButtonTitle = !string.IsNullOrEmpty(i["ButtonTitle"]) ? i["ButtonTitle"] : i.DisplayName }); }); } return(Json(q, JsonRequestBehavior.AllowGet)); }
public static List <ID> GetTagItemIds(IEnumerable <string> taxonomyItemNames) { try { Tag tagRepository = GetTagRepositoryItem(); using (IProviderSearchContext context = ContentSearchManager.GetIndex(new SitecoreIndexableItem(tagRepository.InnerItem)).CreateSearchContext()) { Expression <Func <SearchResultItem, bool> > predicate = PredicateBuilder.True <SearchResultItem>(); predicate = predicate.And(item => item.TemplateId == ID.Parse(Tag.TagTemplateId)); predicate = predicate.And(item => item.Language == Context.Language.Name); Expression <Func <SearchResultItem, bool> > predicate1 = PredicateBuilder.True <SearchResultItem>(); taxonomyItemNames.ForEach(name => { predicate1 = predicate1.Or(p => p.Name == name); }); predicate = predicate.And(predicate1); List <ID> returnList = context.GetQueryable <SearchResultItem>().Where(predicate).Select(result => result.ItemId).ToList(); return(returnList); } } catch (Exception ex) { Log.Error("XBlog GetTaxonomyItemIds error", ex, new object()); } return(new List <ID>(0)); }
public Expression <Func <SearchResultItem, bool> > GetPredicatesFromRules(IProviderSearchContext context, string rawRules, Database db) { Assert.ArgumentNotNull(db, nameof(db)); var expression = PredicateBuilder.True <SearchResultItem>(); Sitecore.ContentSearch.Rules.QueryableRuleFactory ruleFactory = new Sitecore.ContentSearch.Rules.QueryableRuleFactory(); var rules = ruleFactory.ParseRules <Sitecore.ContentSearch.Rules.QueryableRuleContext <SearchResultItem> >(db, rawRules); if (!rules.Rules.Any()) { return(null); } foreach (var rule in rules.Rules) { if (rule.Condition != null) { var ruleContext = new Sitecore.ContentSearch.Rules.QueryableRuleContext <SearchResultItem>(context); var stack = new RuleStack(); rule.Condition.Evaluate(ruleContext, stack); rule.Execute(ruleContext); if (stack.Any()) { expression = ruleContext.Where; } } } return(expression); }
protected virtual IQueryable<SitecoreUISearchResultItem> CreateQuery(IProviderSearchContext context, string query) { var parsedQuery = UIFilterHelpers.ParseDatasourceString(query); var linqQuery = LinqHelper.CreateQuery(context, parsedQuery); return FilterQuery(linqQuery); }
/// <summary>Gets the Descendants of the result</summary> /// <returns>IQueryable<TResult></returns> public IQueryable <TResult> GetDescendants <TResult>(IProviderSearchContext context) where TResult : SearchResultItem, new() { Item sitecoreItem = this.GetItem(); var s = IdHelper.NormalizeGuid(sitecoreItem.ID.ToString()); var query = context.GetQueryable <TResult>(new CultureExecutionContext(new CultureInfo(this.Language))).Where(i => (i.Parent == sitecoreItem.ID || i.Paths.Contains(sitecoreItem.ID)) && (i["_group"] != s)); return(query); }
public static IQueryable <SearchResultItem> ProcessScopeQuery(IProviderSearchContext context, string scope) { var searchStringModel = SearchStringModel.ParseDatasourceString(scope).ToList(); var query = LinqHelper.CreateQuery <SearchResultItem>(context, searchStringModel); query = AddSorting(query, searchStringModel); return(query); }
/// <summary> /// Invoke the ResolveRenderingDataSource pipeline to resolve the data source item /// </summary> private static Item[] RunPipeline(string dataSource, Item contextItem, IProviderSearchContext searchContext) { var args = new ResolveRenderingDataSourceArgs(dataSource, contextItem, searchContext); CorePipeline.Run("resolveRenderingDataSource", args); return(args.DataSourceItems.ToArray()); }
public ResolveRenderingDataSourceArgs(string dataSource, Item contextItem, IProviderSearchContext searchContext) { Assert.ArgumentNotNull(contextItem, "contextItem"); DataSource = dataSource; ContextItem = contextItem; SearchContext = searchContext; DataSourceItems = new List <Item>(); }
/// <summary> /// Given a DataSource string (from the layout editor), resolves the item that refers to. /// </summary> /// <param name="dataSource">The string data source passed to the presentation component.</param> /// <param name="contextItem">The context item for relative paths and specifying the database from which to retrieve other items.</param> /// <param name="searchContext">The search context.</param> /// <param name="assertSingleItem">If true, an exception will be thrown if more than one item matches the data source spec</param> public static Item ResolveDataSource(string dataSource, Item contextItem, IProviderSearchContext searchContext, bool assertSingleItem) { var items = ResolveMultipleDataSource(dataSource, contextItem, searchContext); if (assertSingleItem && items.Count() > 1) throw new Exception(string.Format("The data source {0} matches more than one item, and only a single item is expected.", dataSource)); return items.FirstOrDefault(); }
public ResolveRenderingDataSourceArgs(string dataSource, Item contextItem, IProviderSearchContext searchContext) { Assert.ArgumentNotNull(contextItem, "contextItem"); DataSource = dataSource; ContextItem = contextItem; SearchContext = searchContext; DataSourceItems = new List<Item>(); }
protected virtual IQueryable <CommentResultItem> CreateQueryable(IProviderSearchContext context, Item rootItem, BlogHomeItem blogItem) { var settings = BlogSettingsResolver.Resolve(blogItem); return(context.GetQueryable <CommentResultItem>().Where(x => x.Paths.Contains(rootItem.ID) && x.TemplateId == settings.CommentTemplateID && x.Language == rootItem.Language.Name )); }
/// <summary> /// Gets all redirects. /// </summary> /// <returns></returns> public List <UrlRedirect> GetAll() { using (IProviderSearchContext context = Index.CreateSearchContext()) { IQueryable <UrlRedirect> query = context.GetQueryable <UrlRedirect>(); query = query.Filter(i => i.Paths.Contains(Constants.Ids.RedirectBucketItemId)) .Filter(i => i.TemplateId == Constants.Ids.RedirectItemTemplateId); return(query.ToList()); } }
/// <summary> /// Gets all redirects. /// </summary> /// <returns></returns> public List <MarketingRedirect> GetAll() { using (IProviderSearchContext context = Index.CreateSearchContext()) { IQueryable <MarketingRedirect> query = context.GetQueryable <MarketingRedirect>(); query = query.Filter(i => i.Paths.Contains(ItemIDs.MarketingRedirectBucketID)) .Filter(i => i.TemplateId == ItemIDs.MarketingRedirectTemplateID); return(query.ToList()); } }
protected override void CleanUpOuterUnitOfWork() { if (_index != null) { try { _index.Dispose(); } finally { _index = null; } } }
public SearchResult Search(SearchParameters searchParameters) { _searchParameters = searchParameters; using (_context = ContentSearchManager.GetIndex(_searchParameters.IndexName).CreateSearchContext()) { Expression<Func<SearchResultItem, bool>> query = _indexQueryBuilder.BuildQuery(searchParameters); IQueryable<SearchResultItem> queryable = ConvertToQueryable(query); queryable = _indexQueryBuilder.ApplySortingPagingFacets(queryable, searchParameters); return ExecuteQuery(queryable); } }
protected ODataSearchController() { _context = Index.CreateSearchContext(); }
protected override void Dispose(bool disposing) { base.Dispose(disposing); if (_index != null) { try { _index.Dispose(); } finally { _index = null; } } }
/// <summary> /// Invoke the ResolveRenderingDataSource pipeline to resolve the data source item /// </summary> private static Item[] RunPipeline(string dataSource, Item contextItem, IProviderSearchContext searchContext) { var args = new ResolveRenderingDataSourceArgs(dataSource, contextItem, searchContext); CorePipeline.Run("resolveRenderingDataSource", args); return args.DataSourceItems.ToArray(); }
/// <summary> /// Given a DataSource string (from the layout editor), resolves the item(s) that refers to. /// </summary> /// <param name="dataSource">The string data source passed to the presentation component.</param> /// <param name="contextItem">The context item for relative paths and specifying the database from which to retrieve other items.</param> /// <param name="searchContext">The search context.</param> public static Item[] ResolveMultipleDataSource(string dataSource, Item contextItem, IProviderSearchContext searchContext) { return ResolveMultipleDataSource(dataSource, contextItem, searchContext, true); }
/// <summary> /// Given a DataSource string (from the layout editor), resolves the item(s) that refers to. /// </summary> /// <param name="dataSource">The string data source passed to the presentation component.</param> /// <param name="contextItem">The context item for relative paths and specifying the database from which to retrieve other items.</param> /// <param name="searchContext">The search context.</param> /// <param name="assertSingleItem">If true, an exception will be thrown if more than one item matches the data source spec</param> public static Item[] ResolveMultipleDataSource(string dataSource, Item contextItem, IProviderSearchContext searchContext, bool assertSingleItem) { Assert.IsNotNull(contextItem, "contextItem"); var items = RunPipeline(dataSource, contextItem, searchContext); return items; }