UrlBeautifier

The UrlBeautifier is used to transform a search and navigation state into a beautified and SEO friendly URL. It can convert from a query object into a URL and from a URL into a query object.

Create a beautifier and set up the mappings

UrlBeautifier defaultUrlBeautifier = UrlBeautifier.getUrlBeautifiers()
        .get("default");
if (defaultUrlBeautifier == null) {
    UrlBeautifier.createUrlBeautifier("default");
    defaultUrlBeautifier = UrlBeautifier.getUrlBeautifiers().get(
             "default");
    defaultUrlBeautifier.addRefinementMapping('b', "brand");
    defaultUrlBeautifier.setSearchMapping('q');
    defaultUrlBeautifier.setAppend("/index.html");
}

From a URL

Query query = defaultUrlBeautifier.fromUrl(pRequest.getRequestURI());

To a URL

In this example we’ll use the JSTL EL function that uses the UrlBeautifier behind the scenes.

<a href="<c:url value="${b:toUrlAdd('default', q, selectedNavigations, navigationName, newRefinement)}"/>">${value.value} (${value['count'] })</a>

addRefinementMapping(char pToken, string pName)

  • pToken: The single letter to represent this refinement in the lookup.
  • pName: The name of the navigation that will be mapped using this token.

Set up a mapping for a refinement. Note: you cannot use vowels for mapping tokens to prevent dictionary word creation. The order in which this method is called determines where in the URL the refinements will show up.

clearSavedFields()

Clean up all mappings.

createUrlBeautifier(string pName)

  • pName: The handle back to this UrlBeautifier

Create a UrlBeautifier and store it for the lifetime of this JVM under the name specified.

Query fromUrl(string pUri)

  • pUri: The URI to parse into a query object

Convert a URI into a query object. Mappings will be converted to the correct search and refinement state.

Query fromUrl(string pUrl, Query pDefault)

  • pUri: The URI to parse into a query object
  • pDefault: The default query to use if this URL does not correctly parse.

Convert a URI into a query object. Mappings will be converted to the correct search and refinement state.

string getAppend()

Return the current appended URL segment

string getRefinementsQueryParameterName()

  • returns: The name with which non-mapped refinements will be mapped into the URL query string.

Map<string,UrlBeautifier> getUrlBeautifiers()

Get a map of UrlBeautifiers keyed by name.

setAppend(string pAppend)

  • pAppend: The value to append to each beautified URL.

Quite often URLs need to end with specific extensions to map to the correct controller in the backend. Here you can set this value. For example: /index.html

setRefinementsQueryParameterName(string pRefinementsQueryParameterName)

  • pRefinementsQueryParameterName: The name of the query parameter to use.

Sets the name of the query parameter with which non-mapped refinements will show up in the query string. This includes ranges which are never mapped to beautified URLs.

setSearchMapping(char pToken)

  • pToken: The single letter to represent search in the lookup.

Set the mapping from a search term to a path segment. Note: you cannot use vowels for mapping tokens to prevent dictionary word creation. The order in which this method is called determines where in the URL the search term will show up.

string toUrl(string pSearchString, string pExistingRefinements)

  • pSearchString: The current search state.
  • pExistingRefinements: The current refinement state

Convert a search term and a list of refinements into a beautified URL. Each refinement that has a mapping will be turned into a path segment. If a mapping has been created for search, the search term will also be placed into a URL path segment.