# Filter Results

In some cases, you might want to restrict the results that a user receives as suggestions. You can apply filters to the `TypeAhead` action, depending on the mode that you are using.

- In Index mode, you can use a `SecurityInfo` string with the `TypeAhead` action. QMS forwards this string to the IDOL index, and returns only terms that occur in documents that the user is permitted to see.

- In Index, Dictionary, and Answerbank modes, you can provide a Lua script that filters the suggestions that the `TypeAhead` action returns.

## Use a SecurityInfo String

When you are using the data index to provide suggestions, you can use the IDOL security functionality to ensure that users see only suggestions that occur in at least one document that they are permitted to see.

You can set the `SecurityInfo` parameter in the `TypeAhead` action. QMS forwards this value to the IDOL Content component, which filters the results according to user permissions. You can generate the `SecurityInfo` string for a user by using the `UserRead` action for the IDOL Server Community component. For more information, refer to the IDOL Server Reference.

## Use a Lua Script to Filter Results

You can configure and use a Lua script to filter the suggestions according to your own filtering criteria.

The Lua script that you create to filter results must contain a valid Lua function named `typeahead_filter` that accepts a string value and returns a Boolean value.

QMS calls the Lua script once for each suggestion that the `TypeAhead` action returns. It passes the suggestion to the `prefix` argument of the `typeahead_filter` function. The following script is a very simple example, which filters out the suggestion gold, if it returns from QMS:

    function typeahead_filter (prefix)
       if prefix == "gold" then
          return false
       end
       return true
    end

When you have a script configured, the `TypeAhead` action returns only suggestions for which the `typeahead_filter` function returns `True`. In the example above, the suggestion gold returns `False`, so QMS does not show it in the response for the `TypeAhead` action.

You can use the IDOL Lua libraries in your Lua scripts. For more information about the available functions and methods, see the QMS Reference.

To configure QMS to use a Lua script for filtering

1. Open the QMS configuration file in a text editor.

2. Find the `[TypeAhead]` configuration section, or create one if it does not exist.

3. Set the `Script` parameter to the name of the script file that you want to use. For example:

       [TypeAhead]
       Script=filter_script.lua

4. Save and close the QMS configuration file. Restart QMS for your changes to take effect.

_FT_HTML5_bannerTitle.htm