private void ApplyFilter(FilterContext context)
 {
     var tryGetCurrentContentId = TryGetCurrentContentId();
     if (tryGetCurrentContentId != -1) {
         context.Query = context.Query.Where(factory => factory.ContentItem(), exp1 => exp1.Not(exp2 => exp2.Eq("Id", tryGetCurrentContentId)));
     }
 }
 public void ApplyFilter(FilterContext context)
 {
     var contentTypes = Convert.ToString(context.State.ContentTypes);
     if (!String.IsNullOrEmpty(contentTypes)) {
         context.Query = context.Query.ForType(contentTypes.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries));
     }
 }
示例#3
0
 public void ApplyFilter(FilterContext context) {
     var contentPartRecords = (string)context.State.ContentPartRecords;
     if (!String.IsNullOrEmpty(contentPartRecords)) {
         var contentParts = contentPartRecords.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
         context.Query = context.Query.Include(contentParts);
     }
 }
        public void ApplyFilter(FilterContext context)
        {
            if (string.IsNullOrEmpty((string)context.State.Labels) || context.State.GraphName == null) return;

            var graphContext = new GraphContext { Name = context.State.GraphName };
            var graph = _associativyServices.GraphManager.FindGraph(graphContext);
            if (graph == null) return;

            var labelsArray = AssociativyFrontendSearchFormPart.LabelsToArray((string)context.State.Labels);
            var nodes = graph.Services.NodeManager.GetByLabelQuery(labelsArray).List();

            if (!nodes.Any())
            {
                // No result
                context.Query.Where(a => a.ContentItem(), p => p.In("Id", new[] { -1 }));
                return;
            }

            var associations = graph.Services.Mind.MakeAssociations(nodes, MindSettings.Default).ToGraph();
            var vertices = associations.Vertices.ToList();
            if (context.State.IncludeSearched == null)
            {
                foreach (var nodeId in nodes.Select(item => item.Id))
                {
                    vertices.Remove(nodeId);
                }
            }

            if (vertices.Count == 0) vertices.Add(-1); // No result if no associations are found

            context.Query.WhereIdIn(vertices);
        }
 public override void ApplyFilter(FilterContext context, string storageName, Type storageType, ContentPartDefinition part, ContentPartFieldDefinition field) {
     var op = (OptionSetOperator) Enum.Parse(typeof (OptionSetOperator), (string) context.State.Operator);
     string value = context.State.Value;
     var valueArr = value != null
         ? value.Split('&').Select(int.Parse).ToArray()
         : new[] {0};
     switch (op) {
         case OptionSetOperator.MatchesAny:
             Action<IAliasFactory> selectorAny = alias => alias.ContentPartRecord<OptionItemContainerPartRecord>().Property("OptionItems", "opits").Property("OptionItemRecord", "opcpr");
             Action<IHqlExpressionFactory> filterAny = x => x.InG("Id", valueArr);
             context.Query.Where(selectorAny, filterAny);
             break;
         case OptionSetOperator.MatchesAll:
             foreach (var id in valueArr) {
                 var optionId = id;
                 Action<IAliasFactory> selectorAll =
                     alias => alias.ContentPartRecord<OptionItemContainerPartRecord>().Property("OptionItems", "opit" + optionId);
                 Action<IHqlExpressionFactory> filterAll = x => x.Eq("OptionItemRecord.Id", optionId);
                 context.Query.Where(selectorAll, filterAll);
             }
             break;
         case OptionSetOperator.NotMatchesAny:
             Action<IAliasFactory> selectorNotAny = alias => alias.ContentPartRecord<OptionItemContainerPartRecord>().Property("OptionItems", "opits").Property("OptionItemRecord", "opcpr");
             Action<IHqlExpressionFactory> filterNotAny = x => x.Not(y => y.InG("Id", valueArr));
             context.Query.Where(selectorNotAny, filterNotAny);
             break;
     }
 }
        private void ApplyFilter(FilterContext context)
        {

            // Set the Query property of the context parameter to any IHqlQuery. In our case, we use a default query
            // and narrow it down by joining with the ProductPartRecord.
            context.Query = context.Query.Join(x => x.ContentPartRecord(typeof(ProductRecord)));
        }
        public LocalizedString DisplayFilter(FilterContext context)
        {
            var taxonomyFieldExpression = (string)context.State.TaxonomyFieldExpression;

            return String.IsNullOrEmpty(taxonomyFieldExpression)
                ? T("All content items")
                : T("Related content items whose {0} field share one or more terms with the current content item", taxonomyFieldExpression);
        }
        public void ApplyFilter(FilterContext context)
        {
            var workContext = _workContextAccessor.GetContext();

            var termIds = workContext.GetState<string>("ContentTermsIds");

            if (!String.IsNullOrEmpty(termIds))
            {
                var ids = termIds.Split(new[] { ',' }).Select(Int32.Parse).ToArray();

                if (ids.Length == 0)
                {
                    return;
                }

                int op = Convert.ToInt32(context.State.Operator);

                var terms = ids.Select(_taxonomyService.GetTerm).ToList();
                var allChildren = new List<TermPart>();
                foreach (var term in terms)
                {
                    allChildren.AddRange(_taxonomyService.GetChildren(term));
                    allChildren.Add(term);
                }

                allChildren = allChildren.Distinct().ToList();

                var allIds = allChildren.Select(x => x.Id).ToList();

                switch (op)
                {
                    case 0:
                        // is one of
                        Action<IAliasFactory> s = alias => alias.ContentPartRecord<TermsPartRecord>().Property("Terms", "terms").Property("TermRecord", "termRecord");
                        Action<IHqlExpressionFactory> f = x => x.InG("Id", allIds);
                        context.Query.Where(s, f);
                        break;
                    case 1:
                        // is all of
                        foreach (var id in allIds)
                        {
                            var termId = id;
                            Action<IAliasFactory> selector =
                                alias => alias.ContentPartRecord<TermsPartRecord>().Property("Terms", "terms" + termId);
                            Action<IHqlExpressionFactory> filter = x => x.Eq("TermRecord.Id", termId);
                            context.Query.Where(selector, filter);
                        }
                        break;
                }
            }
            else {
                // Don't return any result if content has no term
                Action<IAliasFactory> selector =
                    alias => alias.ContentPartRecord<TermsPartRecord>().Property("Terms", "noterm");
                Action<IHqlExpressionFactory> filter = x => x.Eq("TermRecord.Id", -1);
                context.Query.Where(selector, filter);
            }
        }
        public LocalizedString DisplayFilter(FilterContext context)
        {
            var contentItemIds = (string)context.State.ContentItemIds;

            if (String.IsNullOrEmpty(contentItemIds))
                return T("Exclude none");
            
            return T("Exclude {0}", contentItemIds);
        }
示例#10
0
        public LocalizedString DisplayFilter(FilterContext context) {
            string contenttypes = context.State.ContentTypes;

            if (String.IsNullOrEmpty(contenttypes)) {
                return T("Any content item");
            }

            return T("Content with type {0}", contenttypes);
        }
示例#11
0
        public LocalizedString DisplayFilter(FilterContext context) {
            string contentpartrecords = context.State.ContentPartRecords;

            if (String.IsNullOrEmpty(contentpartrecords)) {
                return T("No content part record");
            }

            return T("Eager fetch part records {0}", contentpartrecords);
        }
        public void ApplyFilter(FilterContext context)
        {
            if (context.State.ContentIds != null)
            {
                var ids = (string)_tokenizer.Replace(context.State.ContentIds, null, new ReplaceOptions { Encoding = ReplaceOptions.NoEncode });
                var idsArray = ids.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                idsArray = (from p in idsArray select p.Trim()).ToArray();

                context.Query.Where(a => a.ContentPartRecord<CommonPartRecord>(), p => p.In("Id", idsArray));
            }
        }
示例#13
0
        public void ApplyFilter(FilterContext context)
        {
            if (context.State.ContentIds == null) return;

            var ids = ((string)context.State.ContentIds).Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
            var idsArray = (from p in ids select int.Parse(p.Trim())).ToArray();

            if (idsArray.Length == 0) return;

            context.Query.WhereIdIn(idsArray);
        }
        public void ApplyFilter(FilterContext context)
        {
            var contentItemIds = (string)context.State.ContentItemIds;

            if (String.IsNullOrEmpty(contentItemIds))
                return;
            
            var ids = contentItemIds.Split(',').Select(Int32.Parse).ToArray();
            
            foreach (var id in ids) {
                context.Query.Where(alias => alias.ContentItem(), filter => filter.Not(n => n.Eq("Id", id)));
            }
        }
        public void ApplyFilter(FilterContext context)
        {
            if (string.IsNullOrEmpty((string)context.State.ItemId) || context.State.GraphName == null) return;

            var graphContext = new GraphContext { Name = context.State.GraphName };
            var graph = _graphManager.FindGraph(graphContext);
            if (graph == null) return;

            var neighbourIds = graph.Services.ConnectionManager.GetNeighbourIds(int.Parse((string)context.State.ItemId)).ToArray();

            if (neighbourIds.Length == 0) neighbourIds = new[] { -1 }; // No result if no neighbours are found

            context.Query.WhereIdIn(neighbourIds);
        }
示例#16
0
        public void ApplyFilter(FilterContext context, IFieldTypeEditor fieldTypeEditor, string storageName, Type storageType, ContentPartDefinition part, ContentPartFieldDefinition field) {
            var propertyName = String.Join(".", part.Name, field.Name, storageName ?? "");

            // use an alias with the join so that two filters on the same Field Type wont collide
            var relationship = fieldTypeEditor.GetFilterRelationship(propertyName.ToSafeName());

            // generate the predicate based on the editor which has been used
            Action<IHqlExpressionFactory> predicate = fieldTypeEditor.GetFilterPredicate(context.State);

            // combines the predicate with a filter on the specific property name of the storage, as implemented in FieldIndexService
            Action<IHqlExpressionFactory> andPredicate = x => x.And(y => y.Eq("PropertyName", propertyName), predicate);

            // apply where clause
            context.Query = context.Query.Where(relationship, andPredicate);
        }
        public void ApplyFilter(FilterContext context)
        {
            var termIds = (string)context.State.TermIds;

            if (String.IsNullOrEmpty(termIds))
                return;

            var ids = termIds.Split(',').Select(Int32.Parse).ToArray();

            if (ids.Length == 0)
                return;

            int op = Convert.ToInt32(context.State.Operator);
            var terms = ids.Select(mTaxonomyService.GetTerm).ToList();
            var allChildren = new List<TermPart>();

            foreach (var term in terms)
            {
                allChildren.AddRange(mTaxonomyService.GetChildren(term));
                allChildren.Add(term);
            }

            allChildren = allChildren.Distinct().ToList();

            var allIds = allChildren.Select(x => x.Id).ToList();

            switch (op)
            {
                case 0: // is one of
                    // Unique alias so we always get a unique join everytime so can have > 1 HasTerms filter on a query.
                    Action<IAliasFactory> s = alias => alias.ContentPartRecord<TermsPartRecord>().Property("Terms", "terms" + mTermsFilterId++);
                    Action<IHqlExpressionFactory> f = x => x.InG("TermRecord.Id", allIds);
                    context.Query.Where(s, f);
                    break;
                case 1: // is all of
                    foreach (var id in allIds)
                    {
                        var termId = id;
                        Action<IAliasFactory> selector =
                            alias => alias.ContentPartRecord<TermsPartRecord>().Property("Terms", "terms" + termId);
                        Action<IHqlExpressionFactory> filter = x => x.Eq("TermRecord.Id", termId);
                        context.Query.Where(selector, filter);
                    }
                    break;
            }
        }
        public LocalizedString DisplayFilter(FilterContext context)
        {
            var terms = (string)context.State.TermIds;

            if (String.IsNullOrEmpty(terms))
                return T("Any term");

            int op = Convert.ToInt32(context.State.Operator);
            switch (op)
            {
                case 0:
                    return T("Categorized with one of {0}", terms);

                case 1:
                    return T("Categorized with all of {0}", terms);
            }

            return T("Categorized with {0}", terms);
        }
        public void ApplyFilter(FilterContext context)
        {
            var taxonomyFieldExpression = (string)context.State.TaxonomyFieldExpression;

            if (String.IsNullOrWhiteSpace(taxonomyFieldExpression))
                return;

            var expressionParts = taxonomyFieldExpression.Split('.').Select(x => x.Trim()).ToArray();

            if (!expressionParts.Any())
                return;

            var currentContentItem = mCurrentContentAccessor.CurrentContentItem;
            var taxonomyFieldQuery = expressionParts.Length == 1
                ? from part in currentContentItem.Parts from field in part.Fields where field.FieldDefinition.Name == typeof(TaxonomyField).Name && field.Name == expressionParts[0] select field
                : from part in currentContentItem.Parts where part.PartDefinition.Name == expressionParts[0] select part.Fields.FirstOrDefault(x => x.Name == expressionParts[1]);

            var taxonomyField = taxonomyFieldQuery.FirstOrDefault() as TaxonomyField;

            if (taxonomyField == null)
                return;

            var terms = taxonomyField.Terms.ToArray();

            if (!terms.Any())
                return;

            // Expand terms.
            var allChildren = ExpandTerms(terms).Distinct().ToList();
            var allIds = allChildren.Select(x => x.Id).ToList();

            // All content items that share any of the terms of the current content item.
            Action<IAliasFactory> s = alias => alias.ContentPartRecord<TermsPartRecord>().Property("Terms", "relatedterms" + currentContentItem.Id);
            Action<IHqlExpressionFactory> f = x => x.InG("TermRecord.Id", allIds);

            // Exclude the current content item from the results.
            context.Query.Where(alias => alias.ContentItem(), filter => filter.Not(n => n.Eq("Id", currentContentItem.Id)));

            context.Query.Where(s, f);
        }
 public LocalizedString DisplayFilter(FilterContext context)
 {
     return T("Content items having either ids: " + context.State.ContentIds);
 }
示例#21
0
 public LocalizedString DisplayFilter(FilterContext context)
 {
     return T("Content items matched by the search query {0} in the search index \"{1}\".", context.State.SearchQuery, context.State.Index);
 }
示例#22
0
        public IEnumerable<IHqlQuery> GetContentQueries(QueryPartRecord queryRecord, IEnumerable<SortCriterionRecord> sortCriteria) {
            var availableFilters = DescribeFilters().ToList();
            var availableSortCriteria = DescribeSortCriteria().ToList();

            // pre-executing all groups 
            foreach (var group in queryRecord.FilterGroups) {

                var contentQuery = _contentManager.HqlQuery().ForVersion(VersionOptions.Published);

                // iterate over each filter to apply the alterations to the query object
                foreach (var filter in group.Filters) {
                    var tokenizedState = _tokenizer.Replace(filter.State, new Dictionary<string, object>());
                    var filterContext = new FilterContext {
                        Query = contentQuery,
                        State = FormParametersHelper.ToDynamic(tokenizedState)
                    };

                    string category = filter.Category;
                    string type = filter.Type;

                    // look for the specific filter component
                    var descriptor = availableFilters
                        .SelectMany(x => x.Descriptors)
                        .FirstOrDefault(x => x.Category == category && x.Type == type);

                    // ignore unfound descriptors
                    if (descriptor == null) {
                        continue;
                    }

                    // apply alteration
                    descriptor.Filter(filterContext);

                    contentQuery = filterContext.Query;
                }

                // iterate over each sort criteria to apply the alterations to the query object
                foreach (var sortCriterion in sortCriteria) {
                    var sortCriterionContext = new SortCriterionContext {
                        Query = contentQuery,
                        State = FormParametersHelper.ToDynamic(sortCriterion.State)
                    };

                    string category = sortCriterion.Category;
                    string type = sortCriterion.Type;

                    // look for the specific filter component
                    var descriptor = availableSortCriteria
                        .SelectMany(x => x.Descriptors)
                        .FirstOrDefault(x => x.Category == category && x.Type == type);

                    // ignore unfound descriptors
                    if (descriptor == null) {
                        continue;
                    }

                    // apply alteration
                    descriptor.Sort(sortCriterionContext);

                    contentQuery = sortCriterionContext.Query;
                }


                yield return contentQuery;
            }            
        }
 private LocalizedString DisplayFilter(FilterContext context)
 {
     return T("Content with ProductPart");
 }
 private void ApplyFilter(FilterContext context)
 {
     context.Query = context.Query.Join(x => x.ContentPartRecord(typeof(ProductPartRecord)));
 }
示例#25
0
        public LocalizedString DisplayFilter(FilterContext context, ContentPartDefinition part, ContentPartFieldDefinition fieldDefinition) {
            string op = context.State.Operator;
            string value = context.State.Value;

            return T("Field {0} {1} \"{2}\"", fieldDefinition.Name, op, value);
        }
 public LocalizedString DisplayFilter(FilterContext context)
 {
     return T("Content items matched by the search query \"{0}\" in the graph \"{1}\"", context.State.Labels, context.State.GraphName);
 }
示例#27
0
        public void ApplyFilter(FilterContext context)
        {
            string query = context.State.SearchQuery;

            if (string.IsNullOrEmpty(query)) return;

            var settings = _siteService.GetSiteSettings().As<SearchSettingsPart>();
            string index = context.State.Index;

            var hitCountLimit = 0;
            int.TryParse(context.State.HitCountLimit.ToString(), out hitCountLimit);

            var hits = _searchService.Query(query, 0, hitCountLimit != 0 ? new Nullable<int>(hitCountLimit) : null,
                                            settings.FilterCulture, index, SearchSettingsHelper.GetSearchFields(settings),
                                            hit => hit);
            if (hits.Any())
            {
                context.Query.WhereIdIn(hits.Select(hit => hit.ContentItemId));
            }
            else
            {
                context.Query.WhereIdIn(new[] { 0 });
            }
        }
示例#28
0
        public LocalizedString DisplayFilter(FilterContext context)
        {
            if (String.IsNullOrEmpty(context.State.ShoutboxWidget))
            {
                return T("Any Shoutbox message");
            }

            int widgetId = int.Parse(context.State.ShoutboxWidget);
            return T("Messages from the Shoutbox \"{0}\"", _contentManager.Get<WidgetPart>(widgetId).Title);
        }
示例#29
0
        public void ApplyFilter(FilterContext context)
        {
            context.Query.ForType("ShoutboxMessage");

            if (String.IsNullOrEmpty(context.State.ShoutboxWidget)) return;

            context.Query.Where(x => x.ContentPartRecord<CommonPartRecord>(), x => x.Eq("Container.Id", context.State.ShoutboxWidget));
        }
 private LocalizedString DisplayFilter(FilterContext context)
 {
     return T("Content with unequal Id");
 }