Exemple #1
0
 def test_fulltext_options(self):
     # pass in options for a full-text query
     xq = Xquery(xpath='/el', fulltext_options={'default-operator': 'and'})
     xq.add_filter('.', 'fulltext_terms', 'dog')
     self.assertTrue(
         '<default-operator>and</default-operator>' in xq.getQuery())
     self.assertTrue('/el[ft:query(., "dog", $ft_options)]', xq.getQuery())
Exemple #2
0
    def test_filter_exists(self):
        xq = Xquery(xpath='/el')
        xq.add_filter('@id', 'exists', True)
        self.assertEqual('/el[@id]', xq.getQuery())

        xq = Xquery(xpath='/el')
        xq.add_filter('@id', 'exists', False)
        self.assertEqual('/el[not(@id)]', xq.getQuery())
Exemple #3
0
 def test_filters(self):
     xq = Xquery(xpath='/el')
     xq.add_filter('.', 'contains', 'dog')
     self.assertEqual('/el[contains(., "dog")]', xq.getQuery())
     # filters are additive
     xq.add_filter('.', 'startswith', 'S')
     self.assertEqual('/el[contains(., "dog")][starts-with(., "S")]',
                      xq.getQuery())
Exemple #4
0
    def test_not_filters(self):
        xq = Xquery(xpath='/el')
        xq.add_filter('.', 'contains', 'dog', mode='NOT')
        self.assertEqual('/el[not(contains(., "dog"))]', xq.getQuery())

        xq = Xquery(xpath='/el')
        xq.add_filter('.', 'contains', 'dog', mode='NOT')
        xq.add_filter('.', 'startswith', 'S', mode='NOT')
        self.assertEqual(
            '/el[not(contains(., "dog")) and not(starts-with(., "S"))]',
            xq.getQuery())
Exemple #5
0
    def test_filter_in(self):
        xq = Xquery(xpath='/el')
        xq.add_filter('@id', 'in', ['a', 'b', 'c'])
        self.assertEqual('/el[@id="a" or @id="b" or @id="c"]', xq.getQuery())

        # filter on a 'special' field - requires let & where statements
        xq = Xquery(xpath='/el')
        xq.add_filter('document_name', 'in', ['a.xml', 'b.xml'])
        self.assertTrue('let $document_name' in xq.getQuery())
        self.assertTrue(
            'where $document_name="a.xml" or $document_name="b.xml"' in
            xq.getQuery())
Exemple #6
0
    def test_filter_gtlt(self):
        xq = Xquery(xpath='/el')
        xq.add_filter('@id', 'gt', 5)
        self.assertTrue('el[@id > 5]' in xq.getQuery())

        xq = Xquery(xpath='/el')
        xq.add_filter('@id', 'gte', 5)
        self.assertTrue('/el[@id >= 5]' in xq.getQuery())

        xq.add_filter('@id', 'lt', '10')
        self.assertTrue('el[@id >= 5]' in xq.getQuery())
        self.assertTrue('[@id < "10"]' in xq.getQuery())

        xq.add_filter('@id', 'lte', 3)
        self.assertTrue('[@id <= 3]' in xq.getQuery())
Exemple #7
0
 def test_return_also__highlight(self):
     xq = Xquery(xpath='/el')
     xq.xq_var = '$n'
     xq.return_also({'fulltext_score': ''})
     xq.add_filter('.', 'highlight', 'dog star')
     self.assertTrue('(/el[ft:query(., "dog star")]|/el)' in xq.getQuery())
Exemple #8
0
 def test_or_filters(self):
     xq = Xquery(xpath='/el')
     xq.add_filter('.', 'contains', 'dog', mode='OR')
     xq.add_filter('.', 'startswith', 'S', mode='OR')
     self.assertEqual('/el[contains(., "dog") or starts-with(., "S")]',
                      xq.getQuery())
Exemple #9
0
 def test_filter_escaping(self):
     xq = Xquery(xpath='/el')
     xq.add_filter('.', 'contains', '"&')
     self.assertEqual('/el[contains(., """&amp;")]', xq.getQuery())
Exemple #10
0
 def test_filters_highlight(self):
     xq = Xquery(xpath='/el')
     xq.add_filter('.', 'highlight', 'dog star')
     self.assertEqual('util:expand((/el[ft:query(., "dog star")]|/el))',
                      xq.getQuery())
Exemple #11
0
 def test_filters_fulltext(self):
     xq = Xquery(xpath='/el')
     xq.add_filter('.', 'fulltext_terms', 'dog')
     self.assertEqual('/el[ft:query(., "dog")]', xq.getQuery())