@@ -1993,29 +1993,139 @@ def testInfoCommandImplied(env):
19931993 env .assertNotEqual (- 1 , d ['index_options' ].index ('NOHL' ))
19941994
19951995def testNoStem (env ):
1996- env .cmd ('ft.create' , 'idx' , 'ON' , 'HASH' ,
1997- 'schema' , 'body' , 'text' , 'name' , 'text' , 'nostem' )
1998- if not env .isCluster ():
1999- # todo: change it to be more generic to pass on isCluster
2000- res = env .cmd ('ft.info' , 'idx' )
2001- env .assertEqual (res [7 ][1 ][8 ], 'NOSTEM' )
1996+ conn = getConnectionByEnv (env )
1997+
1998+ env .expect ('ft.create' , 'idx' , 'ON' , 'HASH' ,
1999+ 'schema' , 'body' , 'text' , 'name' , 'text' , 'nostem' ,
2000+ 'body2' , 'text' , 'name2' , 'text' , 'nostem' ).ok ()
2001+ d = index_info (env , 'idx' )
2002+ env .assertEqual (d ['attributes' ][1 ][8 ],'NOSTEM' )
2003+ env .assertEqual (d ['attributes' ][3 ][8 ],'NOSTEM' )
20022004 for _ in env .reloadingIterator ():
20032005 waitForIndex (env , 'idx' )
20042006 try :
2005- env . cmd ('ft.del' , 'idx' , 'doc' )
2007+ conn . execute_command ('ft.del' , 'idx' , 'doc' )
20062008 except redis .ResponseError :
20072009 pass
20082010
2009- # Insert a document
2010- env .assertCmdOk ('ft.add' , 'idx' , 'doc' , 1.0 , 'fields' ,
2011- 'body' , "located" ,
2012- 'name' , "located" )
2011+ # Insert documents
2012+ conn .execute_command ('HSET' , 'doc1' , 'body' , "located" , 'name' , "located" )
2013+ conn .execute_command ('HSET' , 'doc2' , 'body' , "smith" , 'name' , "smith" )
2014+ conn .execute_command ('HSET' , 'doc3' , 'body' , "smiths" , 'name' , "smiths" )
2015+ conn .execute_command ('HSET' , 'doc4' , 'body' , "cherry" )
2016+ conn .execute_command ('HSET' , 'doc5' , 'body' , "cherries" )
2017+ conn .execute_command ('HSET' , 'doc6' , 'name' , "candy" )
2018+ conn .execute_command ('HSET' , 'doc7' , 'name' , "candies" )
2019+ conn .execute_command ('HSET' , 'doc8' , 'body2' , "cherries" )
2020+ conn .execute_command ('HSET' , 'doc9' , 'name2' , "candies" )
20132021
20142022 # Now search for the fields
2015- res_body = env .cmd ('ft.search' , 'idx' , '@body:location' )
2016- res_name = env .cmd ('ft.search' , 'idx' , '@name:location' )
2017- env .assertEqual (0 , res_name [0 ])
2023+ res_body = conn .execute_command ('ft.search' , 'idx' , '@body:location' )
20182024 env .assertEqual (1 , res_body [0 ])
2025+ res_name = conn .execute_command ('ft.search' , 'idx' , '@name:location' )
2026+ env .assertEqual (0 , res_name [0 ])
2027+
2028+ res_body = conn .execute_command ('ft.search' , 'idx' , '@body:smith' )
2029+ env .assertEqual (2 , res_body [0 ])
2030+ res_name = conn .execute_command ('ft.search' , 'idx' , '@name:smith' )
2031+ env .assertEqual (1 , res_name [0 ])
2032+
2033+ res_body = conn .execute_command ('ft.search' , 'idx' , '@body:smiths' )
2034+ env .assertEqual (2 , res_body [0 ])
2035+ res_name = conn .execute_command ('ft.search' , 'idx' , '@name:smiths' )
2036+ env .assertEqual (1 , res_name [0 ])
2037+
2038+ # Test modifier list
2039+ # 2 results are returned because 'body' field is stemming 'cherry'
2040+ res = conn .execute_command ('ft.search' , 'idx' , '@body|name:cherry' )
2041+ env .assertEqual (2 , res [0 ])
2042+ res = conn .execute_command ('ft.search' , 'idx' , '@body|name:cherries' )
2043+ env .assertEqual (2 , res [0 ])
2044+
2045+ # only 1 result is returned because 'name' field is not stemming
2046+ res = conn .execute_command ('ft.search' , 'idx' , '@body|name:candy' )
2047+ env .assertEqual (1 , res [0 ])
2048+ res = conn .execute_command ('ft.search' , 'idx' , '@body|name:candies' )
2049+ env .assertEqual (1 , res [0 ])
2050+
2051+ # 3 results are returned because 'body' field is stemming 'candy'
2052+ # but 'name' field is not stemming
2053+ res = conn .execute_command (
2054+ 'ft.search' , 'idx' ,'@body|name:(candy|cherry)' , 'dialect' , 2 )
2055+ env .assertEqual (3 , res [0 ])
2056+ res2 = conn .execute_command (
2057+ 'ft.search' , 'idx' ,'@body:(candy|cherry) | @name:(candy|cherry)' ,
2058+ 'dialect' , 2 )
2059+ env .assertEqual (res , res2 )
2060+
2061+ res = conn .execute_command (
2062+ 'ft.search' , 'idx' , '@body|name:(candies|cherries)' , 'dialect' , 2 )
2063+ env .assertEqual (3 , res [0 ])
2064+ res2 = conn .execute_command (
2065+ 'ft.search' , 'idx' , '@body:(candies|cherries) | @name:(candies|cherries)' ,
2066+ 'dialect' , 2 )
2067+ env .assertEqual (res , res2 )
2068+
2069+ # Test explaincli single field stemming
2070+ env .expect ('ft.explain' , 'idx' , '@body:candy' ).equal (r'''
2071+ @body:UNION {
2072+ @body:candy
2073+ @body:+candi(expanded)
2074+ @body:candi(expanded)
2075+ }
2076+ ''' [1 :])
2077+
2078+ # Test explaincli with modifier list fields, all fields expanded
2079+ env .expect ('ft.explain' , 'idx' , '@body|body2:candy' ).equal (r'''
2080+ @body|body2:UNION {
2081+ @body|body2:candy
2082+ @body|body2:+candi(expanded)
2083+ @body|body2:candi(expanded)
2084+ }
2085+ ''' [1 :])
2086+
2087+ # Test explaincli single field with NOSTEM
2088+ env .expect ('ft.explain' , 'idx' , '@name:candy' ).equal (r'''
2089+ @name:candy
2090+ ''' [1 :])
2091+
2092+ # Test explaincli with modifier list NOSTEM fields
2093+ env .expect ('ft.explain' , 'idx' , '@name|name2:candy' ).equal (r'''
2094+ @name|name2:candy
2095+ ''' [1 :])
2096+
2097+ # Mixing NOSTEM and stemming fields in the same modifier list
2098+ env .expect ('ft.explain' , 'idx' , '@body|name:candy' ).equal (r'''
2099+ @body|name:UNION {
2100+ @body|name:candy
2101+ @body:+candi(expanded)
2102+ @body:candi(expanded)
2103+ }
2104+ ''' [1 :])
2105+
2106+ env .expect ('ft.explain' , 'idx' , '@name2|body|name:candy' ).equal (r'''
2107+ @body|name|name2:UNION {
2108+ @body|name|name2:candy
2109+ @body:+candi(expanded)
2110+ @body:candi(expanded)
2111+ }
2112+ ''' [1 :])
2113+
2114+ env .expect ('ft.explain' , 'idx' , '@body2|body|name:candy' ).equal (r'''
2115+ @body|name|body2:UNION {
2116+ @body|name|body2:candy
2117+ @body|body2:+candi(expanded)
2118+ @body|body2:candi(expanded)
2119+ }
2120+ ''' [1 :])
2121+
2122+ env .expect ('ft.explain' , 'idx' , '@body2|body|name|name2:candy' ).equal (r'''
2123+ @body|name|body2|name2:UNION {
2124+ @body|name|body2|name2:candy
2125+ @body|body2:+candi(expanded)
2126+ @body|body2:candi(expanded)
2127+ }
2128+ ''' [1 :])
20192129
20202130def testSortbyMissingField (env ):
20212131 # GH Issue 131
0 commit comments