Exemplo n.º 1
0
        public void BuildAFacetViewModelWithMultipleConstraintAppliedWhereQueryParametersAreSortedInOrder()
        {
            var results =
                SolrNetFacetTestFramework.RunSolrGetResults(
                "<?xml version=\"1.0\" encoding=\"UTF-8\"?><response><lst name=\"responseHeader\"><int name=\"status\">0</int><int name=\"QTime\">473</int><lst name=\"params\"><str name=\"facet\">true</str><str name=\"q\">*:*</str><str name=\"facet.field\">{!key=brands ex=brandsfilter}brand_f</str><str name=\"fq\">{!tag=brandsfilter}brand_f:(iPhone OR LCD televisions OR LED televisions OR Smartphones)</str><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><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)&facet=true&facet.field={!key=brands+ex=brandsfilter}brand_f&version=2.2");

            var queryOptions = new QueryOptions();

            var brandFacet = new BrandFacet(new NameValueCollection
                {
                    {"fb", "Smartphones"},
                    {"fb", "iPhone"},
                    {"fb", "LCD televisions"},
                    {"fb", "LED televisions"}
                });

            brandFacet.BuildQuery(queryOptions);

            var brandFacetViewModel = brandFacet.BuildViewModel(results);

            var expectedBrandValues = new[] {
                new { Name = "iPad"},
                new { Name = "iPhone"},
                new { Name = "LCD televisions" },
                new { Name = "LED televisions" },
                new { Name = "Mobile phones" },
                new { Name = "Plasma televisions" },
                new { Name = "Smartphones" }
            };

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

            for (var index = 0; index < brandFacetViewModel.Constraints.Length; index++)
            {
                Assert.AreEqual(expectedBrandValues[index].Name, brandFacetViewModel.Constraints[index].Name);
            }
        }
Exemplo n.º 2
0
        public void CreateTwoFacetsWithOneBeingARangeFacetThatBothHaveMultipleConstraintsApplied()
        {
            SolrNetFacetTestFramework.RunSolrUrlCreationTest(@"http://localhost:8983/solr/select?q=*:*&rows=100000000&fq={!tag=unitpricefilter}unitprice:([*+TO+99.99]+OR+[100+TO+499.99])&fq={!tag=brandsfilter}brand_f:(iPhone+OR+LCD+televisions+OR+LED+televisions+OR+Smartphones)&facet=true&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,unitpricefilter}unitprice:[*+TO+99.99]&facet.query={!label=100-499.99-ruledout\+ex=brandsfilter,unitpricefilter}unitprice:[100+TO+499.99]&facet.field={!key=brands+ex=brandsfilter}brand_f&facet.field={!key=brandsruledout+ex=unitpricefilter,brandsfilter}brand_f&version=2.2", solr =>
            {
                var querystring = new NameValueCollection
                            {
                                {"fps", "*"},
                                {"fpl", "99.99"},
                                {"fps", "100"},
                                {"fpl", "499.99"},
                                {"fb", "Smartphones"},
                                {"fb", "iPhone"},
                                {"fb", "LCD televisions"},
                                {"fb", "LED televisions"}
                            };

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

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

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

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

                return solr.Query(SolrQuery.All, queryOptions);
            });
        }
Exemplo n.º 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);
            });
        }
Exemplo n.º 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);
            });
        }
Exemplo n.º 5
0
        public void CreateASingleSelectionFacetThatWillOnlyApplyTheFirstConstraintWhenMultipleConstraintsHaveBeenPassedInToBeApplied()
        {
            SolrNetFacetTestFramework.RunSolrUrlCreationTest(@"http://localhost:8983/solr/select?q=*:*&rows=100000000&fq={!tag=brandsfilter}brand_f:(iPhone)&facet=true&facet.field={!key=brands+ex=brandsfilter}brand_f&version=2.2", solr =>
            {
                var querystring = new NameValueCollection
                {
                    {"fb", "Smartphones"},
                    {"fb", "iPhone"},
                    {"fb", "LCD televisions"},
                    {"fb", "LED televisions"}
                };

                var queryOptions = new QueryOptions();
                var facet = new BrandFacet(querystring, true);

                facet.BuildQuery(queryOptions);

                return solr.Query(SolrQuery.All, queryOptions);
            });
        }
Exemplo n.º 6
0
        public void CreateAFacetWithOneConstraintApplied()
        {
            SolrNetFacetTestFramework.RunSolrUrlCreationTest(@"http://localhost:8983/solr/select?q=*:*&rows=100000000&fq={!tag=brandsfilter}brand_f:(Smartphones)&facet=true&facet.field={!key=brands+ex=brandsfilter}brand_f&version=2.2", solr =>
            {
                var queryOptions = new QueryOptions();
                var facet = new BrandFacet(new NameValueCollection
                {
                    {"fb", "Smartphones"}
                });

                facet.BuildQuery(queryOptions);

                return solr.Query(SolrQuery.All, queryOptions);
            });
        }
Exemplo n.º 7
0
        public void CreateAFacetWithNoConstraintsApplied()
        {
            SolrNetFacetTestFramework.RunSolrUrlCreationTest(@"http://localhost:8983/solr/select?q=*:*&rows=100000000&facet=true&facet.field={!key=brands}brand_f&version=2.2", solr =>
            {
                var queryOptions = new QueryOptions();
                var facet = new BrandFacet(new NameValueCollection());

                facet.BuildQuery(queryOptions);

                return solr.Query(SolrQuery.All, queryOptions);
            });
        }
Exemplo n.º 8
0
        public void CreateAFacetWithMultipleConstraintAppliedWhereQueryParametersAreSortedInOrder()
        {
            SolrNetFacetTestFramework.RunSolrUrlCreationTest(@"http://localhost:8983/solr/select?q=*:*&rows=100000000&fq={!tag=brandsfilter}brand_f:(iPhone+OR+LCD+televisions+OR+LED+televisions+OR+Smartphones)&facet=true&facet.field={!key=brands+ex=brandsfilter}brand_f&version=2.2", solr =>
            {
                var queryOptions = new QueryOptions();
                var facet = new BrandFacet(new NameValueCollection
                {
                    {"fb", "Smartphones"},
                    {"fb", "iPhone"},
                    {"fb", "LCD televisions"},
                    {"fb", "LED televisions"}
                });

                facet.BuildQuery(queryOptions);

                return solr.Query(SolrQuery.All, queryOptions);
            });
        }
Exemplo n.º 9
0
        public void BuildSingleSelectionFacetViewModelThatWillOnlyApplyTheFirstConstraintWhenMultipleConstraintsHaveBeenPassedInToBeApplied()
        {
            var results =
                SolrNetFacetTestFramework.RunSolrGetResults(
                "<?xml version=\"1.0\" encoding=\"UTF-8\"?><response><lst name=\"responseHeader\"><int name=\"status\">0</int><int name=\"QTime\">1</int><lst name=\"params\"><str name=\"facet\">true</str><str name=\"q\">*:*</str><str name=\"facet.field\">{!key=brands ex=brandsfilter}brand_f</str><str name=\"fq\">{!tag=brandsfilter}brand_f:(iPhone)</str><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\">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></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><lst name=\"facet_dates\"/><lst name=\"facet_ranges\"/></lst></response>",
                @"http://localhost:8983/solr/select?q=*:*&rows=100000000&fq={!tag=brandsfilter}brand_f:(iPhone)&facet=true&facet.field={!key=brands+ex=brandsfilter}brand_f&version=2.2");

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

            var queryOptions = new QueryOptions();
            var brandFacet = new BrandFacet(querystring, true);

            brandFacet.BuildQuery(queryOptions);

            var brandFacetViewModel = brandFacet.BuildViewModel(results);

            var expectedBrandValues = new[] {
                new { IsApplied = false, IsDisabled = true, Count = 3, Name = "iPad", Url = string.Empty },
                new { IsApplied = true, IsDisabled = false, Count = 5, Name = "iPhone", Url = "/" },
                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 = false, IsDisabled = true, Count = 2, Name = "Smartphones", Url = string.Empty }
            };

            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);
            }
        }