Ejemplo n.º 1
0
        public IEnumerable <Offer> Search(String search)
        {
            var cachedDocuments = _distributedCache.Get(search);

            if (cachedDocuments == null)
            {
                var documents = _elasticRepository.SearchOffer(search);
                var bf        = new BinaryFormatter();

                using (var ms = new MemoryStream())
                {
                    bf.Serialize(ms, documents);
                    _distributedCache.Set(search, ms.ToArray(), new DistributedCacheEntryOptions {
                        AbsoluteExpirationRelativeToNow = new TimeSpan(0, 2, 0)
                    });
                }

                return(documents);
            }

            using (var memStream = new MemoryStream())
            {
                var binForm = new BinaryFormatter();
                memStream.Write(cachedDocuments, 0, cachedDocuments.Length);
                memStream.Seek(0, SeekOrigin.Begin);
                var obj = (IEnumerable <Offer>)binForm.Deserialize(memStream);
                return(obj);
            }
        }
Ejemplo n.º 2
0
        private void RecalculateNeuralNetwork(string query)
        {
            if (itemsClickedInSearch == null || !itemsClickedInSearch.ContainsKey(query))
            {
                return;
            }
            var offers = _elasticRepository.SearchOffer(query);

            var neuralItems = GetLeadData(offers, query);

            if (neuralItems == null)
            {
                return;
            }

            var neuralTrainingData = GetNeuralTrainingData(neuralItems);

            if (neuralTrainingData == null || neuralTrainingData.xs.Count() == 0)
            {
                return;
            }
            // TODO recalculate model and save on the training static dictionary
            string model = _javascriptExecutor.Fit(query, neuralTrainingData);

            if (trainedModels.ContainsKey(query))
            {
                trainedModels.Remove(query);
            }

            trainedModels.Add(query, model);
        }