-
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(stopwords): add stopwords support (#73)
Implements stopwords management capabilities allowing users to create and manage stopwords sets for search optimization. Adds complete CRUD operations for stopwords with proper error handling and test coverage. Changes include: - New Stopwords and StopwordsSet classes for managing stopwords - Client integration for stopwords management - Full test coverage with realistic scenarios - Helper class updates for testing stopwords functionality - Documentation updates with usage examples feat(stopwords): add Stopwords class for bulk operations feat(stopwords): add StopwordsSet class for individual set management test(stopwords): add StopwordsTest test coverage refactor(client): integrate stopwords support refactor(helper): add stopwords support in test helper docs(stopwords): add documentation and examples
- Loading branch information
1 parent
2faea8a
commit 1eee81d
Showing
6 changed files
with
216 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package org.typesense.api; | ||
|
||
import org.typesense.api.utils.URLEncoding; | ||
import org.typesense.model.StopwordsSetSchema; | ||
import org.typesense.model.StopwordsSetUpsertSchema; | ||
import org.typesense.model.StopwordsSetsRetrieveAllSchema; | ||
|
||
public class Stopwords { | ||
public final static String RESOURCEPATH = "/stopwords"; | ||
|
||
private final ApiCall apiCall; | ||
|
||
public Stopwords(ApiCall apiCall) { | ||
this.apiCall = apiCall; | ||
} | ||
|
||
public StopwordsSetSchema upsert(String stopwordSetId, StopwordsSetUpsertSchema stopwordSet) throws Exception { | ||
return this.apiCall.put(getEndpoint(stopwordSetId), stopwordSet, null, StopwordsSetSchema.class); | ||
} | ||
|
||
public StopwordsSetsRetrieveAllSchema retrieve() throws Exception { | ||
return this.apiCall.get(Stopwords.RESOURCEPATH, null, StopwordsSetsRetrieveAllSchema.class); | ||
} | ||
|
||
private String getEndpoint(String stopwordSetId) { | ||
return RESOURCEPATH + "/" + URLEncoding.encodeURIComponent(stopwordSetId); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package org.typesense.api; | ||
|
||
import org.typesense.api.utils.URLEncoding; | ||
import org.typesense.model.StopwordsSetRetrieveSchema; | ||
import org.typesense.model.StopwordsSetSchema; | ||
|
||
public class StopwordsSet { | ||
private final ApiCall apiCall; | ||
private final String stopwordsSetId; | ||
|
||
public StopwordsSet(String stopwordsSetId, ApiCall apiCall) { | ||
this.stopwordsSetId = stopwordsSetId; | ||
this.apiCall = apiCall; | ||
} | ||
|
||
public StopwordsSetRetrieveSchema retrieve() throws Exception { | ||
return this.apiCall.get(this.getEndpoint(), null, StopwordsSetRetrieveSchema.class); | ||
} | ||
|
||
public StopwordsSetSchema delete() throws Exception { | ||
return this.apiCall.delete(this.getEndpoint(), null, StopwordsSetSchema.class); | ||
} | ||
|
||
private String getEndpoint() { | ||
return Stopwords.RESOURCEPATH + "/" + URLEncoding.encodeURIComponent(this.stopwordsSetId); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package org.typesense.api; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.junit.jupiter.api.AfterEach; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.typesense.model.StopwordsSetRetrieveSchema; | ||
import org.typesense.model.StopwordsSetSchema; | ||
import org.typesense.model.StopwordsSetUpsertSchema; | ||
import org.typesense.model.StopwordsSetsRetrieveAllSchema; | ||
|
||
public class StopwordsTest { | ||
|
||
private Client client; | ||
private Helper helper; | ||
|
||
@BeforeEach | ||
void setUp() throws Exception { | ||
helper = new Helper(); | ||
client = helper.getClient(); | ||
helper.teardown(); | ||
helper.createTestCollection(); | ||
} | ||
|
||
@AfterEach | ||
void tearDown() throws Exception { | ||
helper.teardown(); | ||
} | ||
|
||
@Test | ||
void testUpsert() throws Exception { | ||
List<String> stopwords = new ArrayList<>(); | ||
stopwords.add("the"); | ||
stopwords.add("of"); | ||
stopwords.add("and"); | ||
|
||
StopwordsSetUpsertSchema stopwordsSetSchema = new StopwordsSetUpsertSchema(); | ||
stopwordsSetSchema.stopwords(stopwords); | ||
|
||
client.stopwords().upsert("common-words", stopwordsSetSchema); | ||
} | ||
|
||
@Test | ||
void testRetrieve() throws Exception { | ||
helper.createTestStopwordsSet(); | ||
|
||
StopwordsSetRetrieveSchema result = this.client.stopwords("common-words").retrieve(); | ||
|
||
assertNotNull(result); | ||
|
||
StopwordsSetSchema set = result.getStopwords(); | ||
|
||
assertEquals("common-words", set.getId()); | ||
assertEquals(3, set.getStopwords().size()); | ||
assertEquals("and", set.getStopwords().get(0)); | ||
assertEquals("the", set.getStopwords().get(1)); | ||
assertEquals("of", set.getStopwords().get(2)); | ||
} | ||
|
||
@Test | ||
void testRetrieveAll() throws Exception { | ||
helper.createTestStopwordsSet(); | ||
|
||
StopwordsSetsRetrieveAllSchema result = this.client.stopwords().retrieve(); | ||
|
||
assertNotNull(result); | ||
assertEquals(1, result.getStopwords().size()); | ||
|
||
StopwordsSetSchema set = result.getStopwords().get(0); | ||
|
||
assertEquals("common-words", set.getId()); | ||
assertEquals(3, set.getStopwords().size()); | ||
assertEquals("and", set.getStopwords().get(0)); | ||
assertEquals("the", set.getStopwords().get(1)); | ||
assertEquals("of", set.getStopwords().get(2)); | ||
} | ||
|
||
@Test | ||
void testDelete() throws Exception { | ||
helper.createTestStopwordsSet(); | ||
|
||
StopwordsSetSchema result = this.client.stopwords("common-words").delete(); | ||
|
||
assertNotNull(result); | ||
assertEquals("common-words", result.getId()); | ||
} | ||
} |