Ejemplo n.º 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));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// queries the Lucene index to get all members with the supplied partyGuid
        /// </summary>
        /// <param name="members">the Umbraco MembershipHelper</param>
        /// <param name="partyGuid">Guid identifying a specific party</param>
        /// <returns>a collection of PartyHost / PartyGuest associated with a specific party</returns>
        public static IEnumerable <IPartier> GetPartiers(this MembershipHelper members, Guid partyGuid)
        {
            BaseSearchProvider searchProvider = ExamineManager.Instance.SearchProviderCollection["InternalMemberSearcher"];
            ISearchCriteria    searchCriteria = searchProvider.CreateSearchCriteria(IndexTypes.Member).Field("partyGuid", partyGuid.ToString()).Compile();
            ISearchResults     searchResults  = searchProvider.Search(searchCriteria);

            return(searchResults.Select(x => (IPartier)members.GetById(x.Id)));
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Builds a <see cref="QueryResultDisplay"/>
 /// </summary>
 /// <param name="results">
 /// The results.
 /// </param>
 /// <param name="currentPage">
 /// The current page.
 /// </param>
 /// <param name="itemsPerPage">
 /// The items per page.
 /// </param>
 /// <returns>
 /// The <see cref="QueryResultDisplay"/>.
 /// </returns>
 public QueryResultDisplay BuildQueryResult(ISearchResults results, long currentPage, long itemsPerPage)
 {
     return(new QueryResultDisplay()
     {
         Items = results.Select(_map).Skip((int)((currentPage - 1) * itemsPerPage)).Take((int)itemsPerPage),
         CurrentPage = currentPage,
         ItemsPerPage = itemsPerPage,
         TotalPages = ((results.Count() - 1) / itemsPerPage) + 1,
         TotalItems = results.Count()
     });
 }
Ejemplo n.º 4
0
        public IEnumerable <T> GetAll <T>(string doctypeAlias, int?maxResults = null, bool inCurrentSite = true)
            where T : class, IPublishedContent
        {
            IBooleanOperation operation = Searcher.CreateSearchCriteria().NodeTypeAlias(doctypeAlias);

            if (inCurrentSite)
            {
                int?homepageId = UmbracoContext.Current?.PublishedContentRequest?.PublishedContent?.AncestorOrSelf <Home>()?.Id;
                if (homepageId != null)
                {
                    operation.And().Field("@homepageId", homepageId.ToString());
                }
            }

            ISearchCriteria criteria      = operation.Compile();
            ISearchResults  searchResults = maxResults.HasValue ? Searcher.Search(criteria, maxResults.Value) : Searcher.Search(criteria);

            return(searchResults.Select(sr => UmbracoHelper.TypedContent(sr.Id) as T));
        }
Ejemplo n.º 5
0
        public static PartyHost GetPartyHost(this MembershipHelper members, string partyUrlIdentifier)
        {
            BaseSearchProvider searchProvider = ExamineManager.Instance.SearchProviderCollection["InternalMemberSearcher"];
            ISearchCriteria    searchCriteria = searchProvider.CreateSearchCriteria(IndexTypes.Member).Field("partyUrlIdentifier", partyUrlIdentifier).Compile();
            ISearchResults     searchResults  = searchProvider.Search(searchCriteria);

            return(searchResults.Select(x => (PartyHost)members.GetById(x.Id)).SingleOrDefault());

            //// WARNING: hits db
            //IMember partyHost = ApplicationContext
            //                        .Current
            //                        .Services
            //                        .MemberService
            //                        .GetMembersByMemberType(PartyHost.Alias)
            //                        .SingleOrDefault(x => x.GetValue<string>(PartyHost.PartyUrlIdentifierAlias).ToLower() == partyUrlIdentifier.ToLower());

            //if (partyHost != null)
            //{
            //    return new PartyHost(members.GetByUsername(partyHost.Username));
            //}

            //return null;
        }
 /// <summary>
 /// Get the results converted to the given type
 /// </summary>
 public static IEnumerable <T> GetResults <T>(this ISearchResults searchResults)
 {
     return(searchResults
            .Select(x => ConvertValue <T>(x))
            .Where(x => x != null));
 }