예제 #1
0
        private IRecommendationEngine GetRecommendationEngine(CommerceDataSourceContext context, ParsedGenericCommerceDataSourceSettings settings, out ISet <string> toIgnoreItems)
        {
            var filter = settings.Filters.Find(f => f.Name == "ByProduct");

            if (filter != null)
            {
                var productId = (int)filter.GetParameterValue("ProductId");

                toIgnoreItems = new HashSet <string> {
                    productId.ToString()
                };

                return(new FeatureBasedRecommendationEngine(new[] { new Feature(productId.ToString()) }, RelatedItemsProviders.GetProviders(context.Instance)));
            }
            else
            {
                toIgnoreItems = new HashSet <string>();

                foreach (var behaviorType in BehaviorTypes.All())
                {
                    var store = BehaviorStores.Get(context.Instance, behaviorType);
                    foreach (var itemId in store.GetItemsUserHadBehaviorsOn(context.HttpContext.EnsureVisitorUniqueId(), 10000))
                    {
                        toIgnoreItems.Add(itemId);
                    }
                }

                return(RecommendationEngines.GetEngines(context.Instance));
            }
        }
예제 #2
0
        public void Execute(JobContext context)
        {
            var instance     = context.Instance;
            var behaviorType = context.JobData["BehaviorType"];

            var matrix    = SimilarityMatrixes.Get(instance, behaviorType);
            var newMatrix = matrix.PrepareRecomputation();

            Recompute(newMatrix, BehaviorStores.Get(instance, behaviorType));
            matrix.ReplaceWith(newMatrix);
        }
예제 #3
0
        static WeightedRecommendationEngineCollection CreateRecommendationEngines(string instance)
        {
            var engines = new WeightedRecommendationEngineCollection();

            foreach (var behaviorType in BehaviorTypes.All())
            {
                var featureBuilder = new BehaviorBasedFeatureBuilder(() =>
                {
                    var store = BehaviorStores.Get(instance, behaviorType);
                    return(store.GetRecentBehaviors(50));
                });

                var engine = new FeatureBasedRecommendationEngine(featureBuilder, RelatedItemsProviders.GetProviders(instance));
                engines.Add(engine, 1f);
            }

            return(engines);
        }