示例#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..)))");
        }
示例#2
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..))");
        }