Exemplo n.º 1
0
        public void ComplexOr()
        {
            var condition1A = new StringBooleanCondition("genre", "Sci-Fi");
            var condition1B = new IntBooleanCondition("year");

            condition1B.SetFrom(1990);
            var groupCondition1 = new GroupedCondition(condition1A, ConditionType.AND, condition1B);

            var condition2A = new StringBooleanCondition("genre", "Fantasy");
            var condition2B = new IntBooleanCondition("year");

            condition2B.SetFrom(2013);
            var groupCondition2 = new GroupedCondition(condition2A, ConditionType.AND, condition2B);

            var groupConditionAll = new GroupedCondition(groupCondition1, ConditionType.OR, groupCondition2);

            var bQuery = new BooleanQuery();

            bQuery.Conditions.Add(groupConditionAll);

            _searchQuery = new SearchQuery <Movie> {
                BooleanQuery = bQuery
            };
            string query = _queryBuilder.BuildSearchQuery(_searchQuery);

            query.ShouldContain("(or+(or+(and+genre%3A'Sci-Fi'+year%3A1990..)+(and+genre%3A'Fantasy'+year%3A2013..)))");
        }
Exemplo n.º 2
0
        public void ShouldNotAddToAndConditionIfTheConditionIsAnOrCondition()
        {
            var intBooleanCondition = new IntBooleanCondition("field", 4);

            _booleanQuery.Conditions.Add(intBooleanCondition);
            _queryBuilder.SplitConditions(_booleanQuery, _listOrConditions, _andConditions);
            _andConditions.Length.ShouldEqual(0);
        }
Exemplo n.º 3
0
        public void ShouldAddToOrConditionIfTheConditionIsAnOrCondition()
        {
            var intBooleanCondition = new IntBooleanCondition("field", 4);

            _booleanQuery.Conditions.Add(intBooleanCondition);
            _queryBuilder.SplitConditions(_booleanQuery, _listOrConditions, _andConditions);
            _listOrConditions.Count.ShouldEqual(1);
            _listOrConditions[0].ShouldMatch(intBooleanCondition.GetConditionParam());
        }
Exemplo n.º 4
0
        public void TestSearch()
        {
            var cloudSearch = new CloudSearch <Movie>("YOU_AMAZON_CLOUD_SEARCH_KEY", "2011-02-01");

            //build facet
            var genreFacetContraint = new StringFacetConstraints();

            genreFacetContraint.AddContraint("Sci-Fi");
            genreFacetContraint.AddContraint("Adventure");
            var genreFacet = new Facet {
                Name = "genre", TopResult = 2
            };

            var yearFacetContraint = new IntFacetContraints();

            yearFacetContraint.AddFrom(1950);
            yearFacetContraint.AddInterval(1980, 2012);
            var yearFacet = new Facet {
                Name = "year", FacetContraint = yearFacetContraint
            };

            var liFacet = new List <Facet> {
                genreFacet, yearFacet
            };


            //build boolean query
            var bQuery     = new BooleanQuery();
            var gCondition = new StringBooleanCondition("genre", "Sci-Fi");
            var yCondition = new IntBooleanCondition("year");

            yCondition.SetInterval(1970, 2013);
            bQuery.Conditions.Add(gCondition);
            bQuery.Conditions.Add(yCondition);

            //build search
            var searchQuery = new SearchQuery <Movie> {
                Keyword = "star wars", Facets = liFacet, Size = 20, Start = 0, BooleanQuery = bQuery
            };

            //search
            var found = cloudSearch.Search(searchQuery);

            Assert.IsTrue(!found.IsError);

            Assert.IsTrue(found.hits.found > 0);

            Assert.IsTrue(found.facetsResults.Count > 0);

            Assert.AreEqual(found.facetsResults.Count, 2, "We request only the top 2 facet");
        }
Exemplo n.º 5
0
        public void OrCondition()
        {
            var conditionA = new StringBooleanCondition("genre", "Sci-Fi");
            var conditionB = new IntBooleanCondition("year");

            conditionB.SetFrom(2013);

            var groupCondition = new GroupedCondition(conditionA, ConditionType.OR, conditionB);
            var bQuery         = new BooleanQuery();

            bQuery.Conditions.Add(groupCondition);

            _searchQuery = new SearchQuery <Movie> {
                BooleanQuery = bQuery
            };
            string query = _queryBuilder.BuildSearchQuery(_searchQuery);

            query.ShouldContain("(or+(or+genre%3A'Sci-Fi'+year%3A2013..))");
        }