1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.search.solr.internal; |
21 |
|
|
22 |
|
import static org.junit.Assert.*; |
23 |
|
|
24 |
|
import java.util.Arrays; |
25 |
|
import java.util.Collections; |
26 |
|
import java.util.HashMap; |
27 |
|
import java.util.HashSet; |
28 |
|
import java.util.Map; |
29 |
|
|
30 |
|
import org.apache.solr.common.params.MapSolrParams; |
31 |
|
import org.apache.solr.common.params.SolrParams; |
32 |
|
import org.junit.Test; |
33 |
|
|
34 |
|
|
35 |
|
@link |
36 |
|
|
37 |
|
@version |
38 |
|
@since |
39 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (55) |
Complexity: 5 |
Complexity Density: 0.1 |
|
40 |
|
public class XWikiDismaxQParserPluginTest |
41 |
|
{ |
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
private XWikiDismaxQParserPlugin plugin = new XWikiDismaxQParserPlugin(); |
46 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 1 |
Complexity Density: 0.09 |
1PASS
|
|
47 |
1 |
@Test... |
48 |
|
public void extractFieldNames() |
49 |
|
{ |
50 |
1 |
assertEquals(Collections.emptySet(), plugin.extractFieldNames("")); |
51 |
1 |
assertEquals(Collections.emptySet(), plugin.extractFieldNames("text")); |
52 |
1 |
assertEquals(Collections.emptySet(), plugin.extractFieldNames("+(^:text")); |
53 |
1 |
assertEquals(Collections.emptySet(), plugin.extractFieldNames("foo :bar")); |
54 |
|
|
55 |
1 |
assertEquals(Collections.singleton("foo"), plugin.extractFieldNames("foo:bar")); |
56 |
1 |
assertEquals(Collections.singleton("both"), plugin.extractFieldNames("both:(one two)")); |
57 |
1 |
assertEquals(Collections.singleton("title__"), plugin.extractFieldNames("title__:text")); |
58 |
1 |
assertEquals(Collections.singleton("title_zh_TW"), plugin.extractFieldNames("title_zh_TW:text")); |
59 |
1 |
assertEquals(Collections.singleton("property.Blog.BlogPostClass.title"), |
60 |
|
plugin.extractFieldNames("property.Blog.BlogPostClass.title:value")); |
61 |
1 |
assertEquals(Collections.singleton("property.Blog.Blog..Post$5EClass.title"), |
62 |
|
plugin.extractFieldNames("property.Blog.Blog..Post$5EClass.title:value")); |
63 |
|
|
64 |
1 |
assertEquals( |
65 |
|
new HashSet<String>(Arrays.asList("abc", "g_h.i", "m$n-o", |
66 |
|
"_\u0103\u00EE\u00E2\u0219\u021B\u00E8\u00E9\u00EA\u00EB")), |
67 |
|
plugin.extractFieldNames("+abc:def AND -g_h.i:jkl AND (m$n-o:pqr OR " |
68 |
|
+ "_\u0103\u00EE\u00E2\u0219\u021B\u00E8\u00E9\u00EA\u00EB:stu^3)")); |
69 |
|
} |
70 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (15) |
Complexity: 1 |
Complexity Density: 0.07 |
1PASS
|
|
71 |
1 |
@Test... |
72 |
|
public void withFieldAliases() |
73 |
|
{ |
74 |
1 |
Map<String, String> parameters = new HashMap<String, String>(); |
75 |
1 |
parameters.put("qf", "title^0.4 comment^0.40 date^1.0"); |
76 |
1 |
parameters.put("xwiki.multilingualFields", "title, property.*, foo, comment"); |
77 |
1 |
parameters.put("xwiki.supportedLocales", "en, fr, zh_TW"); |
78 |
1 |
parameters.put("xwiki.typedDynamicFields", "property.*"); |
79 |
1 |
parameters.put("xwiki.dynamicFieldTypes", "boolean, int"); |
80 |
|
|
81 |
1 |
String query = "title:text AND x:y AND property.Blog.BlogPostClass.summary:wiki AND title_ro:value"; |
82 |
1 |
SolrParams paramsWithAliases = plugin.withFieldAliases(query, new MapSolrParams(parameters)); |
83 |
|
|
84 |
1 |
assertEquals("title__ title_en title_fr title_zh_TW", paramsWithAliases.get("f.title.qf")); |
85 |
1 |
assertEquals("property.Blog.BlogPostClass.summary__ property.Blog.BlogPostClass.summary_en " |
86 |
|
+ "property.Blog.BlogPostClass.summary_fr property.Blog.BlogPostClass.summary_zh_TW " |
87 |
|
+ "property.Blog.BlogPostClass.summary_boolean property.Blog.BlogPostClass.summary_int", |
88 |
|
paramsWithAliases.get("f.property.Blog.BlogPostClass.summary.qf")); |
89 |
|
|
90 |
|
|
91 |
1 |
assertEquals("comment__ comment_en comment_fr comment_zh_TW", paramsWithAliases.get("f.comment.qf")); |
92 |
|
|
93 |
|
|
94 |
1 |
assertNull(paramsWithAliases.get("f.x.qf")); |
95 |
1 |
assertNull(paramsWithAliases.get("f.title_ro.qf")); |
96 |
|
|
97 |
|
|
98 |
1 |
assertNull(paramsWithAliases.get("f.date.qf")); |
99 |
|
|
100 |
|
|
101 |
1 |
assertNull(paramsWithAliases.get("f.foo.qf")); |
102 |
|
} |
103 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
104 |
1 |
@Test... |
105 |
|
public void withFieldAliasesWhenNoSupportedLocales() |
106 |
|
{ |
107 |
1 |
Map<String, String> parameters = new HashMap<String, String>(); |
108 |
1 |
parameters.put("qf", "comment^0.40"); |
109 |
1 |
parameters.put("xwiki.multilingualFields", "title, comment"); |
110 |
|
|
111 |
1 |
SolrParams paramsWithAliases = plugin.withFieldAliases("title:text", new MapSolrParams(parameters)); |
112 |
|
|
113 |
|
|
114 |
1 |
assertEquals("title__", paramsWithAliases.get("f.title.qf")); |
115 |
1 |
assertEquals("comment__", paramsWithAliases.get("f.comment.qf")); |
116 |
|
} |
117 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
118 |
1 |
@Test... |
119 |
|
public void withFieldAliasesWhenNoMultilingualFields() |
120 |
|
{ |
121 |
1 |
Map<String, String> parameters = new HashMap<String, String>(); |
122 |
1 |
parameters.put("qf", "title^0.4 comment^0.40 date^1.0"); |
123 |
1 |
parameters.put("xwiki.supportedLocales", "en, ro"); |
124 |
|
|
125 |
1 |
SolrParams paramsWithAliases = plugin.withFieldAliases("title:text", new MapSolrParams(parameters)); |
126 |
|
|
127 |
|
|
128 |
1 |
assertEquals(2, paramsWithAliases.toNamedList().size()); |
129 |
1 |
assertEquals("title^0.4 comment^0.40 date^1.0", paramsWithAliases.get("qf")); |
130 |
1 |
assertEquals("en, ro", paramsWithAliases.get("xwiki.supportedLocales")); |
131 |
|
} |
132 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 1 |
Complexity Density: 0.09 |
1PASS
|
|
133 |
1 |
@Test... |
134 |
|
public void withFieldAliasesWhenNoFieldsInQuery() |
135 |
|
{ |
136 |
1 |
Map<String, String> parameters = new HashMap<String, String>(); |
137 |
1 |
parameters.put("qf", "title^0.4 comment^0.40"); |
138 |
1 |
parameters.put("xwiki.multilingualFields", "title, foo"); |
139 |
1 |
parameters.put("xwiki.supportedLocales", "en, fr"); |
140 |
1 |
parameters.put("xwiki.typedDynamicFields", "property.*"); |
141 |
1 |
parameters.put("xwiki.dynamicFieldTypes", "long, date"); |
142 |
|
|
143 |
1 |
SolrParams paramsWithAliases = plugin.withFieldAliases("text", new MapSolrParams(parameters)); |
144 |
|
|
145 |
|
|
146 |
1 |
assertEquals(6, paramsWithAliases.toNamedList().size()); |
147 |
|
|
148 |
|
|
149 |
1 |
assertEquals("title__ title_en title_fr", paramsWithAliases.get("f.title.qf")); |
150 |
|
|
151 |
|
|
152 |
1 |
assertNull(paramsWithAliases.get("f.comment.qf")); |
153 |
|
|
154 |
|
|
155 |
1 |
assertNull(paramsWithAliases.get("f.foo.qf")); |
156 |
|
} |
157 |
|
} |