/
test_phonetics.py
78 lines (66 loc) · 4.95 KB
/
test_phonetics.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import redis
import unittest
from hotels import hotels
import random
import time
from base_case import BaseSearchTestCase
class PhoneticsTestCase(BaseSearchTestCase):
def testBasicPoneticCase(self):
self.assertOk(self.cmd('ft.create', 'idx', 'schema', 'text', 'TEXT', 'PHONETIC', 'dm:en', 'SORTABLE'))
self.assertOk(self.cmd('ft.add', 'idx', 'doc1', 1.0, 'fields',
'text', 'morfix'))
self.assertEquals(self.cmd('ft.search', 'idx', 'morphix'), [1L, 'doc1', ['text', 'morfix']])
self.assertEquals(self.cmd('ft.search', 'idx', '@text:morphix'), [1L, 'doc1', ['text', 'morfix']])
self.assertEquals(self.cmd('ft.search', 'idx', '@text:morphix=>{$phonetic:true}'), [1L, 'doc1', ['text', 'morfix']])
self.assertEquals(self.cmd('ft.search', 'idx', '@text:morphix=>{$phonetic:false}'), [0L])
def testBasicPoneticWrongDeclaration(self):
with self.assertResponseError():
self.cmd('ft.create', 'idx', 'schema', 'text', 'TEXT', 'PHONETIC', 'something', 'SORTABLE')
with self.assertResponseError():
self.cmd('ft.create', 'idx', 'schema', 'text', 'TEXT', 'PHONETIC', 'kk:tt', 'SORTABLE')
with self.assertResponseError():
self.cmd('ft.create', 'idx', 'schema', 'text', 'TEXT', 'PHONETIC', 'dm:tt', 'SORTABLE')
with self.assertResponseError():
self.cmd('ft.create', 'idx', 'schema', 'text', 'TEXT', 'PHONETIC', 'll:en', 'SORTABLE')
def testPoneticOnNonePhoneticField(self):
self.assertOk(self.cmd('ft.create', 'idx', 'schema', 'text', 'TEXT', 'PHONETIC', 'dm:en', 'SORTABLE', 'text1', 'TEXT', 'SORTABLE'))
self.assertOk(self.cmd('ft.add', 'idx', 'doc1', 1.0, 'fields',
'text', 'morfix',
'text1', 'phonetic'))
self.assertEquals(self.cmd('ft.search', 'idx', 'morphix'), [1L, 'doc1', ['text', 'morfix', 'text1', 'phonetic']])
self.assertEquals(self.cmd('ft.search', 'idx', '@text:morphix'), [1L, 'doc1', ['text', 'morfix', 'text1', 'phonetic']])
self.assertEquals(self.cmd('ft.search', 'idx', 'phonetic'), [1L, 'doc1', ['text', 'morfix', 'text1', 'phonetic']])
self.assertEquals(self.cmd('ft.search', 'idx', 'fonetic'), [0L])
self.assertEquals(self.cmd('ft.search', 'idx', '@text1:morphix'), [0L])
with self.assertResponseError():
self.cmd('ft.search', 'idx', '@text1:morphix=>{$phonetic:true}')
with self.assertResponseError():
self.cmd('ft.search', 'idx', '@text1:morphix=>{$phonetic:false}')
def testPoneticWithAggregation(self):
self.assertOk(self.cmd('ft.create', 'idx', 'schema', 'text', 'TEXT', 'PHONETIC', 'dm:en', 'SORTABLE', 'text1', 'TEXT', 'SORTABLE'))
self.assertOk(self.cmd('ft.add', 'idx', 'doc1', 1.0, 'fields',
'text', 'morfix',
'text1', 'phonetic'))
self.assertEquals(self.cmd('ft.aggregate', 'idx', 'morphix', 'LOAD', 2, '@text', '@text1'), [1L, ['text', 'morfix', 'text1', 'phonetic']])
self.assertEquals(self.cmd('ft.aggregate', 'idx', '@text:morphix', 'LOAD', 2, '@text', '@text1'), [1L, ['text', 'morfix', 'text1', 'phonetic']])
self.assertEquals(self.cmd('ft.aggregate', 'idx', 'phonetic', 'LOAD', 2, '@text', '@text1'), [1L, ['text', 'morfix', 'text1', 'phonetic']])
self.assertEquals(self.cmd('ft.aggregate', 'idx', '@text1:morphix', 'LOAD', 2, '@text', '@text1'), [0L])
if not self.is_cluster():
with self.assertResponseError():
self.cmd('ft.aggregate', 'idx', '@text1:morphix=>{$phonetic:true}')
with self.assertResponseError():
self.cmd('ft.aggregate', 'idx', '@text1:morphix=>{$phonetic:false}')
else:
self.skipTest("FIXME: Aggregation error propagation broken on cluster mode")
def testPoneticWithSchemaAlter(self):
self.assertOk(self.cmd('ft.create', 'idx', 'schema', 'text', 'TEXT', 'PHONETIC', 'dm:en', 'SORTABLE', 'text1', 'TEXT', 'SORTABLE'))
self.assertOk(self.cmd('ft.alter', 'idx', 'SCHEMA', 'ADD', 'text2', 'TEXT', 'PHONETIC', 'dm:en'))
self.assertOk(self.cmd('ft.add', 'idx', 'doc1', 1.0, 'fields',
'text', 'morfix',
'text1', 'check',
'text2', 'phonetic'))
self.assertEquals(self.cmd('ft.search', 'idx', 'fonetic'), [1L, 'doc1', ['text', 'morfix', 'text1', 'check', 'text2', 'phonetic']])
self.assertEquals(self.cmd('ft.search', 'idx', '@text2:fonetic'), [1L, 'doc1', ['text', 'morfix', 'text1', 'check', 'text2', 'phonetic']])
self.assertEquals(self.cmd('ft.search', 'idx', '@text1:fonetic'), [0L])
self.assertEquals(self.cmd('ft.search', 'idx', '@text2:fonetic=>{$phonetic:false}'), [0L])
self.assertEquals(self.cmd('ft.search', 'idx', '@text2:fonetic=>{$phonetic:true}'), [1L, 'doc1', ['text', 'morfix', 'text1', 'check', 'text2', 'phonetic']])