Esempio n. 1
0
        private IClient CreateClient(ISearchConfiguration config)
        {
            ProviderClient providerClient = new ProviderClient(config);

            providerClient.Conventions.ContractResolver.ContractInterceptors.Add((IInterceptContract) new IncludeTypeNameInDictionaryKeyFieldNameConvention());
            return((IClient)providerClient);
        }
Esempio n. 2
0
        /// <summary>Gets the configuration.</summary>
        /// <param name="client">The client.</param>
        /// <returns></returns>
        /// <exception cref="T:System.NotSupportedException">Find Provider for Commerce extensions will only work on searches against the provider-created client.</exception>
        public static ISearchConfiguration GetConfiguration(this IClient client)
        {
            ProviderClient providerClient = client as ProviderClient;

            if (providerClient == null)
            {
                throw new NotSupportedException("Find Provider for Commerce extensions will only work on searches against the provider-created client.");
            }
            return(providerClient.ProviderConfiguration);
        }
Esempio n. 3
0
        private void SendOperations(Dictionary <int, FindDocument> operations)
        {
            ProviderClient      client           = (ProviderClient)this.Client;
            List <int>          intList          = new List <int>(operations.Count);
            List <FindDocument> findDocumentList = new List <FindDocument>(operations.Count);

            foreach (KeyValuePair <int, FindDocument> operation in operations)
            {
                if (operation.Value == null)
                {
                    intList.Add(operation.Key);
                }
                else
                {
                    findDocumentList.Add(operation.Value);
                }
            }
            if (intList.Count > 0)
            {
                FilterBuilder <FindDocument> filter = client.BuildFilter <FindDocument>();
                foreach (int num in intList)
                {
                    int documentId = num;
                    filter = filter.Or((Expression <Func <FindDocument, Filter> >)(doc => doc.CatalogEntryId.Match(documentId)));
                }
                client.Delete <FindDocument>((Expression <Func <FindDocument, Filter> >)(_ => (Filter)filter));
            }
            if (findDocumentList.Count <= 0)
            {
                return;
            }
            BulkResultItem bulkResultItem = client.Index((IEnumerable)findDocumentList).Items.FirstOrDefault <BulkResultItem>((Func <BulkResultItem, bool>)(r => !r.Ok));

            if (bulkResultItem != null)
            {
                throw new Exception(string.Format("Indexing error: {0}", (object)bulkResultItem.Error));
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="T:EPiServer.Commerce.FindSearchProvider.FindSearchQueryBuilder" /> class.
        /// </summary>
        /// <param name="client">The client.</param>
        /// <param name="criteria">The criteria.</param>
        /// <param name="languageOption">The language option.</param>
        /// <exception cref="T:System.InvalidOperationException">The Find search query builder only works with clients created by the provider.</exception>
        public FindSearchQueryBuilder(IClient client, ISearchCriteria criteria, QueryCultureOption languageOption)
        {
            ProviderClient providerClient = client as ProviderClient;

            if (providerClient == null)
            {
                throw new InvalidOperationException("The Find search query builder only works with clients created by the provider.");
            }
            ISearchConfiguration       providerConfiguration = providerClient.ProviderConfiguration;
            Language                   language  = (Language)null;
            ITypeSearch <FindDocument> search1   = criteria.IgnoreFilterOnLanguage || !FindSearchQueryBuilder._providerLanguages.TryGetValue(criteria.Locale, out language) ? providerClient.Search <FindDocument>() : providerClient.Search <FindDocument>(language);
            CatalogEntrySearchCriteria criteria1 = criteria as CatalogEntrySearchCriteria;

            if (criteria1 != null)
            {
                ITypeSearch <FindDocument> search2;
                if (criteria.IgnoreFilterOnLanguage)
                {
                    search2 = search1.ForDefaultFields(criteria1.SearchPhrase, string.Empty);
                }
                else
                {
                    ITypeSearch <FindDocument> search3 = search1.ForDefaultFields(criteria1.SearchPhrase, criteria.Locale);
                    HashSet <string>           source  = new HashSet <string>((IEqualityComparer <string>)StringComparer.OrdinalIgnoreCase);
                    if (language != null && !string.IsNullOrEmpty(language.FieldSuffix) && languageOption.HasFlag((Enum)QueryCultureOption.Neutral))
                    {
                        source.Add(language.FieldSuffix);
                    }
                    if (!string.IsNullOrEmpty(criteria.Locale) && languageOption.HasFlag((Enum)QueryCultureOption.Specific))
                    {
                        source.Add(criteria.Locale);
                    }
                    if (!source.Any <string>())
                    {
                        source.Add(ContentLanguage.PreferredCulture.Name);
                    }
                    search2 = search3.FilterLanguages((IEnumerable <string>)source);
                }
                if (DateTime.MinValue < criteria1.StartDate && criteria1.EndDate < DateTime.MaxValue)
                {
                    search2 = search2.FilterDates(criteria1.StartDate, criteria1.EndDate, criteria1.IncludePreorderEntry);
                }
                search1 = search2.FilterCatalogs(this.ToStringEnumerable(criteria1.CatalogNames)).FilterCatalogNodes(this.GetNodes(criteria1)).FilterOutlines(this.GetOutlines(criteria1)).FilterMetaClasses(this.ToStringEnumerable(criteria1.SearchIndex)).FilterCatalogEntryTypes(this.ToStringEnumerable(criteria1.ClassTypes));
                if (!criteria1.IncludeInactive)
                {
                    search1 = search1.FilterInactiveCatalogEntries();
                }
                if (criteria1.MarketId != MarketId.Empty)
                {
                    search1 = search1.FilterCatalogEntryMarket(criteria1.MarketId);
                }
            }
            ITypeSearch <FindDocument> search4 = search1.AddActiveFilters(criteria).AddFacets(criteria).OrderBy(criteria);

            if (criteria.StartingRecord > 0)
            {
                search4 = search4.Skip <FindDocument>(criteria.StartingRecord);
            }
            if (criteria.RecordsToRetrieve > 0)
            {
                search4 = search4.Take <FindDocument>(criteria.RecordsToRetrieve);
            }
            this.Search = (ISearch <FindDocument>)search4;
        }