@@ -12,7 +12,6 @@ test_that("basic search works", {
12
12
})
13
13
14
14
test_that(" search for document type works" , {
15
-
16
15
b <- Search(index = " shakespeare" , type = " line" )
17
16
expect_match(vapply(b $ hits $ hits , " [[" , " " , " _type" ), " line" )
18
17
})
@@ -44,42 +43,43 @@ test_that("getting json data back from search works", {
44
43
expect_is(jsonlite :: fromJSON(f ), " list" )
45
44
})
46
45
47
- test_that(" Search works with special characters" , {
48
- if (index_exists(" a+b" )) {
49
- invisible (index_delete(" a+b" ))
50
- }
46
+ test_that(" Search works with special characters - +" , {
47
+ invisible (tryCatch(index_delete(" a+b" ), error = function (e ) e ))
51
48
invisible (index_create(" a+b" ))
52
49
invisible (docs_create(index = " a+b" , type = " wiz" , id = 1 , body = list (a = " ddd" , b = " eee" )))
53
50
54
- vv <- Search(index = " a+b" )
55
-
56
- expect_is(vv , " list" )
57
- expect_equal(length(vv $ hits $ hits ), 1 )
58
- expect_equal(vapply(vv $ hits $ hits , " [[" , " " , " _index" ), ' a+b' )
51
+ Sys.sleep(1 )
52
+ aplusb <- Search(index = " a+b" )
59
53
60
- if (index_exists(" a^z" )) {
61
- invisible (index_delete(" a^z" ))
62
- }
63
- index_create(" a^z" )
54
+ expect_is(aplusb , " list" )
55
+ expect_equal(length(aplusb $ hits $ hits ), 1 )
56
+ expect_equal(vapply(aplusb $ hits $ hits , " [[" , " " , " _index" ), ' a+b' )
57
+ })
58
+
59
+ test_that(" Search works with special characters - ^" , {
60
+ invisible (tryCatch(index_delete(" a^z" ), error = function (e ) e ))
61
+ invisible (index_create(" a^z" ))
64
62
invisible (docs_create(index = " a^z" , type = " bang" , id = 1 , body = list (a = " fff" , b = " ggg" )))
65
63
66
- vv <- Search(index = " a^z" )
64
+ Sys.sleep(1 )
65
+ ahatz <- Search(index = " a^z" )
67
66
68
- expect_is(vv , " list" )
69
- expect_equal(length(vv $ hits $ hits ), 1 )
70
- expect_equal(vapply(vv $ hits $ hits , " [[" , " " , " _index" ), ' a^z' )
67
+ expect_is(ahatz , " list" )
68
+ expect_equal(length(ahatz $ hits $ hits ), 1 )
69
+ expect_equal(vapply(ahatz $ hits $ hits , " [[" , " " , " _index" ), ' a^z' )
70
+ })
71
71
72
- if (index_exists(" a$z" )) {
73
- invisible (index_delete(" a$z" ))
74
- }
75
- index_create(" a$z" )
72
+ test_that(" Search works with special characters - $" , {
73
+ invisible (tryCatch(index_delete(" a$z" ), error = function (e ) e ))
74
+ invisible (index_create(" a$z" ))
76
75
invisible (docs_create(index = " a$z" , type = " bang" , id = 1 , body = list (a = " fff" , b = " ggg" )))
77
76
78
- vv <- Search(index = " a$z" )
77
+ Sys.sleep(1 )
78
+ adollarz <- Search(index = " a$z" )
79
79
80
- expect_is(vv , " list" )
81
- expect_equal(length(vv $ hits $ hits ), 1 )
82
- expect_equal(vapply(vv $ hits $ hits , " [[" , " " , " _index" ), ' a$z' )
80
+ expect_is(adollarz , " list" )
81
+ expect_equal(length(adollarz $ hits $ hits ), 1 )
82
+ expect_equal(vapply(adollarz $ hits $ hits , " [[" , " " , " _index" ), ' a$z' )
83
83
})
84
84
85
85
test_that(" Search works with wild card" , {
@@ -88,19 +88,20 @@ test_that("Search works with wild card", {
88
88
}
89
89
invisible (index_create(" voobardang1" ))
90
90
invisible (docs_create(index = " voobardang1" , type = " wiz" , id = 1 , body = list (a = " ddd" , b = " eee" )))
91
-
91
+
92
92
if (index_exists(" voobardang2" )) {
93
93
invisible (index_delete(" voobardang2" ))
94
94
}
95
95
index_create(" voobardang2" )
96
96
invisible (docs_create(index = " voobardang2" , type = " bang" , id = 1 , body = list (a = " fff" , b = " ggg" )))
97
97
98
- vv <- Search(index = " voobardang*" )
98
+ Sys.sleep(1 )
99
+ aster <- Search(index = " voobardang*" )
99
100
100
- expect_is(vv , " list" )
101
- expect_equal(length(vv $ hits $ hits ), 2 )
102
- expect_equal(vapply(vv $ hits $ hits , " [[" , " " , " _index" ), c(' voobardang1' , ' voobardang2' ))
103
- expect_equal(vapply(vv $ hits $ hits , " [[" , " " , " _id" ), c(' 1' , ' 1' ))
101
+ expect_is(aster , " list" )
102
+ expect_equal(length(aster $ hits $ hits ), 2 )
103
+ expect_equal(vapply(aster $ hits $ hits , " [[" , " " , " _index" ), c(' voobardang1' , ' voobardang2' ))
104
+ expect_equal(vapply(aster $ hits $ hits , " [[" , " " , " _id" ), c(' 1' , ' 1' ))
104
105
})
105
106
106
107
test_that(" Search fails as expected" , {
0 commit comments