示例#1
0
    def test_it(self):
        from csquery.structured import field, not_, or_, term

        actual = self._call_fut(title='star',
                                actors='Harrison Ford', year=('', 2000))
        expected = "(and actors:'Harrison Ford' title:'star' year:{,2000])"
        assert expected == actual()

        actual = self._call_fut({'title': 'star'}, {'title': 'star2'})
        assert "(and title:'star' title:'star2')" == actual()

        actual = self._call_fut(field('star', 'title'),
                                field('star2', 'title'))
        assert "(and title:'star' title:'star2')" == actual()

        actual = self._call_fut({'title': 'star'}, {'title': 'star2'}, boost=2)
        assert "(and boost=2 title:'star' title:'star2')" == actual()

        # complex query
        actual = self._call_fut(
            not_('テスト', field='genres'),
            or_(
                term('star', field='title', boost=2),
                term('star', field='plot'),

            ),
            boost='plot'
        )
        expected = "(and boost=plot (not field=genres 'テスト') "
        expected += "(or (term field=title boost=2 'star') "
        expected += "(term field=plot 'star')))"
        assert expected == actual()
示例#2
0
    def test_it(self):
        from csquery.structured import field

        actual = self._call_fut(title='star',
                                actors='Harrison Ford', year=('', 2000))
        expected = "(or actors:'Harrison Ford' title:'star' year:{,2000])"
        assert expected == actual()

        actual = self._call_fut({'title': 'star'}, {'title': 'star2'})
        assert "(or title:'star' title:'star2')" == actual()

        actual = self._call_fut(field('star', 'title'),
                                field('star2', 'title'))
        assert "(or title:'star' title:'star2')" == actual()

        actual = self._call_fut({'title': 'star'}, {'title': 'star2'}, boost=2)
        assert "(or boost=2 title:'star' title:'star2')" == actual()
示例#3
0
    def test_it(self):
        from csquery.structured import Expression, field

        assert '[1900,2000]' == self._call_fut([1900, 2000])
        assert "(and title:'star')" == self._call_fut(
            Expression('and', title='star')
        )
        assert '[1900,2000]' == self._call_fut('[1900,2000]')
        assert '{,2000]' == self._call_fut('{,2000]')
        assert '[1900,}' == self._call_fut('[1900,}')
        assert "'test'" == self._call_fut("'test'")
        assert 'field=test' == self._call_fut('field=test')
        assert '1' == self._call_fut(1)
        assert "actors:'Alec Guinness'" == self._call_fut(
            field('Alec Guinness', 'actors')
        )
        assert "'test'" == self._call_fut('test')

        # escape value
        assert r"(and title:'st\\ar')" == self._call_fut(
            Expression('and', title=r'st\ar')
        )
        assert "(and title:'st\'ar')" == self._call_fut(
            Expression('and', title="st'ar")
        )

        assert r"'te\\st'" == self._call_fut(r"'te\st'")
        assert "'te\'st'" == self._call_fut("'te'st'")

        assert r"field=te\\st" == self._call_fut(r"field=te\st")
        assert "field=te\'st" == self._call_fut("field=te'st")

        assert r"actors:'Alec\\Guinness'" == self._call_fut(
            field(r'Alec\Guinness', 'actors')
        )
        assert "actors:'Alec\'Guinness'" == self._call_fut(
            field("Alec'Guinness", 'actors')
        )
示例#4
0
    def test_it_for_escape(self):
        from csquery.structured import Expression, field

        assert r"(and title:'st\\ar')" == self._call_fut(
            Expression('and', title=r'st\ar')
        )
        assert r"(and title:'st\'ar')" == self._call_fut(
            Expression('and', title="st'ar")
        )

        assert r"'te\\st'" == self._call_fut(r"te\st")
        assert r"'te\'st'" == self._call_fut("te'st")

        assert r"actors:'Alec\\Guinness'" == self._call_fut(
            field(r'Alec\Guinness', 'actors')
        )
        assert r"actors:'Alec\'Guinness'" == self._call_fut(
            field("Alec'Guinness", 'actors')
        )

        assert "'ジャン=ピエール・オーモン'" == self._call_fut(
            'ジャン=ピエール・オーモン'
        )
示例#5
0
    def test_it(self):
        from csquery.structured import Expression, field

        assert '[1900,2000]' == self._call_fut([1900, 2000])
        assert "(and title:'star')" == self._call_fut(
            Expression('and', title='star')
        )
        assert '[1900,2000]' == self._call_fut('[1900,2000]')
        assert '{,2000]' == self._call_fut('{,2000]')
        assert '[1900,}' == self._call_fut('[1900,}')
        assert '1' == self._call_fut(1)
        assert "actors:'Alec Guinness'" == self._call_fut(
            field('Alec Guinness', 'actors')
        )
        assert "'test'" == self._call_fut('test')