コード例 #1
0
        public ActionResult CalculatePrice(ProductCardRenderingViewModel priceCalculationDetails)
        {
            var product = _productIndex.Find()
                          .Where(x => x.Sku == priceCalculationDetails.ProductSku && x.VariantSku == null).SingleOrDefault();

            string priceGroupName  = _catalogContext.CurrentPriceGroup.Name;
            string currencyIsoCode = _catalogContext.CurrentPriceGroup.CurrencyISOCode;

            var yourPrice = new Money(product.PricesInclTax[priceGroupName], currencyIsoCode).ToString();
            var yourTax   = new Money(product.Taxes[priceGroupName], currencyIsoCode).ToString();

            return(Json(new { YourPrice = yourPrice, Tax = yourTax, Discount = 0 }));
        }
        public ActionResult Rendering()
        {
            var productView = new ProductCardRenderingViewModel();

            var database    = Sitecore.Context.Database;
            var productItem = database.GetItem(RenderingContext.Current.Rendering.Properties["productGuid"]);

            if (productItem == null)
            {
                return(null);
            }
            productView.DisplayName    = new HtmlString(FieldRenderer.Render(productItem, "Display Name"));
            productView.ThumbnailImage = new HtmlString(FieldRenderer.Render(productItem, "Thumbnail image"));

            var currentProduct = _productIndex.Find().Where(x => x.Guid == productItem.ID.Guid).SingleOrDefault();
            var category       = _catalogContext.CurrentCategory;

            productView.Url = _urlService.GetUrl(_catalogContext.CurrentCatalog,
                                                 _catalogContext.CurrentCategories.Append(_catalogContext.CurrentCategory).Compact()
                                                 , currentProduct);

            productView.ProductPriceRenderingViewModel =
                GetProductPriceRenderingViewModel(currentProduct, category, _catalogContext.CurrentCatalog);

            return(View(productView));
        }
コード例 #3
0
        /// <inheritdoc />
        public byte[] Read(Guid guid)
        {
            var indexEntry = index.Find(guid);
            var data       = datastore.Read(indexEntry.DataOffset, indexEntry.DataSize);

            return(data);
        }
コード例 #4
0
        /// <summary>
        ///     Perform a circular query on this index. This will return all entries in the index that are in the specified range
        ///     of the specified point, using the euclidean distance function (i.e. <c>sqrt(x*x+y*y)</c>).
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="index">The index to search in.</param>
        /// <param name="point">The query point near which to get entries.</param>
        /// <param name="range">The maximum distance an entry may be away from the query point to be returned.</param>
        /// <param name="list">The list to put the results into. It is guaranteed that there will be no duplicate entries.</param>
        /// <remarks>
        ///     This checks for intersections of the query circle and the bounds of the entries in the index. Intersections
        ///     (i.e. bounds not fully contained in the circle) will be returned, too.
        /// </remarks>
        public static void Find <T>(
            this IIndex <T, TRectangle, TPoint> index, Vector2 point, float range, ref ISet <T> list)
        {
            // Convert to integer point type.
            TPoint p;

            p.X = (int)point.X;
            p.Y = (int)point.Y;

            // Perform actual search.
            index.Find(p, range, list);
        }
コード例 #5
0
ファイル: EtSearcher.cs プロジェクト: avetome/BooleanSearch
        private List <int> SearchInTree(ExpressionTreeNode node, bool notCompareWithAll = false)
        {
            if (node == null)
            {
                throw new Exception("Invalid expression tree");
            }

            if (!string.IsNullOrEmpty(node.Term))
            {
                return(_index.Find(node.Term));
            }

            var result = new List <int>();

            if (node.Operation == "AND")
            {
                if (node.Child2.Operation == "NOT")
                {
                    return(SearchInTree(node.Child1).Except(SearchInTree(node.Child2, true)).ToList());
                }

                return(SearchInTree(node.Child1).Intersect(SearchInTree(node.Child2)).ToList());
            }

            if (node.Operation == "OR")
            {
                return(SearchInTree(node.Child1).Concat(SearchInTree(node.Child2)).ToList());
            }

            if (node.Operation == "NOT")
            {
                if (notCompareWithAll)
                {
                    return(SearchInTree(node.Child1).ToList());
                }

                return(_dataSource.GetAllIds().Except(SearchInTree(node.Child1)).ToList());
            }

            if (node.Operation == "ALL")
            {
                return(_dataSource.GetAllIds());
            }

            if (node.Operation == "ZERO")
            {
                return(new List <int>());
            }

            throw new Exception("Invalid expression tree");
        }
コード例 #6
0
        public void KeyCanBeNull()
        {
            _items.Add(new TestObject(99, null));

            Assert.IsTrue(_itemsByName.Find(null).Count() == 1);
        }
コード例 #7
0
        public void FindReturnsEmptyListAfterRemovalOfLastObjectWithKey()
        {
            _items.Remove(new TestObject(1, "one"));

            Assert.IsTrue(_itemsById.Find(1).IsEmpty());
        }
コード例 #8
0
        private static void Run <T>(IIndex <int, TRectangle, TPoint> index, IList <Tuple <int, T> > data,
                                    BuildSmallUpdates <T> makeSmallUpdate,
                                    BuildLargeUpdates <T> makeLargeUpdate,
                                    AddEntries <T> addEntries,
                                    DoUpdate <T> doUpdate)
        {
            // Get new randomizer.
            var random = new MersenneTwister(Seed);

            // Get stop watch for profiling.
            var watch = new Stopwatch();

            // Also allocate the ids to look up in advance.
            var rangeQueries = new List <Tuple <TPoint, float> >(Operations);
            var areaQueries  = new List <TRectangle>(Operations);

            // And updates.
            var smallUpdates = new List <Tuple <int, T> >(Operations);
            var largeUpdates = new List <Tuple <int, T> >(Operations);

            var addTime              = new DoubleSampling(Iterations);
            var rangeQueryTime       = new DoubleSampling(Iterations);
            var areaQueryTime        = new DoubleSampling(Iterations);
            var smallUpdateTime      = new DoubleSampling(Iterations);
            var largeUpdateTime      = new DoubleSampling(Iterations);
            var highLoadRemoveTime   = new DoubleSampling(Iterations);
            var mediumLoadRemoveTime = new DoubleSampling(Iterations);
            var lowLoadRemoveTime    = new DoubleSampling(Iterations);

            Console.Write("Doing {0} iterations... ", Iterations);

            for (var i = 0; i < Iterations; i++)
            {
                Console.Write("{0}. ", i + 1);

                // Clear the index.
                index.Clear();

                // Generate look up ids in advance.
                rangeQueries.Clear();
                for (var j = 0; j < Operations; j++)
                {
                    rangeQueries.Add(Tuple.Create(random.NextVector(Area), MinQueryRange + (MaxQueryRange - MinQueryRange) * (float)random.NextDouble()));
                }
                areaQueries.Clear();
                for (var j = 0; j < Operations; j++)
                {
                    areaQueries.Add(random.NextRectangle(Area, MinQueryRange * 2, MaxQueryRange * 2));
                }

                // Generate position updates.
                smallUpdates.Clear();
                largeUpdates.Clear();
                for (var j = 0; j < Operations; j++)
                {
                    // High chance it remains in the same cell.
                    makeSmallUpdate(smallUpdates, data, random, j);
                }
                for (var j = 0; j < Operations; j++)
                {
                    // High chance it will be outside the original cell.
                    makeLargeUpdate(largeUpdates, data, random, j);
                }

                // Test time to add.
                try
                {
                    watch.Reset();
                    watch.Start();
                    addEntries(index, data);
                    watch.Stop();
                    addTime.Put(watch.ElapsedMilliseconds / (double)NumberOfObjects);
                }
                catch (NotSupportedException)
                {
                }

                // Test update time.
                try
                {
                    watch.Reset();
                    watch.Start();
                    foreach (var update in smallUpdates)
                    {
                        doUpdate(index, update);
                    }
                    watch.Stop();
                    smallUpdateTime.Put(watch.ElapsedMilliseconds / (double)smallUpdates.Count);
                }
                catch (NotSupportedException)
                {
                }

                try
                {
                    watch.Reset();
                    watch.Start();
                    foreach (var update in largeUpdates)
                    {
                        doUpdate(index, update);
                    }
                    watch.Stop();
                    largeUpdateTime.Put(watch.ElapsedMilliseconds / (double)largeUpdates.Count);
                }
                catch (NotSupportedException)
                {
                }

                // Test look up time.
                try
                {
                    watch.Reset();
                    watch.Start();
                    for (var j = 0; j < Operations; j++)
                    {
#if USE_CALLBACK
                        index.Find(rangeQueries[j].Item1, rangeQueries[j].Item2, value => true);
#else
                        index.Find(rangeQueries[j].Item1, rangeQueries[j].Item2, ref DummyCollection <int> .Instance);
#endif
                    }
                    watch.Stop();
                    rangeQueryTime.Put(watch.ElapsedMilliseconds / (double)Operations);
                }
                catch (NotSupportedException)
                {
                }

                try
                {
                    watch.Reset();
                    watch.Start();
                    for (var j = 0; j < Operations; j++)
                    {
                        var rect = areaQueries[j];
#if USE_CALLBACK
                        index.Find(rect, value => true);
#else
                        index.Find(rect, ref DummyCollection <int> .Instance);
#endif
                    }
                    watch.Stop();
                    areaQueryTime.Put(watch.ElapsedMilliseconds / (double)Operations);
                }
                catch (NotSupportedException)
                {
                }

                // Test removal time.
                try
                {
                    watch.Reset();
                    watch.Start();
                    for (var j = 0; j < NumberOfObjects / 3; j++)
                    {
                        index.Remove(data[j].Item1);
                    }
                    watch.Stop();
                    highLoadRemoveTime.Put(watch.ElapsedMilliseconds / (double)(NumberOfObjects / 3));
                }
                catch (NotSupportedException)
                {
                }

                try
                {
                    watch.Reset();
                    watch.Start();
                    for (var j = NumberOfObjects / 3; j < NumberOfObjects * 2 / 3; j++)
                    {
                        index.Remove(data[j].Item1);
                    }
                    watch.Stop();
                    mediumLoadRemoveTime.Put(watch.ElapsedMilliseconds / (double)(NumberOfObjects / 3));
                }
                catch (NotSupportedException)
                {
                }

                try
                {
                    watch.Reset();
                    watch.Start();
                    for (var j = NumberOfObjects * 2 / 3; j < NumberOfObjects; j++)
                    {
                        index.Remove(data[j].Item1);
                    }
                    watch.Stop();
                    lowLoadRemoveTime.Put(watch.ElapsedMilliseconds / (double)(NumberOfObjects / 3));
                }
                catch (NotSupportedException)
                {
                }
            }

            Console.WriteLine("Done!");

            Console.WriteLine("Operation           | Mean      | Std.dev.\n" +
                              "Add:                | {0:0.00000}ms | {1:0.00000}ms\n" +
                              "Range query:        | {2:0.00000}ms | {3:0.00000}ms\n" +
                              "Area query:         | {4:0.00000}ms | {5:0.00000}ms\n" +
                              "Update (small):     | {6:0.00000}ms | {7:0.00000}ms\n" +
                              "Update (large):     | {8:0.00000}ms | {9:0.00000}ms\n" +
                              "Remove (high load): | {10:0.00000}ms | {11:0.00000}ms\n" +
                              "Remove (med. load): | {12:0.00000}ms | {13:0.00000}ms\n" +
                              "Remove (low load):  | {14:0.00000}ms | {15:0.00000}ms",
                              addTime.Mean(), addTime.StandardDeviation(),
                              rangeQueryTime.Mean(), rangeQueryTime.StandardDeviation(),
                              areaQueryTime.Mean(), areaQueryTime.StandardDeviation(),
                              smallUpdateTime.Mean(), smallUpdateTime.StandardDeviation(),
                              largeUpdateTime.Mean(), largeUpdateTime.StandardDeviation(),
                              highLoadRemoveTime.Mean(), highLoadRemoveTime.StandardDeviation(),
                              mediumLoadRemoveTime.Mean(), mediumLoadRemoveTime.StandardDeviation(),
                              lowLoadRemoveTime.Mean(), lowLoadRemoveTime.StandardDeviation());
        }
コード例 #9
0
        public List <int> Search(string query)
        {
            var parser      = new SimpleQueryParser(query);
            var parsedQuery = parser.Parse();

            if (parsedQuery.Length == 1)
            {
                return(_index.Find(parsedQuery[0]));
            }

            var i      = 0;
            var result = new List <int>();

            while (i < parsedQuery.Length)
            {
                if (i == 0)
                {
                    var invertedFirstArg = parsedQuery[i] == "NOT";

                    i = invertedFirstArg ? ++i : i;

                    if (invertedFirstArg)
                    {
                        result = _dataSource.GetAllIds().Except(_index.Find(parsedQuery[i++])).ToList();
                    }
                    else
                    {
                        result = _index.Find(parsedQuery[i++]);
                    }
                }

                if (parsedQuery[i] == "AND")
                {
                    i++;

                    if (parsedQuery[i] == "NOT")
                    {
                        result = result.Except(_index.Find(parsedQuery[++i])).ToList();
                    }
                    else
                    {
                        result = result.Intersect(_index.Find(parsedQuery[i])).ToList();
                    }
                }
                else if (parsedQuery[i] == "OR")
                {
                    i++;

                    if (parsedQuery[i] == "NOT")
                    {
                        result = result.Concat(_dataSource.GetAllIds().Except(_index.Find(parsedQuery[++i]))).ToList();
                    }
                    else
                    {
                        result = result.Concat(_index.Find(parsedQuery[i])).ToList();
                    }
                }

                i++;
            }

            return(result);
        }