PrizmDoc® Viewer v13.26 Release - Updated
PrizmDoc Viewer / Developer Guide / Viewer / Configure the Viewer / Configuration Options / How to Use Pre-defined Search
In This Topic
    How to Use Pre-defined Search
    In This Topic

    Introduction

    This feature allows you to define a set of predefined search terms. To enable this functionality you must add the predefinedSearch property to the Viewer parameters. The following example shows you how:

    Example

    <script type="text/javascript">
      $(document).ready(function () {
        var pluginOptions = {
          documentID: viewingSessionId,
          language: languageItems,
          template: htmlTemplates,
          predefinedSearch: {
            highlightColor: "#ee3a8c",
            searchOnInit: false,
            globalOptions: {
              matchCase: false,
              endsWith: false,
              beginsWith: false,
              matchWholeWord: false,
              wildcard: false
            },
            terms: [{
              searchTerm: "llama",
              selected: true,
              options: {
                matchWholeWord: true,
                wildcard: false
              }
            },
            {
              searchTerm: "Words that begin with ll",
              userDefinedRegex: "\\bll(\\w*)\\b",
              searchTermIsRegex: true,
              selected: true,
              highlightColor: "#4169e1",
              options: {
                matchCase: true
              }
            }]
          }
        };
        var viewerControl = $("#viewer1").pccViewer(pluginOptions).viewerControl;
      });
    </script>
    
    

    PredefinedSearch.JSON

    Predefined Search can also be specified using a text file (predefinedSearch.json). The predefinedSearch.json file provides several sample search terms and custom regular expressions; the file is parsed by the web-tier and loaded in the Viewer. The following example shows you how:

    Example

    <script type="text/javascript"\>
      var viewingSessionId = '<%=HttpUtility.JavaScriptStringEncode(viewingSessionId)%>';
      //Retrieve the searchJson (search data) into javascript var searchTerms = <%=searchJson%>;
      var pluginOptions = {
        documentID: viewingSessionId,
        predefinedSearch: searchTerms,
      };
      $(document).ready(function () {
        var viewerControl = $("#viewer1").pccViewer(pluginOptions).viewerControl;
      });
    </script>
    
    

    Predefined Search Patterns

    The following table shows the predefined search pattern parameters:

    Parameter Data Type Description
    highlightColor String The default highlight color of the search terms. This is overridden by the term-level parameter. This must be in 6 digit hexadecimal format preceded by a #.
    Example: "#ee3a8c"
    searchOnInit Boolean Run search on launch.
    globalOptions Object Set the default search options for each of the predefined search terms. This is overridden by the term-level options parameter.
    Example:
    predefinedSearch: { globalOptions: { matchCase: false, endsWith: false, beginsWith: false, matchWholeWord: false } }
    terms Array An array of objects that represent the search terms that will be available in the predefined search menu.
    Example:
    predefinedSearch: { terms: [{ searchTerm: "llama" } ] }

    Predefined Search Terms

    The following table shows the predefined search term parameters:

    Parameter Data Type Description
    searchTerm String The search string for the term object. This is overridden by the userDefinedRegex parameter.
    userDefinedRegex String A regular expression that will be searched in place of searchTerm. The first and last forward slashes, as well as the flags, are stripped from the string. For example, /Pa(\w+)/ig will become Pa(\w+). When special characters (ex: backslash) are used in the userDefinedRegex field, they need to be properly escaped. For example, for searching words that begins with "Pa", the regular expression will be Pa(\w+), this regular expression should be properly escaped like this Pa(\w+). All patterns use the Global(g) flag.
    Example:
    predefinedSearch: { terms: [{ searchTerm: "4 digits", userdefinedRegex: "(\\\d{4})" } ] }
    selected Boolean Whether or not this term will be selected in the menu.
    options Object Set the search options for this term. If a parameter is not defined it will inherit the globalOptions-level parameter.
    Example:
    predefinedSearch: { terms: [{ searchTerm: "Lla", options: { matchCase: true, endsWith: false, beginsWith: true, matchWholeWord: false } } ] }