Exemple #1
0
        public ActionResult Index(string q)
        {
            var model = GetModel <CategoriesPageViewModel>(CurrentPage);

            model.IsSearchMode = !string.IsNullOrEmpty(q);

            if (model.IsSearchMode)
            {
                if (ExamineManager.Instance.TryGetIndex("ExternalIndex", out IIndex index))
                {
                    ISearcher searcher = index.GetSearcher();
                    var       fields   = new List <string> {
                        "nodeName", "content", "pageContent", "bodyText"
                    };

                    ISearchResults results = searcher.CreateQuery("content").GroupedOr(fields, q).Execute();
                    model.SearchResults = results.Select(result => new PageViewModel(result, model.TenantUid, Umbraco)).Where(x => !string.IsNullOrEmpty(x.Title));
                    //model.SearchResults = results.Select(result => new PageViewModel(result, Umbraco));
                }
            }
            else
            {
                model.Categories = CurrentPage.Children.Select(content => new ArticleCategoryViewModel(content));
            }

            return(CurrentTemplate(model));
        }
        /// <summary>
        /// Creates a query with predefined criteria for published content
        /// </summary>
        public static IBooleanOperation CreatePublishedQuery(this ISearcher searcher, string category = null, BooleanOperation defaultOperation = BooleanOperation.And)
        {
            var query = searcher
                        .CreateQuery(category, defaultOperation)
                        .IsPublished();

            query.AndNot(x => x.IsVisble());

            query.AndNot(x => x.HasTemplate());

            return(query);
        }
Exemple #3
0
 /// <summary>
 /// Creates a new query from the specified <paramref name="searcher"/> and <paramref name="options"/>.
 /// </summary>
 /// <param name="searcher">The searcher.</param>
 /// <param name="options">The options for the search.</param>
 /// <returns>An instance of <see cref="IQuery"/>.</returns>
 protected virtual IQuery CreateQuery(ISearcher searcher, ISearchOptions options)
 {
     return(searcher.CreateQuery());
 }