public JsonResult Search(FilterOptions options)
        {
            var searchTerm = options != null && options.Filter != null && options.Filter.Filters != null ? options.Filter.Filters.FirstOrDefault() : null;

            if (searchTerm != null)
            {
                this.ViewBag.SearchTerm = searchTerm.Value;
            }

            return this.Json(this._searchService.Search(options));
        }
 public void SearchShouldReturnASearchResultForAllEntitiesMatchingTheFilter()
 {
     var service = new SearchService(_sourceMock.Object);
     var options = new FilterOptions();
     options.Filter = new Filter();
     options.Filter.Logic = FilterType.Or;
     options.Filter.Filters = new List<FilterField>()
     {
         new FilterField(FilterFieldOperator.Contains, "Name", "My"),
         new FilterField(FilterFieldOperator.Contains, "Body", "My"),
         new FilterField(FilterFieldOperator.Contains, "Description", "My")
     };
     var result = service.Search(options);
     Assert.IsNotNull(result);
     Assert.AreEqual(3, result.Data.Select(d => d.TypeName).Distinct().Count());
     Assert.AreEqual(3, result.Data.Count);
 }
Esempio n. 3
0
 /// <summary>
 /// Creates a data records wrapper for an enumerable.
 /// </summary>
 /// <param name="enumerable">The enumerable</param>
 /// <param name="options">The filter options used to get the data</param>
 /// <returns>The data records wrapper</returns>
 public static DataRecords DataRecords(this IEnumerable enumerable, FilterOptions options)
 {
     return new DataRecords(enumerable, options);
 }
        public SearchResult Search(FilterOptions options)
        {
            if (options == null)
            {
                options = new FilterOptions();
            }

            var culture = StrixPlatform.CurrentCultureCode;
            var result = new SearchResult();
            result.Locators = PageRegistration.ContentLocators;
            var typesTosearch = EntityHelper.EntityTypes.Where(e => e.Name != typeof(MailContentTemplate).FullName && e.Name != typeof(MailContent).FullName).ToList();
            var itemsToSkip = options.PageSize == 1 ? 0 : options.PageSize * (options.Page - 1);

            // Todo: make configurable.
            var itemsToGet = options.PageSize == 0 ? 100 : options.PageSize;

            foreach (var entityType in typesTosearch)
            {
                var entryType = EntityHelper.GetEntityType(entityType.Id);
                var query = this._source.Query(entryType).Where("Culture.Equals(@0) AND IsCurrentVersion", culture);

                var queryEvent = new PrepareQueryEvent(query, options, false);
                StrixPlatform.RaiseEvent(queryEvent);
                query = queryEvent.Query;

                if (itemsToGet > 0)
                {
                    if (entryType.Equals(typeof(Html)))
                    {
                        var htmlTypeName = typeof(Html).FullName;
                        var htmlLocators = PageRegistration.ContentLocators.Where(l => l.ContentTypeName == htmlTypeName);
                        var htmlQuery = query.Cast<Html>().Select(h => new { Name = h.Name, Url = h.Entity.Url }).ToList().Select(h => new { Name = h.Name, Url = htmlLocators.Where(l => l.ContentUrl.ToLower() == h.Url.ToLower()).Select(l => l.PageUrl).FirstOrDefault() });
                        query = htmlQuery.GroupBy(h => h.Url).Select(h => new Html { Name = h.Select(i => i.Url.ToTitleCase()).First(), Entity = new PlatformEntity { Id = Guid.Empty, Url = h.Select(i => i.Url).First() } }).AsQueryable();
                    }

                    int addedItems = 0;
                    var entries = query.Skip(itemsToSkip).Take(itemsToGet).Select<SearchItem>("new (Entity.Id, Name, Entity.Url)").ToList();

                    foreach (var entry in entries)
                    {
                        entry.TypeName = entryType.FullName;
                        result.Data.Add(entry);
                        addedItems++;
                    }

                    options.Total = 0;
                    itemsToGet -= addedItems;
                }

                var queryCount = query.Count();
                itemsToSkip -= queryCount;

                if (itemsToSkip < 0)
                {
                    itemsToSkip = 0;
                }

                result.Total += queryCount;
            }

            return result;
        }
 public JsonResult List(FilterOptions options)
 {
     var entries = this._dataService.ErrorLogEntries(options);
     return this.Json(entries.DataRecords(options));
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="PrepareQueryEvent"/> class.
 /// </summary>
 /// <param name="query">The current query</param>
 /// <param name="filter">The current filter options</param>
 /// <param name="page">True if the query results should be paged, false otherwise</param>
 public PrepareQueryEvent(IQueryable query, FilterOptions filter, bool page)
 {
     this.Query = query;
     this.Filter = filter;
     this.Page = page;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="PrepareQueryEvent"/> class.
 /// </summary>
 /// <param name="query">The current query</param>
 /// <param name="filter">The current filter options</param>
 public PrepareQueryEvent(IQueryable query, FilterOptions filter) : this(query, filter, true)
 {
 }
 public IEnumerable List(FilterOptions filter)
 {
     var groupId = ApplicationHelper.GetMainGroupId(this._dataSource);
     return this._groupManager.Query().Where(g => g.Id != groupId).Filter(filter).Map<GroupListModel>().ToList();
 }
 public IEnumerable List(FilterOptions filter)
 {
     return this._manager.VocabularyQuery().Filter(filter).Map<VocabularyViewModel>().ToList();
 }
 public IList<TermViewModel> GetTagList(FilterOptions filter, string vocabularyName)
 {
     return this._manager.TagQueryForVocabulary(vocabularyName, null).Filter(filter).Map<TermViewModel>().ToList();
 }
 public IList<TermViewModel> GetTagList(FilterOptions filter, Guid vocabularyId)
 {
     return this._manager.TagQueryForVocabulary(vocabularyId).Filter(filter).Map<TermViewModel>().ToList();
 }
Esempio n. 12
0
 public DataRecords(IEnumerable data, FilterOptions options)
 {
     this.Data = data;
     this.Options = options;
     this.Total = options != null ? options.Total : data.Length();
 }
 public IEnumerable List(FilterOptions filter)
 {
     return this._roleManager.Query().Where(r => r.Name.ToLower() != Resources.DefaultValues.PermissionSetName.ToLower()).Filter(filter).Select(r => new RoleViewModel { Id = r.Id, Name = r.Name }).ToList();
 }