Skip to content

Product Search with our Java client

You will find our Java SDK on Maven.

Start by making a Searcher instance:

java
var searcher = new Searcher(
  "00000000-0000-0000-0000-000000000001"
  "your api key");

Before you proceed, make sure that you have read and understood the following:

  • How to authenticate against our API, found here
  • How to handle different types of users, found here

Also remember to specify your Server URL in your request.

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.

Don't know us? Don't worry - you can find more information about us, by visiting our main page www.relewise.com