private IEnumerable <NavigationNode> GetNavigationNodesBySearch(SPWeb web, NavigationSearchSettings settings, IEnumerable <string> additionalFilters = null) { var filters = new List <string>(settings.GlobalFilters); // Check if find result source var searchResultSource = this.searchHelper.GetResultSourceByName(web.Site, settings.ResultSourceName, SearchObjectLevel.Ssa); if (searchResultSource == null) { this.logger.Error("searchResultSource is null in GSoft.Dynamite.Navigation.NavigationService.GetNavigationNodeItems"); return(new List <NavigationNode>()); } var query = new KeywordQuery(web) { SourceId = searchResultSource.Id, TrimDuplicates = false, RowLimit = 500 }; // Add defined filters if (additionalFilters != null) { filters.AddRange(additionalFilters); } if (settings.SelectedProperties != null && settings.SelectedProperties.Any()) { query.SelectProperties.AddRange(settings.SelectedProperties.ToArray()); } // TODO: For now, the filters are applied seperated by whitespaces which means "AND" in KQL land. // TODO: We should figure out a way to make this more flexible to use "OR" if necessary. query.QueryText = string.Join(" ", filters.Where(filter => !string.IsNullOrEmpty(filter))); // Execute search query var tables = new SearchExecutor().ExecuteQuery(query); if (tables.Exists(KnownTableTypes.RelevantResults)) { // Build navigation nodes for search results var results = tables.Filter("TableType", KnownTableTypes.RelevantResults).Single(relevantTable => relevantTable.QueryRuleId == Guid.Empty); var nodes = results.Table.Rows.Cast <DataRow>().Select(dataRow => new NavigationNode(dataRow, settings.NavigationManagedPropertyName)); this.logger.Info( "GetNavigationNodeItems: Found {0} items with search query '{1}' from source '{2}'.", results.Table.Rows.Count, query.QueryText, settings.ResultSourceName); return(nodes); } this.logger.Error( "GetNavigationNodeItems: No relevant results table found with search query '{0}' from source '{1}'.", query.QueryText, settings.ResultSourceName); return(new List <NavigationNode>()); }
private IEnumerable<NavigationNode> GetNavigationNodesBySearch(SPWeb web, NavigationSearchSettings settings, IEnumerable<string> additionalFilters = null) { var filters = new List<string>(settings.GlobalFilters); // Check if find result source var searchResultSource = this.searchHelper.GetResultSourceByName(web.Site, settings.ResultSourceName, SearchObjectLevel.Ssa); if (searchResultSource == null) { this.logger.Error("searchResultSource is null in GSoft.Dynamite.Navigation.NavigationService.GetNavigationNodeItems"); return new List<NavigationNode>(); } var query = new KeywordQuery(web) { SourceId = searchResultSource.Id, TrimDuplicates = false, RowLimit = 500 }; // Add defined filters if (additionalFilters != null) { filters.AddRange(additionalFilters); } if (settings.SelectedProperties != null && settings.SelectedProperties.Any()) { query.SelectProperties.AddRange(settings.SelectedProperties.ToArray()); } // TODO: For now, the filters are applied seperated by whitespaces which means "AND" in KQL land. // TODO: We should figure out a way to make this more flexible to use "OR" if necessary. query.QueryText = string.Join(" ", filters.Where(filter => !string.IsNullOrEmpty(filter))); // Execute search query var tables = new SearchExecutor().ExecuteQuery(query); if (tables.Exists(KnownTableTypes.RelevantResults)) { // Build navigation nodes for search results var results = tables.Filter("TableType", KnownTableTypes.RelevantResults).Single(relevantTable => relevantTable.QueryRuleId == Guid.Empty); var nodes = results.Table.Rows.Cast<DataRow>().Select(dataRow => new NavigationNode(dataRow, settings.NavigationManagedPropertyName)); this.logger.Info( "GetNavigationNodeItems: Found {0} items with search query '{1}' from source '{2}'.", results.Table.Rows.Count, query.QueryText, settings.ResultSourceName); return nodes; } this.logger.Error( "GetNavigationNodeItems: No relevant results table found with search query '{0}' from source '{1}'.", query.QueryText, settings.ResultSourceName); return new List<NavigationNode>(); }