示例#1
0
        /// <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)
        {
            ISearchCriteria   searchCriteria = ExamineManager.Instance.CreateSearchCriteria(BooleanOperation.And);
            IBooleanOperation queryNodes     = null;

            //only shows results for visible documents.
            queryNodes = searchCriteria.GroupedNot(new string[] { "umbracoNaviHide" }, "1");

            if (documentTypes != null && documentTypes.Length > 0)
            {
                //only get results for documents of a certain type
                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(ExamineManager.Instance.Search(queryNodes.Compile()));;
        }
示例#2
0
        /// <summary>
        /// Performs a lucene search using Examine.
        /// </summary>
        /// <param name="documentTypes">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>
        /// <param name="sortFields">optional sort fields.</param>
        /// <param name="sortDescending">sort direction</param>
        /// <returns>Examine search results</returns>
        public ISearchResults Search(IEnumerable <string> documentTypes, IEnumerable <SearchGroup> searchGroups, IEnumerable <string> sortFields = null, bool sortDescending = false)
        {
            var               searchManager  = ExamineManager.Instance; // uses the default providers
            ISearchCriteria   searchCriteria = searchManager.CreateSearchCriteria(BooleanOperation.And);
            IBooleanOperation queryNodes;

            // initialize query
            if (sortFields == null)
            {
                queryNodes = searchCriteria.GroupedNot(new string[] { "__ignoreMe" }, new string[] { "ignoreMe" });
            }
            else if (sortDescending)
            {
                queryNodes = searchCriteria.OrderByDescending(sortFields.ToArray());
            }
            else
            {
                queryNodes = searchCriteria.OrderBy(sortFields.ToArray());
            }

            if (documentTypes?.Any() == true)
            {
                //only get results for documents of a certain type
                queryNodes = queryNodes.And().GroupedOr(new string[] { Constants.PropertyAlias.NodeTypeAlias }, documentTypes.ToArray());
            }

            if (searchGroups?.Any() == true)
            {
                //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.ToArray());
                }
            }

            var compileQuery = queryNodes.Compile();

            //return the results of the search
            return(searchManager.Search(compileQuery));
        }