Exemplo n.º 1
0
 def add_reverse_scan(self, is_reverse=True):
     with OptionsCtx(
         'reverse_scan', is_reverse
     ).with_config(self.config) as lex:
         if lex:
             self.options.append(lex)
Exemplo n.º 2
0
 def add_comment(self, comment):
     with OptionsCtx(
         'comment', comment
     ).with_config(self.config) as lex:
         if lex:
             self.options.append(lex)
Exemplo n.º 3
0
 def add_retry_delay(self, retry_delay):
     with OptionsCtx(
         'retry_delay', retry_delay
     ).with_config(self.config) as lex:
         if lex:
             self.options.append(lex)
Exemplo n.º 4
0
 def add_index_weights(self, **kwargs):
     with OptionsCtx(
         'index_weights', kwargs
     ).with_config(self.config) as lex:
         if lex:
             self.options.append(lex)
Exemplo n.º 5
0
 def add_max_query_time(self, max_query_time):
     with OptionsCtx(
         'max_query_time', max_query_time
     ).with_config(self.config) as lex:
         if lex:
             self.options.append(lex)
Exemplo n.º 6
0
 def add_retry_count(self, retry_count):
     with OptionsCtx(
         'retry_count', retry_count
     ).with_config(self.config) as lex:
         if lex:
             self.options.append(lex)
Exemplo n.º 7
0
 def add_cutoff(self, cutoff):
     with OptionsCtx(
         'cutoff', cutoff
     ).with_config(self.config) as lex:
         if lex:
             self.options.append(lex)
Exemplo n.º 8
0
 def add_max_matches(self, max_matches):
     with OptionsCtx(
         'max_matches', max_matches
     ).with_config(self.config) as lex:
         if lex:
             self.options.append(lex)
Exemplo n.º 9
0
 def add_ranker(self, ranker):
     with OptionsCtx(
         'ranker', ranker
     ).with_config(self.config) as lex:
         if lex:
             self.options.append(lex)
Exemplo n.º 10
0
 def set_options(self, **kwargs):
     for option, params in kwargs.items():
         with OptionsCtx(option, params).with_config(self.config) as lex:
             if lex:
                 self.options.append(lex)
Exemplo n.º 11
0
        )
        self.assertRaises(
            SphinxQLSyntaxException,
            lambda: OrderCtxStrict('name', 'DEC').__enter__()
        )
        self.assertRaises(
            SphinxQLSyntaxException,
            lambda: OrderCtxStrict(42, 'ASC').__enter__()
        )
        self.assertRaises(
            SphinxQLSyntaxException,
            lambda: OrderCtxStrict('asc', '').__enter__()
        )


OptionsCtxSoft = lambda x, y: OptionsCtx(x, y).with_config(ProductionConfig)
OptionsCtxStrict = lambda x, y: OptionsCtx(x, y).with_config(DebugConfig)

class TestOptionsCtx(unittest.TestCase):

    def test_get_ranker_valid_attrs(self):
        with OptionsCtxSoft('ranker', 'proximity_bm25') as lex:
            self.assertEqual(lex, 'ranker=proximity_bm25')

        with OptionsCtxSoft('ranker', 'bm25') as lex:
            self.assertEqual(lex, 'ranker=bm25')

        with OptionsCtxSoft('ranker', 'none') as lex:
            self.assertEqual(lex, 'ranker=none')

        with OptionsCtxSoft('ranker', 'wordcount') as lex: