Appearance
Product Search with our Java client
You can find our Java SDK here.
Start by making a Searcher
instance:
java
var searcher = new Searcher(
"00000000-0000-0000-0000-000000000001",
"your api key",
"the server URL for the dataset");
Before you proceed, make sure that you have read and understood the following:
The following shows an example of how to perform a product search with 3 selected facets:
java
var productSearch = ProductSearchRequest.create(
Language.create("da"),
Currency.create("DKK"),
getUser(),
"Search overlay", // displayed at location
"gaffel", // search term
0, // skip
10 // take
).setSettings(ProductSearchSettings.create()
.setSelectedProductProperties(SelectedProductPropertiesSettings.create()
.setDisplayName(true)
.setCategoryPaths(true)
.setBrand(true)
.setDataKeys("Description", "ImagePath")
.setAllVariants(true)
)
).setFacets(ProductFacetQuery.create()
.addToItems(BrandFacet.create()
.setSelected("77", "93")
)
.addToItems(ProductDataStringValueFacet.create(
DataSelectionStrategy.Product,
"Environment",
new ArrayList<>() { { add("Selection 1"); } },
null
))
.addToItems(
ProductDataBooleanValueFacet.create(
DataSelectionStrategy.Product,
"InStock",
new ArrayList<>() { { add(true); } },
null
)
)
);
searcher.search(productSearch);
Using facets and selecting values
Add the following code to the request to return a facet with the different brands from the products matching the search.
java
productSearch.setFacets(
ProductFacetQuery.create()
.addToItems(BrandFacet.create())
);
When the user selects a brand, update the code to the following:
java
productSearch.setFacets(
ProductFacetQuery.create()
.addToItems(BrandFacet.create()
.setSelected("93")
)
);
You can learn more about facets here.