/// <summary> /// Performs a lucene search using Examine. /// </summary> /// <param name="documentTypes">Array of document type aliases to search for.</param> /// <param name="searchGroups">A list of search groupings, if you have more than one group it will apply an and to the search criteria</param> /// <returns>Examine search results</returns> public Examine.ISearchResults SearchUsingExamine(string[] documentTypes, List <SearchGroup> searchGroups) { if (!ExamineManager.Instance.TryGetIndex("ExternalIndex", out var index)) { throw new InvalidOperationException($"No index found by name 'External Index'"); } var searcher = index.GetSearcher(); var searchCriteria = searcher.CreateQuery(IndexTypes.Content); //only shows results for visible documents. IBooleanOperation queryNodes = searchCriteria.GroupedOr(new string[] { "umbracoNaviHide" }, "0", ""); if (documentTypes != null && documentTypes.Length > 0) { //only get results for documents of a certain type - changed And() to Or() queryNodes = queryNodes.And().GroupedOr(new string[] { _docTypeAliasFieldName }, documentTypes); } if (searchGroups != null && searchGroups.Any()) { //in each search group it looks for a match where the specified fields contain any of the specified search terms //usually would only have 1 search group, unless you want to filter out further, i.e. using categories as well as search terms foreach (SearchGroup searchGroup in searchGroups) { queryNodes = queryNodes.And().GroupedOr(searchGroup.FieldsToSearchIn, searchGroup.SearchTerms); } } //return the results of the search return(queryNodes.Execute()); }
/// <summary> /// Get the results for the given query /// </summary> public ISearchResults Search(IBooleanOperation query, out int totalResults) { var searchResult = query.Execute(); totalResults = (int)searchResult.TotalItemCount; return(searchResult); }
/// <summary> /// Get the results for the given query /// </summary> public IEnumerable <T> Search <T>(IBooleanOperation query, out int totalResults) where T : class, IPublishedContent { var searchResult = query.Execute(); totalResults = (int)searchResult.TotalItemCount; var typedResult = searchResult.GetResults <T>(); return(typedResult); }
/// <summary> /// Get the results for the given query /// </summary> public IEnumerable <T> Search <T>(IBooleanOperation query, out int totalResults) where T : class, IPublishedContent { var searchResult = query.Execute(); totalResults = (int)searchResult.TotalItemCount; var typedResult = searchResult .ToPublishedSearchResults(_publishedSnapshotAccessor.PublishedSnapshot.Content) .Select(x => x.Content as T) .Where(x => x != null); return(typedResult); }