Skip to content

Commit fd9d855

Browse files
Add test
1 parent 1cbcd07 commit fd9d855

File tree

2 files changed

+82
-1
lines changed

2 files changed

+82
-1
lines changed

pom.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
<properties>
4343
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
4444
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
45+
<skipTests>true</skipTests>
4546
</properties>
4647
<repositories>
4748
<repository>
@@ -122,7 +123,10 @@
122123
<plugin>
123124
<groupId>org.apache.maven.plugins</groupId>
124125
<artifactId>maven-surefire-plugin</artifactId>
125-
<version>2.18</version>
126+
<version>2.18.1</version>
127+
<configuration>
128+
<skipTests>${skipTests}</skipTests>
129+
</configuration>
126130
</plugin>
127131
<plugin>
128132
<groupId>org.apache.maven.plugins</groupId>
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/**
2+
* Copyright 2015 OpenSearchServer Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.opensearchserver.client.test.v1;
17+
18+
import java.io.IOException;
19+
import java.net.URISyntaxException;
20+
21+
import com.opensearchserver.client.JsonClient1;
22+
import com.opensearchserver.client.common.search.query.SearchField;
23+
import com.opensearchserver.client.common.search.query.SearchField.SearchFieldMode;
24+
import com.opensearchserver.client.common.search.query.SearchFieldQuery;
25+
import com.opensearchserver.client.common.search.query.SearchQueryAbstract.OperatorEnum;
26+
import com.opensearchserver.client.v1.SearchApi1;
27+
import com.opensearchserver.client.v1.search.SearchResult1;
28+
import com.opensearchserver.utils.json.JsonMapper;
29+
30+
public class SearchFieldTest {
31+
32+
public void testSearchBooleanGroup(String[] args) throws IOException,
33+
URISyntaxException {
34+
JsonClient1 client = new JsonClient1("http://localhost:8080", null,
35+
null, 50000);
36+
String queryGroup1 = "open search server";
37+
String queryGroup2 = "en";
38+
SearchApi1 searchApi = new SearchApi1(client);
39+
SearchFieldQuery searchFieldQuery = (SearchFieldQuery) new SearchFieldQuery()
40+
.setEmptyReturnsAll(false).setOperator(OperatorEnum.AND);
41+
42+
// If the queryGroup1 is not empty, we add the required fields
43+
if (queryGroup1 != null && !queryGroup1.isEmpty()) {
44+
45+
// Create the search fields, affected to the first boolean group
46+
searchFieldQuery.addSearchField(new SearchField()
47+
.setField("content").setMode(SearchFieldMode.PATTERN)
48+
.setBooleanGroup(1));
49+
50+
searchFieldQuery.addSearchField(new SearchField()
51+
.setField("contentExact").setMode(SearchFieldMode.PATTERN)
52+
.setBooleanGroup(1));
53+
54+
// We set the text query
55+
searchFieldQuery.setQueryStringMap("content", queryGroup1);
56+
searchFieldQuery.setQueryStringMap("contentExact", queryGroup1);
57+
58+
}
59+
60+
// If the queryGroup2 is not empty, we add the required fields
61+
if (queryGroup2 != null && !queryGroup2.isEmpty()) {
62+
63+
// Create the search fields, affected to the first boolean group
64+
searchFieldQuery.addSearchField(new SearchField().setField("lang")
65+
.setMode(SearchFieldMode.PATTERN).setBooleanGroup(2));
66+
67+
searchFieldQuery.setQueryStringMap("lang", queryGroup2);
68+
}
69+
70+
System.out.println(JsonMapper.MAPPER
71+
.writeValueAsString(searchFieldQuery));
72+
SearchResult1 searchResult = searchApi.executeSearchField("web",
73+
searchFieldQuery);
74+
75+
System.out.println(JsonMapper.MAPPER.writeValueAsString(searchResult));
76+
}
77+
}

0 commit comments

Comments
 (0)