public void CreateThreeFacetsWithOneBeingARangeFacetThatAllHaveMultipleConstraintApplied()
        {
            SolrNetFacetTestFramework.RunSolrUrlCreationTest(@"http://localhost:8983/solr/select?q=*:*&rows=100000000&fq={!tag=brandsfilter}brand_f:(iPhone+OR+LCD+televisions+OR+Smartphones)&fq={!tag=manufacturersfilter}manufacturer_f:(Apple+OR+Samsung)&fq={!tag=unitpricefilter}unitprice:([*+TO+99.99]+OR+[100+TO+499.99])&facet=true&facet.field={!key=brands+ex=brandsfilter}brand_f&facet.field={!key=brandsruledout+ex=manufacturersfilter,unitpricefilter,brandsfilter}brand_f&facet.field={!key=manufacturers+ex=manufacturersfilter}manufacturer_f&facet.field={!key=manufacturersruledout+ex=brandsfilter,unitpricefilter,manufacturersfilter}manufacturer_f&facet.query={!label=*-99.99\+ex=unitpricefilter}unitprice:[*+TO+99.99]&facet.query={!label=100-499.99\+ex=unitpricefilter}unitprice:[100+TO+499.99]&facet.query={!label=*-99.99-ruledout\+ex=brandsfilter,manufacturersfilter,unitpricefilter}unitprice:[*+TO+99.99]&facet.query={!label=100-499.99-ruledout\+ex=brandsfilter,manufacturersfilter,unitpricefilter}unitprice:[100+TO+499.99]&version=2.2", solr =>
            {
                var querystring = new NameValueCollection
                    {
                        {"fb", "Smartphones"},
                        {"fb", "iPhone"},
                        {"fb", "LCD televisions"},
                        {"fm", "Apple"},
                        {"fm", "Samsung"},
                        {"fps", "*"},
                        {"fpl", "99.99"},
                        {"fps", "100"},
                        {"fpl", "499.99"},
                    };

                var queryOptions = new QueryOptions();
                var brandFacet = new BrandFacet(querystring);
                var manufacturerFacet = new ManufacturerFacet(querystring);
                var priceFacet = new PriceFacet(querystring, false, new RangeQuery("*", "99.99"), new RangeQuery("100", "499.99"));

                var facets = new IFacet[]
                {
                    brandFacet,
                    manufacturerFacet,
                    priceFacet
                };

                brandFacet.BuildDependencies(facets);
                manufacturerFacet.BuildDependencies(facets);
                priceFacet.BuildDependencies(facets);

                brandFacet.BuildQuery(queryOptions);
                manufacturerFacet.BuildQuery(queryOptions);
                priceFacet.BuildQuery(queryOptions);

                return solr.Query(SolrQuery.All, queryOptions);
            });
        }
Beispiel #2
0
        public void BuildFacetViewModelsForThreeFacetsWithOneBeingARangeFacetThatAllHaveMultipleConstraintApplied()
        {
            var results =
                SolrNetFacetTestFramework.RunSolrGetResults(
                "<?xml version=\"1.0\" encoding=\"UTF-8\"?><response><lst name=\"responseHeader\"><int name=\"status\">0</int><int name=\"QTime\">68</int><lst name=\"params\"><str name=\"facet\">true</str><arr name=\"facet.query\"><str>{!label=*-99.99 ex=unitpricefilter}unitprice:[* TO 99.99]</str><str>{!label=100-499.99 ex=unitpricefilter}unitprice:[100 TO 499.99]</str><str>{!label=*-99.99-ruledout ex=brandsfilter,manufacturersfilter,unitpricefilter}unitprice:[* TO 99.99]</str><str>{!label=100-499.99-ruledout ex=brandsfilter,manufacturersfilter,unitpricefilter}unitprice:[100 TO 499.99]</str></arr><str name=\"q\">*:*</str><arr name=\"facet.field\"><str>{!key=brands ex=brandsfilter}brand_f</str><str>{!key=brandsruledout ex=manufacturersfilter,unitpricefilter,brandsfilter}brand_f</str><str>{!key=manufacturers ex=manufacturersfilter}manufacturer_f</str><str>{!key=manufacturersruledout ex=brandsfilter,unitpricefilter,manufacturersfilter}manufacturer_f</str></arr><arr name=\"fq\"><str>{!tag=brandsfilter}brand_f:(iPhone OR LCD televisions OR Smartphones)</str><str>{!tag=manufacturersfilter}manufacturer_f:(Apple OR Samsung)</str><str>{!tag=unitpricefilter}unitprice:([* TO 99.99] OR [100 TO 499.99])</str></arr><str name=\"version\">2.2</str><str name=\"rows\">100000000</str></lst></lst><result name=\"response\" numFound=\"5\" start=\"0\"><doc><str name=\"id\">65536</str><str name=\"categoryid\">32770</str><float name=\"unitprice\">100.0</float><str name=\"unitprice_c\">100.0000,USD</str><str name=\"name\">iPhone</str><str name=\"url\">home/electronics/phones/iphone</str><long name=\"_version_\">1435991846256902144</long></doc><doc><str name=\"id\">65537</str><str name=\"categoryid\">32770</str><float name=\"unitprice\">200.0</float><str name=\"unitprice_c\">200.0000,USD</str><str name=\"name\">iPhone3G</str><str name=\"url\">home/electronics/phones/iphone3g</str><long name=\"_version_\">1435991846263193600</long></doc><doc><str name=\"id\">65540</str><str name=\"categoryid\">32770</str><float name=\"unitprice\">250.0</float><str name=\"unitprice_c\">250.0000,USD</str><str name=\"name\">iPhone3GS</str><str name=\"url\">home/electronics/phones/iphone3gs</str><long name=\"_version_\">1435991846267387904</long></doc><doc><str name=\"id\">65541</str><str name=\"categoryid\">32770</str><float name=\"unitprice\">350.0</float><str name=\"unitprice_c\">350.0000,USD</str><str name=\"name\">iPhone4</str><str name=\"url\">home/electronics/phones/iphone4</str><long name=\"_version_\">1435991846272630784</long></doc><doc><str name=\"id\">65548</str><str name=\"categoryid\">32770</str><float name=\"unitprice\">270.0</float><str name=\"unitprice_c\">270.0000,USD</str><str name=\"name\">Omina W</str><str name=\"url\">home/electronics/phones/omina-w</str><long name=\"_version_\">1435991846282067968</long></doc></result><lst name=\"facet_counts\"><lst name=\"facet_queries\"><int name=\"{!label=*-99.99 ex=unitpricefilter}unitprice:[* TO 99.99]\">0</int><int name=\"{!label=100-499.99 ex=unitpricefilter}unitprice:[100 TO 499.99]\">5</int><int name=\"{!label=*-99.99-ruledout ex=brandsfilter,manufacturersfilter,unitpricefilter}unitprice:[* TO 99.99]\">1</int><int name=\"{!label=100-499.99-ruledout ex=brandsfilter,manufacturersfilter,unitpricefilter}unitprice:[100 TO 499.99]\">8</int></lst><lst name=\"facet_fields\"><lst name=\"brands\"><int name=\"iPhone\">4</int><int name=\"Mobile phones\">2</int><int name=\"iPad\">2</int><int name=\"Smartphones\">1</int><int name=\"LCD televisions\">0</int><int name=\"LED televisions\">0</int><int name=\"Plasma televisions\">0</int></lst><lst name=\"brandsruledout\"><int name=\"iPhone\">5</int><int name=\"iPad\">3</int><int name=\"Mobile phones\">2</int><int name=\"Smartphones\">2</int><int name=\"LCD televisions\">1</int><int name=\"LED televisions\">1</int><int name=\"Plasma televisions\">1</int></lst><lst name=\"manufacturers\"><int name=\"Apple\">4</int><int name=\"Samsung\">1</int></lst><lst name=\"manufacturersruledout\"><int name=\"Apple\">8</int><int name=\"Samsung\">7</int></lst></lst><lst name=\"facet_dates\"/><lst name=\"facet_ranges\"/></lst></response>",
                @"http://localhost:8983/solr/select?q=*:*&rows=100000000&fq={!tag=brandsfilter}brand_f:(iPhone OR LCD televisions OR Smartphones)&fq={!tag=manufacturersfilter}manufacturer_f:(Apple OR Samsung)&fq={!tag=unitpricefilter}unitprice:([* TO 99.99] OR [100 TO 499.99])&facet=true&facet.field={!key=brands ex=brandsfilter}brand_f&facet.field={!key=brandsruledout ex=manufacturersfilter,unitpricefilter,brandsfilter}brand_f&facet.field={!key=manufacturers ex=manufacturersfilter}manufacturer_f&facet.field={!key=manufacturersruledout ex=brandsfilter,unitpricefilter,manufacturersfilter}manufacturer_f&facet.query={!label=*-99.99 ex=unitpricefilter}unitprice:[* TO 99.99]&facet.query={!label=100-499.99 ex=unitpricefilter}unitprice:[100 TO 499.99]&facet.query={!label=*-99.99-ruledout ex=brandsfilter,manufacturersfilter,unitpricefilter}unitprice:[* TO 99.99]&facet.query={!label=100-499.99-ruledout ex=brandsfilter,manufacturersfilter,unitpricefilter}unitprice:[100 TO 499.99]&version=2.2");

            var querystring = new NameValueCollection
                    {
                        {"fb", "Smartphones"},
                        {"fb", "iPhone"},
                        {"fb", "LCD televisions"},
                        {"fm", "Apple"},
                        {"fm", "Samsung"},
                        {"fps", "*"},
                        {"fpl", "99.99"},
                        {"fps", "100"},
                        {"fpl", "499.99"},
                    };

            var brandFacet = new BrandFacet(querystring);
            var manufacturerFacet = new ManufacturerFacet(querystring);
            var priceFacet = new PriceFacet(querystring, false, new RangeQuery("*", "99.99"), new RangeQuery("100", "499.99"));

            var facets = new IFacet[]
                {
                    brandFacet,
                    manufacturerFacet,
                    priceFacet
                };

            brandFacet.BuildDependencies(facets);
            manufacturerFacet.BuildDependencies(facets);
            priceFacet.BuildDependencies(facets);

            var brandFacetViewModel = brandFacet.BuildViewModel(results);
            var manufacturerFacetViewModel = manufacturerFacet.BuildViewModel(results);
            var priceFacetViewModel = priceFacet.BuildViewModel(results);

            var expectedBrandValues = new[] {
                new { IsApplied = false, IsDisabled = false, Count = 2, Name = "iPad", Url = "/?fm=Apple&fm=Samsung&fps=*&fps=100&fpl=99.99&fpl=499.99&fb=iPad&fb=iPhone&fb=LCD+televisions&fb=Smartphones" },
                new { IsApplied = true, IsDisabled = false, Count = 4, Name = "iPhone", Url = "/?fm=Apple&fm=Samsung&fps=*&fps=100&fpl=99.99&fpl=499.99&fb=LCD+televisions&fb=Smartphones" },
                new { IsApplied = true, IsDisabled = true, Count = 1, Name = "LCD televisions", Url = string.Empty },
                new { IsApplied = false, IsDisabled = true, Count = 1, Name = "LED televisions", Url = string.Empty },
                new { IsApplied = false, IsDisabled = false, Count = 2, Name = "Mobile phones", Url = "/?fm=Apple&fm=Samsung&fps=*&fps=100&fpl=99.99&fpl=499.99&fb=iPhone&fb=LCD+televisions&fb=Mobile+phones&fb=Smartphones" },
                new { IsApplied = false, IsDisabled = true, Count = 1, Name = "Plasma televisions", Url = string.Empty },
                new { IsApplied = true, IsDisabled = false, Count = 1, Name = "Smartphones", Url = "/?fm=Apple&fm=Samsung&fps=*&fps=100&fpl=99.99&fpl=499.99&fb=iPhone&fb=LCD+televisions" }
            };

            Assert.AreEqual(7, brandFacetViewModel.Constraints.Length);

            for (var index = 0; index < brandFacetViewModel.Constraints.Length; index++)
            {
                Assert.AreEqual(expectedBrandValues[index].IsApplied, brandFacetViewModel.Constraints[index].IsApplied);
                Assert.AreEqual(expectedBrandValues[index].IsDisabled, brandFacetViewModel.Constraints[index].IsDisabled);
                Assert.AreEqual(expectedBrandValues[index].Count, brandFacetViewModel.Constraints[index].Count);
                Assert.AreEqual(expectedBrandValues[index].Name, brandFacetViewModel.Constraints[index].Name);
                Assert.AreEqual(expectedBrandValues[index].Url, brandFacetViewModel.Constraints[index].Url);
            }

            var expectedManufacturerValues = new[] {
                new { IsApplied = true, IsDisabled = false, Count = 4, Name = "Apple", Url = "/?fb=iPhone&fb=LCD+televisions&fb=Smartphones&fps=*&fps=100&fpl=99.99&fpl=499.99&fm=Samsung" },
                new { IsApplied = true, IsDisabled = false, Count = 1, Name = "Samsung", Url = "/?fb=iPhone&fb=LCD+televisions&fb=Smartphones&fps=*&fps=100&fpl=99.99&fpl=499.99&fm=Apple" }
            };

            Assert.AreEqual(2, manufacturerFacetViewModel.Constraints.Length);

            for (var index = 0; index < manufacturerFacetViewModel.Constraints.Length; index++)
            {
                Assert.AreEqual(expectedManufacturerValues[index].IsApplied, manufacturerFacetViewModel.Constraints[index].IsApplied);
                Assert.AreEqual(expectedManufacturerValues[index].IsDisabled, manufacturerFacetViewModel.Constraints[index].IsDisabled);
                Assert.AreEqual(expectedManufacturerValues[index].Count, manufacturerFacetViewModel.Constraints[index].Count);
                Assert.AreEqual(expectedManufacturerValues[index].Name, manufacturerFacetViewModel.Constraints[index].Name);
                Assert.AreEqual(expectedManufacturerValues[index].Url, manufacturerFacetViewModel.Constraints[index].Url);
            }

            var expectedPriceValues = new[] {
                new { IsApplied = true, IsDisabled = true, Count = 1, Name = string.Format("Up to {0}99.99", NumberFormatInfo.CurrentInfo.CurrencySymbol), Url = string.Empty },
                new { IsApplied = true, IsDisabled = false, Count = 5, Name = string.Format("{0}100.00 - {0}499.99", NumberFormatInfo.CurrentInfo.CurrencySymbol), Url = "/?fb=iPhone&fb=LCD+televisions&fb=Smartphones&fm=Apple&fm=Samsung&fps=*&fpl=99.99" }
            };

            Assert.AreEqual(2, priceFacetViewModel.Constraints.Length);

            for (var index = 0; index < priceFacetViewModel.Constraints.Length; index++)
            {
                Assert.AreEqual(expectedPriceValues[index].IsApplied, priceFacetViewModel.Constraints[index].IsApplied);
                Assert.AreEqual(expectedPriceValues[index].IsDisabled, priceFacetViewModel.Constraints[index].IsDisabled);
                Assert.AreEqual(expectedPriceValues[index].Count, priceFacetViewModel.Constraints[index].Count);
                Assert.AreEqual(expectedPriceValues[index].Name, priceFacetViewModel.Constraints[index].Name);
                Assert.AreEqual(expectedPriceValues[index].Url, priceFacetViewModel.Constraints[index].Url);
            }
        }
Beispiel #3
0
        public void CreateTwoFacetsThatBothHaveMultipleConstraintsApplied()
        {
            SolrNetFacetTestFramework.RunSolrUrlCreationTest(@"http://localhost:8983/solr/select?q=*:*&rows=100000000&fq={!tag=brandsfilter}brand_f:(iPhone+OR+LCD+televisions+OR+LED+televisions+OR+Smartphones)&fq={!tag=manufacturersfilter}manufacturer_f:(Apple+OR+Samsung)&facet=true&facet.field={!key=brands+ex=brandsfilter}brand_f&facet.field={!key=brandsruledout+ex=manufacturersfilter,brandsfilter}brand_f&facet.field={!key=manufacturers+ex=manufacturersfilter}manufacturer_f&facet.field={!key=manufacturersruledout+ex=brandsfilter,manufacturersfilter}manufacturer_f&version=2.2", solr =>
            {
                var querystring = new NameValueCollection
                {
                    {"fb", "Smartphones"},
                    {"fb", "iPhone"},
                    {"fb", "LCD televisions"},
                    {"fb", "LED televisions"},
                    {"fm", "Apple"},
                    {"fm", "Samsung"}
                };

                var queryOptions = new QueryOptions();
                var brandFacet = new BrandFacet(querystring);
                var manufacturerFacet = new ManufacturerFacet(querystring);

                var facets = new IFacet[]
                {
                    brandFacet,
                    manufacturerFacet
                };

                brandFacet.BuildDependencies(facets);
                manufacturerFacet.BuildDependencies(facets);

                brandFacet.BuildQuery(queryOptions);
                manufacturerFacet.BuildQuery(queryOptions);

                return solr.Query(SolrQuery.All, queryOptions);
            });
        }
Beispiel #4
0
        public void CreateThreeFacetsThatAllHaveOneConstraintApplied()
        {
            SolrNetFacetTestFramework.RunSolrUrlCreationTest(@"http://localhost:8983/solr/select?q=*:*&rows=100000000&fq={!tag=brandsfilter}brand_f:(Smartphones)&fq={!tag=manufacturersfilter}manufacturer_f:(Samsung)&fq={!tag=unitpricefilter}unitprice:([500+TO+600])&facet=true&facet.field={!key=brands+ex=brandsfilter}brand_f&facet.field={!key=brandsruledout+ex=manufacturersfilter,unitpricefilter,brandsfilter}brand_f&facet.field={!key=manufacturers+ex=manufacturersfilter}manufacturer_f&facet.field={!key=manufacturersruledout+ex=brandsfilter,unitpricefilter,manufacturersfilter}manufacturer_f&facet.query={!label=500-600\+ex=unitpricefilter}unitprice:[500+TO+600]&facet.query={!label=601-1000\+ex=unitpricefilter}unitprice:[601+TO+1000]&facet.query={!label=500-600-ruledout\+ex=brandsfilter,manufacturersfilter,unitpricefilter}unitprice:[500+TO+600]&facet.query={!label=601-1000-ruledout\+ex=brandsfilter,manufacturersfilter,unitpricefilter}unitprice:[601+TO+1000]&version=2.2", solr =>
            {
                var querystring = new NameValueCollection
                {
                    {"fb", "Smartphones"},
                    {"fm", "Samsung"},
                    {"fps", "500"},
                    {"fpl", "600"}
                };

                var queryOptions = new QueryOptions();
                var brandFacet = new BrandFacet(querystring);
                var manufacturerFacet = new ManufacturerFacet(querystring);
                var priceFacet = new PriceFacet(querystring, false, new RangeQuery("500", "600"), new RangeQuery("601", "1000"));

                var facets = new IFacet[]
                {
                    brandFacet,
                    manufacturerFacet,
                    priceFacet
                };

                brandFacet.BuildDependencies(facets);
                manufacturerFacet.BuildDependencies(facets);
                priceFacet.BuildDependencies(facets);

                brandFacet.BuildQuery(queryOptions);
                manufacturerFacet.BuildQuery(queryOptions);
                priceFacet.BuildQuery(queryOptions);

                return solr.Query(SolrQuery.All, queryOptions);
            });
        }
Beispiel #5
0
        public void BuildTwoMultipleSelectFacetViewModelThatBothHaveMultipleConstraintsApplied()
        {
            var results =
                SolrNetFacetTestFramework.RunSolrGetResults(
                    "<?xml version=\"1.0\" encoding=\"UTF-8\"?><response><lst name=\"responseHeader\"><int name=\"status\">0</int><int name=\"QTime\">121</int><lst name=\"params\"><str name=\"facet\">true</str><str name=\"q\">*:*</str><arr name=\"facet.field\"><str>{!key=brands ex=brandsfilter}brand_f</str><str>{!key=brandsruledout ex=manufacturersfilter,brandsfilter}brand_f</str><str>{!key=manufacturers ex=manufacturersfilter}manufacturer_f</str><str>{!key=manufacturersruledout ex=brandsfilter,manufacturersfilter}manufacturer_f</str></arr><arr name=\"fq\"><str>{!tag=brandsfilter}brand_f:(iPhone OR LCD televisions OR LED televisions OR Smartphones)</str><str>{!tag=manufacturersfilter}manufacturer_f:(Apple OR Samsung)</str></arr><str name=\"version\">2.2</str><str name=\"rows\">100000000</str></lst></lst><result name=\"response\" numFound=\"7\" start=\"0\"><doc><str name=\"id\">65538</str><str name=\"categoryid\">32770</str><float name=\"unitprice\">523.0</float><str name=\"unitprice_c\">523.0000,USD</str><str name=\"name\">Galaxy Note</str><str name=\"url\">home/electronics/phones/galaxy-note</str><long name=\"_version_\">1435991846240124928</long></doc><doc><str name=\"id\">65536</str><str name=\"categoryid\">32770</str><float name=\"unitprice\">100.0</float><str name=\"unitprice_c\">100.0000,USD</str><str name=\"name\">iPhone</str><str name=\"url\">home/electronics/phones/iphone</str><long name=\"_version_\">1435991846256902144</long></doc><doc><str name=\"id\">65537</str><str name=\"categoryid\">32770</str><float name=\"unitprice\">200.0</float><str name=\"unitprice_c\">200.0000,USD</str><str name=\"name\">iPhone3G</str><str name=\"url\">home/electronics/phones/iphone3g</str><long name=\"_version_\">1435991846263193600</long></doc><doc><str name=\"id\">65540</str><str name=\"categoryid\">32770</str><float name=\"unitprice\">250.0</float><str name=\"unitprice_c\">250.0000,USD</str><str name=\"name\">iPhone3GS</str><str name=\"url\">home/electronics/phones/iphone3gs</str><long name=\"_version_\">1435991846267387904</long></doc><doc><str name=\"id\">65541</str><str name=\"categoryid\">32770</str><float name=\"unitprice\">350.0</float><str name=\"unitprice_c\">350.0000,USD</str><str name=\"name\">iPhone4</str><str name=\"url\">home/electronics/phones/iphone4</str><long name=\"_version_\">1435991846272630784</long></doc><doc><str name=\"id\">65539</str><str name=\"categoryid\">32770</str><float name=\"unitprice\">550.0</float><str name=\"unitprice_c\">550.0000,USD</str><str name=\"name\">iPhone4S</str><str name=\"url\">home/electronics/phones/iphone4s</str><long name=\"_version_\">1435991846277873664</long></doc><doc><str name=\"id\">65548</str><str name=\"categoryid\">32770</str><float name=\"unitprice\">270.0</float><str name=\"unitprice_c\">270.0000,USD</str><str name=\"name\">Omina W</str><str name=\"url\">home/electronics/phones/omina-w</str><long name=\"_version_\">1435991846282067968</long></doc></result><lst name=\"facet_counts\"><lst name=\"facet_queries\"/><lst name=\"facet_fields\"><lst name=\"brands\"><int name=\"iPhone\">5</int><int name=\"iPad\">3</int><int name=\"Mobile phones\">2</int><int name=\"Smartphones\">2</int><int name=\"LCD televisions\">1</int><int name=\"LED televisions\">1</int><int name=\"Plasma televisions\">1</int></lst><lst name=\"brandsruledout\"><int name=\"iPhone\">5</int><int name=\"iPad\">3</int><int name=\"Mobile phones\">2</int><int name=\"Smartphones\">2</int><int name=\"LCD televisions\">1</int><int name=\"LED televisions\">1</int><int name=\"Plasma televisions\">1</int></lst><lst name=\"manufacturers\"><int name=\"Apple\">5</int><int name=\"Samsung\">2</int></lst><lst name=\"manufacturersruledout\"><int name=\"Apple\">8</int><int name=\"Samsung\">7</int></lst></lst><lst name=\"facet_dates\"/><lst name=\"facet_ranges\"/></lst></response>",
                    @"http://localhost:8983/solr/select?q=*:*&rows=100000000&fq={!tag=brandsfilter}brand_f:(iPhone+OR+LCD+televisions+OR+LED+televisions+OR+Smartphones)&fq={!tag=manufacturersfilter}manufacturer_f:(Apple+OR+Samsung)&facet=true&facet.field={!key=brands+ex=brandsfilter}brand_f&facet.field={!key=brandsruledout+ex=manufacturersfilter,brandsfilter}brand_f&facet.field={!key=manufacturers+ex=manufacturersfilter}manufacturer_f&facet.field={!key=manufacturersruledout+ex=brandsfilter,manufacturersfilter}manufacturer_f&version=2.2");

            var querystring = new NameValueCollection
            {
                    {"fb", "Smartphones"},
                    {"fb", "iPhone"},
                    {"fb", "LCD televisions"},
                    {"fb", "LED televisions"},
                    {"fm", "Apple"},
                    {"fm", "Samsung"}
                };

            var brandFacet = new BrandFacet(querystring);
            var manufacturerFacet = new ManufacturerFacet(querystring);

            var facets = new IFacet[]
                {
                    brandFacet,
                    manufacturerFacet
                };

            brandFacet.BuildDependencies(facets);
            manufacturerFacet.BuildDependencies(facets);

            var brandFacetViewModel = brandFacet.BuildViewModel(results);
            var manufacturerFacetViewModel = manufacturerFacet.BuildViewModel(results);

            var expectedBrandValues = new[] {
                new { IsApplied = false, IsDisabled = false, Count = 3, Name = "iPad", Url = "/?fm=Apple&fm=Samsung&fb=iPad&fb=iPhone&fb=LCD+televisions&fb=LED+televisions&fb=Smartphones" },
                new { IsApplied = true, IsDisabled = false, Count = 5, Name = "iPhone", Url = "/?fm=Apple&fm=Samsung&fb=LCD+televisions&fb=LED+televisions&fb=Smartphones" },
                new { IsApplied = true, IsDisabled = false, Count = 1, Name = "LCD televisions", Url = "/?fm=Apple&fm=Samsung&fb=iPhone&fb=LED+televisions&fb=Smartphones" },
                new { IsApplied = true, IsDisabled = false, Count = 1, Name = "LED televisions", Url = "/?fm=Apple&fm=Samsung&fb=iPhone&fb=LCD+televisions&fb=Smartphones" },
                new { IsApplied = false, IsDisabled = false, Count = 2, Name = "Mobile phones", Url = "/?fm=Apple&fm=Samsung&fb=iPhone&fb=LCD+televisions&fb=LED+televisions&fb=Mobile+phones&fb=Smartphones" },
                new { IsApplied = false, IsDisabled = false, Count = 1, Name = "Plasma televisions", Url = "/?fm=Apple&fm=Samsung&fb=iPhone&fb=LCD+televisions&fb=LED+televisions&fb=Plasma+televisions&fb=Smartphones" },
                new { IsApplied = true, IsDisabled = false, Count = 2, Name = "Smartphones", Url = "/?fm=Apple&fm=Samsung&fb=iPhone&fb=LCD+televisions&fb=LED+televisions" }
            };

            Assert.AreEqual(7, brandFacetViewModel.Constraints.Length);

            for (var index = 0; index < brandFacetViewModel.Constraints.Length; index++)
            {
                Assert.AreEqual(expectedBrandValues[index].IsApplied, brandFacetViewModel.Constraints[index].IsApplied);
                Assert.AreEqual(expectedBrandValues[index].IsDisabled, brandFacetViewModel.Constraints[index].IsDisabled);
                Assert.AreEqual(expectedBrandValues[index].Count, brandFacetViewModel.Constraints[index].Count);
                Assert.AreEqual(expectedBrandValues[index].Name, brandFacetViewModel.Constraints[index].Name);
                Assert.AreEqual(expectedBrandValues[index].Url, brandFacetViewModel.Constraints[index].Url);
            }

            var expectedManufacturerValues = new[] {
                new { IsApplied = true, IsDisabled = false, Count = 5, Name = "Apple", Url = "/?fb=iPhone&fb=LCD+televisions&fb=LED+televisions&fb=Smartphones&fm=Samsung" },
                new { IsApplied = true, IsDisabled = false, Count = 2, Name = "Samsung", Url = "/?fb=iPhone&fb=LCD+televisions&fb=LED+televisions&fb=Smartphones&fm=Apple" }
            };

            Assert.AreEqual(2, manufacturerFacetViewModel.Constraints.Length);

            for (var index = 0; index < manufacturerFacetViewModel.Constraints.Length; index++)
            {
                Assert.AreEqual(expectedManufacturerValues[index].IsApplied, manufacturerFacetViewModel.Constraints[index].IsApplied);
                Assert.AreEqual(expectedManufacturerValues[index].IsDisabled, manufacturerFacetViewModel.Constraints[index].IsDisabled);
                Assert.AreEqual(expectedManufacturerValues[index].Count, manufacturerFacetViewModel.Constraints[index].Count);
                Assert.AreEqual(expectedManufacturerValues[index].Name, manufacturerFacetViewModel.Constraints[index].Name);
                Assert.AreEqual(expectedManufacturerValues[index].Url, manufacturerFacetViewModel.Constraints[index].Url);
            }
        }
Beispiel #6
0
        public void BuildThreeFacetsViewModelsThatAllHaveOneConstraintApplied()
        {
            var results =
                SolrNetFacetTestFramework.RunSolrGetResults(
                "<?xml version=\"1.0\" encoding=\"UTF-8\"?><response><lst name=\"responseHeader\"><int name=\"status\">0</int><int name=\"QTime\">5</int><lst name=\"params\"><str name=\"facet\">true</str><arr name=\"facet.query\"><str>{!label=500-600 ex=unitpricefilter}unitprice:[500 TO 600]</str><str>{!label=601-1000 ex=unitpricefilter}unitprice:[601 TO 1000]</str><str>{!label=500-600-ruledout ex=brandsfilter,manufacturersfilter,unitpricefilter}unitprice:[500 TO 600]</str><str>{!label=601-1000-ruledout ex=brandsfilter,manufacturersfilter,unitpricefilter}unitprice:[601 TO 1000]</str></arr><str name=\"q\">*:*</str><arr name=\"facet.field\"><str>{!key=brands ex=brandsfilter}brand_f</str><str>{!key=brandsruledout ex=manufacturersfilter,unitpricefilter,brandsfilter}brand_f</str><str>{!key=manufacturers ex=manufacturersfilter}manufacturer_f</str><str>{!key=manufacturersruledout ex=brandsfilter,unitpricefilter,manufacturersfilter}manufacturer_f</str></arr><arr name=\"fq\"><str>{!tag=brandsfilter}brand_f:(Smartphones)</str><str>{!tag=manufacturersfilter}manufacturer_f:(Samsung)</str><str>{!tag=unitpricefilter}unitprice:([500 TO 600])</str></arr><str name=\"version\">2.2</str><str name=\"rows\">100000000</str></lst></lst><result name=\"response\" numFound=\"1\" start=\"0\"><doc><str name=\"id\">65538</str><str name=\"categoryid\">32770</str><float name=\"unitprice\">523.0</float><str name=\"unitprice_c\">523.0000,USD</str><str name=\"name\">Galaxy Note</str><str name=\"url\">home/electronics/phones/galaxy-note</str><long name=\"_version_\">1435991846240124928</long></doc></result><lst name=\"facet_counts\"><lst name=\"facet_queries\"><int name=\"{!label=500-600 ex=unitpricefilter}unitprice:[500 TO 600]\">1</int><int name=\"{!label=601-1000 ex=unitpricefilter}unitprice:[601 TO 1000]\">0</int><int name=\"{!label=500-600-ruledout ex=brandsfilter,manufacturersfilter,unitpricefilter}unitprice:[500 TO 600]\">3</int><int name=\"{!label=601-1000-ruledout ex=brandsfilter,manufacturersfilter,unitpricefilter}unitprice:[601 TO 1000]\">0</int></lst><lst name=\"facet_fields\"><lst name=\"brands\"><int name=\"Smartphones\">1</int><int name=\"LCD televisions\">0</int><int name=\"LED televisions\">0</int><int name=\"Mobile phones\">0</int><int name=\"Plasma televisions\">0</int><int name=\"iPad\">0</int><int name=\"iPhone\">0</int></lst><lst name=\"brandsruledout\"><int name=\"iPhone\">5</int><int name=\"iPad\">3</int><int name=\"Mobile phones\">2</int><int name=\"Smartphones\">2</int><int name=\"LCD televisions\">1</int><int name=\"LED televisions\">1</int><int name=\"Plasma televisions\">1</int></lst><lst name=\"manufacturers\"><int name=\"Samsung\">1</int><int name=\"Apple\">0</int></lst><lst name=\"manufacturersruledout\"><int name=\"Apple\">8</int><int name=\"Samsung\">7</int></lst></lst><lst name=\"facet_dates\"/><lst name=\"facet_ranges\"/></lst></response>",
                @"http://localhost:8983/solr/select?q=*:*&rows=100000000&fq={!tag=brandsfilter}brand_f:(Smartphones)&fq={!tag=manufacturersfilter}manufacturer_f:(Samsung)&fq={!tag=unitpricefilter}unitprice:([500 TO 600])&facet=true&facet.field={!key=brands ex=brandsfilter}brand_f&facet.field={!key=brandsruledout ex=manufacturersfilter,unitpricefilter,brandsfilter}brand_f&facet.field={!key=manufacturers ex=manufacturersfilter}manufacturer_f&facet.field={!key=manufacturersruledout ex=brandsfilter,unitpricefilter,manufacturersfilter}manufacturer_f&facet.query={!label=500-600 ex=unitpricefilter}unitprice:[500 TO 600]&facet.query={!label=601-1000 ex=unitpricefilter}unitprice:[601 TO 1000]&facet.query={!label=500-600-ruledout ex=brandsfilter,manufacturersfilter,unitpricefilter}unitprice:[500 TO 600]&facet.query={!label=601-1000-ruledout ex=brandsfilter,manufacturersfilter,unitpricefilter}unitprice:[601 TO 1000]&version=2.2");

            var querystring = new NameValueCollection
                {
                    {"fb", "Smartphones"},
                    {"fm", "Samsung"},
                    {"fps", "500"},
                    {"fpl", "600"}
                };

            var brandFacet = new BrandFacet(querystring);
            var manufacturerFacet = new ManufacturerFacet(querystring);
            var priceFacet = new PriceFacet(querystring, false, new RangeQuery("500", "600"), new RangeQuery("601", "1000"));

            var facets = new IFacet[]
                {
                    brandFacet,
                    manufacturerFacet,
                    priceFacet
                };

            brandFacet.BuildDependencies(facets);
            manufacturerFacet.BuildDependencies(facets);
            priceFacet.BuildDependencies(facets);

            var brandFacetViewModel = brandFacet.BuildViewModel(results);
            var manufacturerFacetViewModel = manufacturerFacet.BuildViewModel(results);
            var priceFacetViewModel = priceFacet.BuildViewModel(results);

            var expectedBrandValues = new[] {
                new { IsApplied = false, IsDisabled = true, Count = 3, Name = "iPad", Url = string.Empty },
                new { IsApplied = false, IsDisabled = true, Count = 5, Name = "iPhone", Url = string.Empty },
                new { IsApplied = false, IsDisabled = true, Count = 1, Name = "LCD televisions", Url = string.Empty },
                new { IsApplied = false, IsDisabled = true, Count = 1, Name = "LED televisions", Url = string.Empty },
                new { IsApplied = false, IsDisabled = true, Count = 2, Name = "Mobile phones", Url = string.Empty },
                new { IsApplied = false, IsDisabled = true, Count = 1, Name = "Plasma televisions", Url = string.Empty },
                new { IsApplied = true, IsDisabled = false, Count = 1, Name = "Smartphones", Url = "/?fm=Samsung&fps=500&fpl=600" }
            };

            Assert.AreEqual(7, brandFacetViewModel.Constraints.Length);

            for (var index = 0; index < brandFacetViewModel.Constraints.Length; index++)
            {
                Assert.AreEqual(expectedBrandValues[index].IsApplied, brandFacetViewModel.Constraints[index].IsApplied);
                Assert.AreEqual(expectedBrandValues[index].IsDisabled, brandFacetViewModel.Constraints[index].IsDisabled);
                Assert.AreEqual(expectedBrandValues[index].Count, brandFacetViewModel.Constraints[index].Count);
                Assert.AreEqual(expectedBrandValues[index].Name, brandFacetViewModel.Constraints[index].Name);
                Assert.AreEqual(expectedBrandValues[index].Url, brandFacetViewModel.Constraints[index].Url);
            }

            var expectedManufacturerValues = new[] {
                new { IsApplied = false, IsDisabled = true, Count = 8, Name = "Apple", Url = string.Empty },
                new { IsApplied = true, IsDisabled = false, Count = 1, Name = "Samsung", Url = "/?fb=Smartphones&fps=500&fpl=600" }
            };

            Assert.AreEqual(2, manufacturerFacetViewModel.Constraints.Length);

            for (var index = 0; index < manufacturerFacetViewModel.Constraints.Length; index++)
            {
                Assert.AreEqual(expectedManufacturerValues[index].IsApplied, manufacturerFacetViewModel.Constraints[index].IsApplied);
                Assert.AreEqual(expectedManufacturerValues[index].IsDisabled, manufacturerFacetViewModel.Constraints[index].IsDisabled);
                Assert.AreEqual(expectedManufacturerValues[index].Count, manufacturerFacetViewModel.Constraints[index].Count);
                Assert.AreEqual(expectedManufacturerValues[index].Name, manufacturerFacetViewModel.Constraints[index].Name);
                Assert.AreEqual(expectedManufacturerValues[index].Url, manufacturerFacetViewModel.Constraints[index].Url);
            }

            var expectedPriceValues = new[] {
                new { IsApplied = true, IsDisabled = false, Count = 1, Name = string.Format("{0}500.00 - {0}600.00", NumberFormatInfo.CurrentInfo.CurrencySymbol), Url = "/?fb=Smartphones&fm=Samsung" },
                new { IsApplied = false, IsDisabled = true, Count = 0, Name = string.Format("{0}601.00 - {0}1,000.00", NumberFormatInfo.CurrentInfo.CurrencySymbol), Url = string.Empty }
            };

            Assert.AreEqual(2, priceFacetViewModel.Constraints.Length);

            for (var index = 0; index < priceFacetViewModel.Constraints.Length; index++)
            {
                Assert.AreEqual(expectedPriceValues[index].IsApplied, priceFacetViewModel.Constraints[index].IsApplied);
                Assert.AreEqual(expectedPriceValues[index].IsDisabled, priceFacetViewModel.Constraints[index].IsDisabled);
                Assert.AreEqual(expectedPriceValues[index].Count, priceFacetViewModel.Constraints[index].Count);
                Assert.AreEqual(expectedPriceValues[index].Name, priceFacetViewModel.Constraints[index].Name);
                Assert.AreEqual(expectedPriceValues[index].Url, priceFacetViewModel.Constraints[index].Url);
            }
        }