Пример #1
0
def test_create_bool_with_multiple_clauses():
    """
    Create Bool Block with Multiple Clauses
    """
    # When I create a Bool block
    t = Bool()

    # And add multiple conditions
    t.must_not(Term("foo", "foo"))\
     .must(Term("bar", "bar"))\
     .should(Term("baz", "baz"))\
     .should(Term("foobar", "foobar"))

    # Then I see the appropriate JSON
    results = {
        "bool": {
            "must_not": [
                {
                    "term": {
                        "foo": "foo"
                    }
                }
            ],
            "must": [
                {
                    "term": {
                        "bar": "bar"
                    }
                }
            ],
            "should": [
                {
                    "term": {
                        "baz": "baz"
                    }
                },
                {
                    "term": {
                        "foobar": "foobar"
                    }
                },
            ]
        }
    }

    homogeneous(t, results)
def test_simple_search_with_boolean_should(context):
    """
    Search with boolean should
    """
    # When create a queryset
    t = QuerySet("localhost", index="foo")

    # And there are records
    add_document("foo", {"bar": "baz"})
    add_document("foo", {"bar": "bazbaz"})

    # And I do a filtered search
    b = Bool()
    b.should(Term("bar", "baz"))
    t.filter(b)
    results = t[0:10]

    # Then I get a the expected results
    len(results).should.equal(1)
    results[0]['_source'].should.equal({"bar": "baz"})
Пример #3
0
def test_create_bool_with_should():
    """
    Create Bool Block with Should
    """
    # When I create a Bool block
    t = Bool()

    # And add a 'should' condition with a Term
    t.should(Term("foo", "bar"))

    # Then I see the appropriate JSON
    results = {
        "bool": {
            "should": [
                {
                    "term": {
                        "foo": "bar"
                    }
                }
            ]
        }
    }

    homogeneous(t, results)
Пример #4
0
def test_create_bool_with_must_not():
    """
    Create Bool Block with Must Not
    """
    # When I create a Bool block
    t = Bool()

    # And add a 'must_not' condition with a Term
    t.must_not(Term("foo", "bar"))

    # Then I see the appropriate JSON
    results = {
        "bool": {
            "must_not": [
                {
                    "term": {
                        "foo": "bar"
                    }
                }
            ]
        }
    }

    homogeneous(t, results)