示例#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)
示例#2
0
 def add_comment(self, comment):
     with OptionsCtx(
         'comment', comment
     ).with_config(self.config) as lex:
         if lex:
             self.options.append(lex)
示例#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)
示例#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)
示例#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)
示例#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)
示例#7
0
 def add_cutoff(self, cutoff):
     with OptionsCtx(
         'cutoff', cutoff
     ).with_config(self.config) as lex:
         if lex:
             self.options.append(lex)
示例#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)
示例#9
0
 def add_ranker(self, ranker):
     with OptionsCtx(
         'ranker', ranker
     ).with_config(self.config) as lex:
         if lex:
             self.options.append(lex)
示例#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)
示例#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: