Skip to content

Commit d16a732

Browse files
committed
feat(synonyms): add new synonym set classes
1 parent 2a9be82 commit d16a732

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package org.typesense.api;
2+
3+
import org.typesense.api.utils.URLEncoding;
4+
5+
import org.typesense.model.SynonymSetCreateSchema;
6+
import org.typesense.model.SynonymSetSchema;
7+
import org.typesense.model.SynonymSetDeleteSchema;
8+
9+
public class SynonymSet {
10+
11+
private String synonymSetName;
12+
private ApiCall apiCall;
13+
14+
public SynonymSet(String synonymSetName, ApiCall apiCall) {
15+
this.synonymSetName = synonymSetName;
16+
this.apiCall = apiCall;
17+
}
18+
19+
public SynonymSetCreateSchema retrieve() throws Exception {
20+
return this.apiCall.get(this.getEndpoint(), null, SynonymSetCreateSchema.class);
21+
}
22+
23+
public SynonymSetSchema upsert(SynonymSetCreateSchema synonymSetCreateSchema) throws Exception {
24+
return this.apiCall.put(this.getEndpoint(), synonymSetCreateSchema, null, SynonymSetSchema.class);
25+
}
26+
27+
public SynonymSetDeleteSchema delete() throws Exception {
28+
return this.apiCall.delete(this.getEndpoint(), null, SynonymSetDeleteSchema.class);
29+
}
30+
31+
public String getEndpoint() {
32+
return "/synonym_sets/" + URLEncoding.encodeURIComponent(this.synonymSetName);
33+
}
34+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package org.typesense.api;
2+
3+
import java.util.List;
4+
import org.typesense.model.SynonymSetCreateSchema;
5+
import org.typesense.model.SynonymSetSchema;
6+
7+
public class SynonymSets {
8+
9+
private ApiCall apiCall;
10+
public final static String RESOURCEPATH = "/synonym_sets";
11+
12+
public SynonymSets(ApiCall apiCall) {
13+
this.apiCall = apiCall;
14+
}
15+
16+
public SynonymSetSchema upsert(String synonymSetName, SynonymSetCreateSchema synonymSetCreateSchema) throws Exception {
17+
return this.apiCall.put(getEndpoint(synonymSetName), synonymSetCreateSchema, null, SynonymSetSchema.class);
18+
}
19+
20+
public SynonymSetSchema[] retrieve() throws Exception {
21+
return this.apiCall.get(this.getEndpoint(null), null, SynonymSetSchema[].class);
22+
}
23+
24+
public String getEndpoint(String operation) {
25+
return RESOURCEPATH + "/" + (operation == null ? "" : operation);
26+
}
27+
}

0 commit comments

Comments
 (0)