-
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(presets): add search presets support
Implements search presets management to allow storing and reusing common search configurations. Adds complete CRUD operations for search presets with proper error handling and test coverage. Changes include: - New Presets and Preset classes for managing search presets - Full test coverage with realistic search preset scenarios - Helper class updates for testing preset functionality - Documentation updates with usage examples for common scenarios feat(presets): add Presets class for bulk operations feat(presets): add Preset class for individual preset management test(presets): add PresetsTest test coverage refactor(helper): add presets support in test helper docs(presets): add documentation and examples
- Loading branch information
1 parent
1eee81d
commit 87c3563
Showing
6 changed files
with
213 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,28 @@ | ||
package org.typesense.api; | ||
|
||
import org.typesense.api.utils.URLEncoding; | ||
import org.typesense.model.PresetDeleteSchema; | ||
import org.typesense.model.PresetSchema; | ||
|
||
public class Preset { | ||
private final ApiCall apiCall; | ||
private final String name; | ||
|
||
public Preset(String name, ApiCall apiCall) { | ||
this.name = name; | ||
this.apiCall = apiCall; | ||
} | ||
|
||
public PresetSchema retrieve() throws Exception { | ||
return this.apiCall.get(this.getEndpoint(), null, PresetSchema.class); | ||
} | ||
|
||
public PresetDeleteSchema delete() throws Exception { | ||
return this.apiCall.delete(this.getEndpoint(), null, PresetDeleteSchema.class); | ||
} | ||
|
||
private String getEndpoint() { | ||
return Presets.RESOURCEPATH + "/" + URLEncoding.encodeURIComponent(this.name); | ||
} | ||
|
||
} |
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.PresetSchema; | ||
import org.typesense.model.PresetUpsertSchema; | ||
import org.typesense.model.PresetsRetrieveSchema; | ||
|
||
public class Presets { | ||
public final static String RESOURCEPATH = "/presets"; | ||
|
||
private final ApiCall apiCall; | ||
|
||
public Presets(ApiCall apiCall) { | ||
this.apiCall = apiCall; | ||
} | ||
|
||
public PresetSchema upsert(String name, PresetUpsertSchema preset) throws Exception { | ||
return this.apiCall.put(getEndpoint(name), preset, null, PresetSchema.class); | ||
} | ||
|
||
public PresetsRetrieveSchema retrieve() throws Exception { | ||
return this.apiCall.get(Presets.RESOURCEPATH, null, PresetsRetrieveSchema.class); | ||
} | ||
|
||
private String getEndpoint(String name) { | ||
return RESOURCEPATH + "/" + URLEncoding.encodeURIComponent(name); | ||
} | ||
|
||
} |
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,88 @@ | ||
package org.typesense.api; | ||
|
||
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.OneOfPresetUpsertSchemaValue; | ||
import org.typesense.model.PresetDeleteSchema; | ||
import org.typesense.model.PresetSchema; | ||
import org.typesense.model.PresetUpsertSchema; | ||
import org.typesense.model.PresetsRetrieveSchema; | ||
import org.typesense.model.SearchParameters; | ||
|
||
public class PresetsTest { | ||
|
||
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 { | ||
SearchParameters params = new SearchParameters() | ||
.q("Romeo") | ||
.queryBy("title"); | ||
|
||
PresetUpsertSchema preset = new PresetUpsertSchema() | ||
.value(params); | ||
|
||
PresetSchema result = client.presets().upsert("listing_view", preset); | ||
|
||
assertNotNull(result); | ||
assertEquals("listing_view", result.getName()); | ||
|
||
OneOfPresetUpsertSchemaValue value = result.getValue(); | ||
assertNotNull(value); | ||
} | ||
|
||
@Test | ||
void testRetrieve() throws Exception { | ||
helper.createTestPreset(); | ||
|
||
PresetSchema result = this.client.presets("listing_view").retrieve(); | ||
|
||
assertNotNull(result); | ||
assertEquals("listing_view", result.getName()); | ||
assertNotNull(result.getValue()); | ||
} | ||
|
||
@Test | ||
void testRetrieveAll() throws Exception { | ||
helper.createTestPreset(); | ||
|
||
PresetsRetrieveSchema result = this.client.presets().retrieve(); | ||
|
||
assertNotNull(result); | ||
|
||
assertEquals(1, result.getPresets().size()); | ||
|
||
PresetSchema preset = result.getPresets().get(0); | ||
assertEquals("listing_view", preset.getName()); | ||
assertNotNull(preset.getValue()); | ||
} | ||
|
||
@Test | ||
void testDelete() throws Exception { | ||
helper.createTestPreset(); | ||
|
||
PresetDeleteSchema result = this.client.presets("listing_view").delete(); | ||
|
||
assertNotNull(result); | ||
|
||
assertEquals("listing_view", result.getName()); | ||
|
||
} | ||
} |