def test_can_sort_with_multiple_orderings(self):
        manager = self.store.query(Scene)
        qs = manager.order_by(Scene.speaker, ~Scene.line_id)
        expected = {'sort': 'speaker:asc,line_id:desc'}
        builder = elasticsearch.ES2QueryStringBuilder()

        self.assertEqual(builder.build(orderings=qs.query.orderings), expected)
    def test_can_compile_and_filters_eq(self):
        manager = self.store.query(Scene)
        qs = manager.filter(Scene.speaker == 'LEONTES', Scene.line_id == 422)

        expected = {'q': '(speaker:"LEONTES" AND line_id:422)'}
        builder = elasticsearch.ES2QueryStringBuilder()

        self.assertEqual(builder.build(qs.query.filters), expected)
    def test_can_compile_filter_eq(self):
        manager = self.store.query(Scene)
        qs = manager.filter(Scene.speaker == 'LEONTES')

        expected = {'q': 'speaker:"LEONTES"'}
        builder = elasticsearch.ES2QueryStringBuilder()

        self.assertEqual(builder.build(qs.query.filters), expected)
    def test_can_compile_three_filters_or_eq(self):
        manager = self.store.query(Scene)
        qs = manager.filter((Scene.speaker == 'LEONTES') | (Scene.line_id == 1)
                            | (Scene.play == 'henry'))

        expected = {'q': '(speaker:"LEONTES" OR line_id:1 OR play:"henry")'}
        builder = elasticsearch.ES2QueryStringBuilder()

        self.assertEqual(builder.build(qs.query.filters), expected)
 def test_can_sort_with_single_ordering(self):
     manager = self.store.query(Scene)
     qs = manager.order_by(Scene.speaker)
     expected = {'sort': 'speaker:asc    '}
     builder = elasticsearch.ES2QueryStringBuilder()