private static void AddSortArgument(ISearchCriteria criteria, ArgMap arguments)
        {
            if (criteria.Sort == null)
            {
                return;
            }

            var searchSortFields = criteria.Sort.GetSort();

            if (searchSortFields == null || searchSortFields.Length == 0)
            {
                return;
            }

            var builder = new StringBuilder();

            foreach (var field in searchSortFields)
            {
                if (builder.Length > 0)
                {
                    builder.Append(",");
                }
                builder.Append(field.FieldName).Append(" ").Append(field.IsDescending ? "desc" : "asc");
            }
            arguments.Add("sort_by", builder.ToString());
        }
 private void AddCatalogEntrySearchCriteria(ISearchCriteria criteria, IList <Filter> filters, ArgMap arguments)
 {
     if (criteria is CatalogEntrySearchCriteria)
     {
         var c = criteria as CatalogEntrySearchCriteria;
         AddOrFilter(filters, c.CatalogNames, "_catalog");
         AddOrFilter(filters, c.CatalogNodes, "_node");
         AddOrFilter(filters, c.Outlines, "_outline");
         AddOrFilter(filters, c.SearchIndex, "_metaclass");
         AddOrFilter(filters, c.ClassTypes, "_classtype");
         const string year0           = "0.0";
         const string yearFarInFuture = "99999999999999999";
         filters.Add(FilterBuilder.Range("startdate", year0, ConvertToTimestamp(c.StartDate).ToString(CultureInfo.InvariantCulture), false, true));
         filters.Add(FilterBuilder.Range("enddate", ConvertToTimestamp(c.EndDate).ToString(CultureInfo.InvariantCulture), yearFarInFuture, true, false));
         var searchAttributes = SearchAttributes();
         if (!(string.IsNullOrEmpty(c.SearchPhrase) || string.IsNullOrEmpty(searchAttributes)))
         {
             arguments.Add("search_phrase", c.SearchPhrase);
             arguments.Add("search_attributes", searchAttributes);
         }
     }
 }
        private PanelContent PerformQuery(ISearchCriteria criteria)
        {
            IList <Filter> filters = new List <Filter> {
                FilterBuilder.Attribute("locale_filter", criteria.Locale)
            };
            var arguments = new ArgMap();

            AddFilterCriteria(criteria, filters);
            AddCatalogEntrySearchCriteria(criteria, filters, arguments);
            AddSortArgument(criteria, arguments);
            AddFacetAttributes(arguments);

            var filter = filters.Count == 1 ? filters[0] : FilterBuilder.And(filters.ToArray());

            arguments.Add("filter", filter);
            arguments.Add("window_first", criteria.StartingRecord + 1);
            arguments.Add("window_last", criteria.RecordsToRetrieve + criteria.StartingRecord);

            var p = Util.ESales.Connector.Session(Util.Session.Key).Panel("/commerce-standard-search");

            return(p.RetrieveContent(arguments));
        }
        private void AddFacetAttributes(ArgMap arguments)
        {
            var builder = new StringBuilder();

            foreach (var facetAttribute in _configuration.FacetAttributes)
            {
                if (builder.Length > 0)
                {
                    builder.Append(",");
                }
                builder.Append(facetAttribute.Name + "__facet");
            }
            arguments.Add("filter_attributes", builder.ToString());
        }