Configuring Query Modification for Application Builder

Query modification is the process of modifying a query before it is passed to the configured Watson Explorer Engine backend.

Procedure

  1. In the Settings > Search > Query modification section of the Application Builder settings page (the cog icon on the navigation bar), click the information iconthe information icon, which is located next to the Query modification script field.
  2. Experiment with available examples by selecting them, inserting them into the field, and modifying them, as necessary. For example:
    Option Description
    Remove stopwords

    You can insert and use this example without making further changes. It removes the English stopwords that are listed in the code. You can add or remove stopwords from the list.

    Call a service

    All query modifications enable you to transform the query string before it is passed to Watson Explorer Engine. In the case of calling services, you can submit the query string from end users to a service, which alters it in some way, and then submit that altered string to Watson Explorer Engine.

    You can insert the example code to call the AlchemyAPI keyword extraction service. The only change you must make to the example code is to supply your AlchemyAPI key, which you must register for. You can receive a key without charge for a certain number of daily transactions. For more information about registering for a key and pricing for AlchemyAPI, see http://www.alchemyapi.com/.

    The keyword extraction service extracts keywords from the query, similar to what the code for removing stopwords does. But the keyword extraction service does more than remove stopwords. The service applies statistical algorithms and natural language processing to the query term and identifies what it determines are the relevant keywords from the query. Those keywords are then submitted to Watson Explorer Engine as the query term, and searched in your data sources.

    To see what the AlchemyAPI keyword extraction service considers relevant, you can experiment with the demo at the following URL, http://www.alchemyapi.com/products/demo/alchemylanguage. For example, if you try the query, The US Government Users Restricted Rights, and view the keywords that the service extracts, you see that the keywords are Government Users and Rights.

    Personalize the query to the current user

    Although this is not an example in the administration tool because the code is highly dependent on your entity model, you could use query modification to change the query based on the currently logged-in user.

    The query modification script has access to the following information:
    • Current user
    • Entity types
    • Query string
    • Endpoints
    Note: Use query API methods in the script to access the previous information in the query modification script. Methods that are part of the query API are suggested automatically in the field while you type. For example, enter endpoints( in the field, which suggests a list of available endpoints.
  3. Save the changes and test that the query modification works as you expect by viewing the application in admin mode, which is enabled by default. When admin mode is enabled, query debugging information displays the result of each step of query processing that was performed.