/// <summary>
        /// Get paged search results.
        /// </summary>
        /// <param name="queryText">The query to search for.</param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="indexDir"></param>
        /// <returns></returns>
        public SearchResultCollection GetSearchResults(string queryText, int pageIndex, int pageSize, string indexDir)
        {
            IndexQuery query         = new IndexQuery(indexDir);
            Hashtable  keywordFilter = new Hashtable();

            keywordFilter.Add("site", Section.Node.Site.Name);
            SearchResultCollection nonFilteredResults = query.Find(queryText, keywordFilter, pageIndex, pageSize);

            // Filter results where the current user doesn't have access to.
            return(FilterResults(nonFilteredResults));
        }
Example #2
0
        public SearchResultCollection FindContent(string queryText, IList<string> categoryNames, int pageIndex, int pageSize)
        {
            // Check queryText for invalid fields
            if (queryText.Contains("viewroleid:"))
            {
                throw new SearchException("Don't try to mess with security!");
            }

            ICuyahogaContext cuyahogaContext = this._cuyahogaContextProvider.GetContext();
            User currentUser = cuyahogaContext.CurrentUser;

            IList<Role> roles;
            if (currentUser != null)
            {
                roles = currentUser.Roles;
            }
            else
            {
                // Assume anonymous access, get all roles that have only anonymous access.
                roles = this._userDao.GetAllRolesBySite(cuyahogaContext.CurrentSite).Where(role => role.IsAnonymousRole).ToList();
            }
            IList<int> roleIds = roles.Select(role => role.Id).ToList();
            IndexQuery query = new IndexQuery(GetIndexDirectory());

            try
            {
                return query.Find(queryText, categoryNames, pageIndex, pageSize, roleIds);
            }
            catch (ParseException ex)
            {
                Logger.Error(string.Format("Invalid query: {0}", queryText), ex);
                throw new SearchException("Invalid search query", ex);
            }
        }