components/jansson/doc/html/_static/searchtools.js
author Tomas Heran <tomas.heran@oracle.com>
Fri, 17 Apr 2015 01:30:52 -0700
branchs11-update
changeset 4141 c6a303a2f8c5
permissions -rw-r--r--
PSARC/2014/362 Jansson 19903653 Jansson - C library for working with JSON should be added to Userland
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4141
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
     1
/*
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
     2
 * searchtools.js_t
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
     3
 * ~~~~~~~~~~~~~~~~
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
     4
 *
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
     5
 * Sphinx JavaScript utilties for the full-text search.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
     6
 *
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
     7
 * :copyright: Copyright 2007-2014 by the Sphinx team, see AUTHORS.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
     8
 * :license: BSD, see LICENSE for details.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
     9
 *
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    10
 */
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    11
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    12
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    13
/**
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    14
 * Porter Stemmer
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    15
 */
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    16
var Stemmer = function() {
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    17
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    18
  var step2list = {
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    19
    ational: 'ate',
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    20
    tional: 'tion',
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    21
    enci: 'ence',
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    22
    anci: 'ance',
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    23
    izer: 'ize',
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    24
    bli: 'ble',
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    25
    alli: 'al',
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    26
    entli: 'ent',
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    27
    eli: 'e',
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    28
    ousli: 'ous',
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    29
    ization: 'ize',
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    30
    ation: 'ate',
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    31
    ator: 'ate',
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    32
    alism: 'al',
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    33
    iveness: 'ive',
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    34
    fulness: 'ful',
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    35
    ousness: 'ous',
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    36
    aliti: 'al',
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    37
    iviti: 'ive',
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    38
    biliti: 'ble',
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    39
    logi: 'log'
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    40
  };
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    41
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    42
  var step3list = {
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    43
    icate: 'ic',
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    44
    ative: '',
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    45
    alize: 'al',
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    46
    iciti: 'ic',
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    47
    ical: 'ic',
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    48
    ful: '',
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    49
    ness: ''
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    50
  };
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    51
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    52
  var c = "[^aeiou]";          // consonant
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    53
  var v = "[aeiouy]";          // vowel
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    54
  var C = c + "[^aeiouy]*";    // consonant sequence
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    55
  var V = v + "[aeiou]*";      // vowel sequence
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    56
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    57
  var mgr0 = "^(" + C + ")?" + V + C;                      // [C]VC... is m>0
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    58
  var meq1 = "^(" + C + ")?" + V + C + "(" + V + ")?$";    // [C]VC[V] is m=1
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    59
  var mgr1 = "^(" + C + ")?" + V + C + V + C;              // [C]VCVC... is m>1
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    60
  var s_v   = "^(" + C + ")?" + v;                         // vowel in stem
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    61
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    62
  this.stemWord = function (w) {
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    63
    var stem;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    64
    var suffix;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    65
    var firstch;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    66
    var origword = w;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    67
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    68
    if (w.length < 3)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    69
      return w;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    70
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    71
    var re;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    72
    var re2;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    73
    var re3;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    74
    var re4;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    75
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    76
    firstch = w.substr(0,1);
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    77
    if (firstch == "y")
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    78
      w = firstch.toUpperCase() + w.substr(1);
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    79
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    80
    // Step 1a
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    81
    re = /^(.+?)(ss|i)es$/;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    82
    re2 = /^(.+?)([^s])s$/;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    83
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    84
    if (re.test(w))
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    85
      w = w.replace(re,"$1$2");
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    86
    else if (re2.test(w))
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    87
      w = w.replace(re2,"$1$2");
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    88
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    89
    // Step 1b
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    90
    re = /^(.+?)eed$/;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    91
    re2 = /^(.+?)(ed|ing)$/;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    92
    if (re.test(w)) {
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    93
      var fp = re.exec(w);
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    94
      re = new RegExp(mgr0);
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    95
      if (re.test(fp[1])) {
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    96
        re = /.$/;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    97
        w = w.replace(re,"");
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    98
      }
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
    99
    }
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   100
    else if (re2.test(w)) {
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   101
      var fp = re2.exec(w);
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   102
      stem = fp[1];
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   103
      re2 = new RegExp(s_v);
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   104
      if (re2.test(stem)) {
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   105
        w = stem;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   106
        re2 = /(at|bl|iz)$/;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   107
        re3 = new RegExp("([^aeiouylsz])\\1$");
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   108
        re4 = new RegExp("^" + C + v + "[^aeiouwxy]$");
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   109
        if (re2.test(w))
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   110
          w = w + "e";
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   111
        else if (re3.test(w)) {
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   112
          re = /.$/;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   113
          w = w.replace(re,"");
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   114
        }
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   115
        else if (re4.test(w))
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   116
          w = w + "e";
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   117
      }
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   118
    }
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   119
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   120
    // Step 1c
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   121
    re = /^(.+?)y$/;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   122
    if (re.test(w)) {
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   123
      var fp = re.exec(w);
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   124
      stem = fp[1];
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   125
      re = new RegExp(s_v);
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   126
      if (re.test(stem))
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   127
        w = stem + "i";
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   128
    }
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   129
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   130
    // Step 2
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   131
    re = /^(.+?)(ational|tional|enci|anci|izer|bli|alli|entli|eli|ousli|ization|ation|ator|alism|iveness|fulness|ousness|aliti|iviti|biliti|logi)$/;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   132
    if (re.test(w)) {
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   133
      var fp = re.exec(w);
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   134
      stem = fp[1];
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   135
      suffix = fp[2];
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   136
      re = new RegExp(mgr0);
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   137
      if (re.test(stem))
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   138
        w = stem + step2list[suffix];
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   139
    }
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   140
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   141
    // Step 3
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   142
    re = /^(.+?)(icate|ative|alize|iciti|ical|ful|ness)$/;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   143
    if (re.test(w)) {
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   144
      var fp = re.exec(w);
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   145
      stem = fp[1];
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   146
      suffix = fp[2];
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   147
      re = new RegExp(mgr0);
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   148
      if (re.test(stem))
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   149
        w = stem + step3list[suffix];
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   150
    }
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   151
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   152
    // Step 4
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   153
    re = /^(.+?)(al|ance|ence|er|ic|able|ible|ant|ement|ment|ent|ou|ism|ate|iti|ous|ive|ize)$/;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   154
    re2 = /^(.+?)(s|t)(ion)$/;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   155
    if (re.test(w)) {
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   156
      var fp = re.exec(w);
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   157
      stem = fp[1];
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   158
      re = new RegExp(mgr1);
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   159
      if (re.test(stem))
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   160
        w = stem;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   161
    }
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   162
    else if (re2.test(w)) {
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   163
      var fp = re2.exec(w);
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   164
      stem = fp[1] + fp[2];
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   165
      re2 = new RegExp(mgr1);
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   166
      if (re2.test(stem))
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   167
        w = stem;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   168
    }
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   169
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   170
    // Step 5
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   171
    re = /^(.+?)e$/;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   172
    if (re.test(w)) {
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   173
      var fp = re.exec(w);
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   174
      stem = fp[1];
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   175
      re = new RegExp(mgr1);
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   176
      re2 = new RegExp(meq1);
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   177
      re3 = new RegExp("^" + C + v + "[^aeiouwxy]$");
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   178
      if (re.test(stem) || (re2.test(stem) && !(re3.test(stem))))
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   179
        w = stem;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   180
    }
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   181
    re = /ll$/;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   182
    re2 = new RegExp(mgr1);
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   183
    if (re.test(w) && re2.test(w)) {
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   184
      re = /.$/;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   185
      w = w.replace(re,"");
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   186
    }
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   187
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   188
    // and turn initial Y back to y
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   189
    if (firstch == "y")
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   190
      w = firstch.toLowerCase() + w.substr(1);
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   191
    return w;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   192
  }
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   193
}
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   194
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   195
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   196
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   197
/**
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   198
 * Simple result scoring code.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   199
 */
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   200
var Scorer = {
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   201
  // Implement the following function to further tweak the score for each result
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   202
  // The function takes a result array [filename, title, anchor, descr, score]
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   203
  // and returns the new score.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   204
  /*
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   205
  score: function(result) {
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   206
    return result[4];
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   207
  },
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   208
  */
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   209
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   210
  // query matches the full name of an object
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   211
  objNameMatch: 11,
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   212
  // or matches in the last dotted part of the object name
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   213
  objPartialMatch: 6,
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   214
  // Additive scores depending on the priority of the object
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   215
  objPrio: {0:  15,   // used to be importantResults
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   216
            1:  5,   // used to be objectResults
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   217
            2: -5},  // used to be unimportantResults
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   218
  //  Used when the priority is not in the mapping.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   219
  objPrioDefault: 0,
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   220
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   221
  // query found in title
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   222
  title: 15,
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   223
  // query found in terms
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   224
  term: 5
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   225
};
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   226
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   227
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   228
/**
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   229
 * Search Module
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   230
 */
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   231
var Search = {
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   232
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   233
  _index : null,
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   234
  _queued_query : null,
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   235
  _pulse_status : -1,
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   236
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   237
  init : function() {
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   238
      var params = $.getQueryParameters();
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   239
      if (params.q) {
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   240
          var query = params.q[0];
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   241
          $('input[name="q"]')[0].value = query;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   242
          this.performSearch(query);
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   243
      }
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   244
  },
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   245
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   246
  loadIndex : function(url) {
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   247
    $.ajax({type: "GET", url: url, data: null,
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   248
            dataType: "script", cache: true,
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   249
            complete: function(jqxhr, textstatus) {
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   250
              if (textstatus != "success") {
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   251
                document.getElementById("searchindexloader").src = url;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   252
              }
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   253
            }});
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   254
  },
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   255
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   256
  setIndex : function(index) {
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   257
    var q;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   258
    this._index = index;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   259
    if ((q = this._queued_query) !== null) {
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   260
      this._queued_query = null;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   261
      Search.query(q);
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   262
    }
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   263
  },
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   264
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   265
  hasIndex : function() {
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   266
      return this._index !== null;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   267
  },
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   268
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   269
  deferQuery : function(query) {
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   270
      this._queued_query = query;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   271
  },
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   272
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   273
  stopPulse : function() {
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   274
      this._pulse_status = 0;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   275
  },
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   276
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   277
  startPulse : function() {
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   278
    if (this._pulse_status >= 0)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   279
        return;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   280
    function pulse() {
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   281
      var i;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   282
      Search._pulse_status = (Search._pulse_status + 1) % 4;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   283
      var dotString = '';
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   284
      for (i = 0; i < Search._pulse_status; i++)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   285
        dotString += '.';
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   286
      Search.dots.text(dotString);
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   287
      if (Search._pulse_status > -1)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   288
        window.setTimeout(pulse, 500);
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   289
    }
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   290
    pulse();
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   291
  },
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   292
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   293
  /**
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   294
   * perform a search for something (or wait until index is loaded)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   295
   */
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   296
  performSearch : function(query) {
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   297
    // create the required interface elements
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   298
    this.out = $('#search-results');
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   299
    this.title = $('<h2>' + _('Searching') + '</h2>').appendTo(this.out);
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   300
    this.dots = $('<span></span>').appendTo(this.title);
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   301
    this.status = $('<p style="display: none"></p>').appendTo(this.out);
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   302
    this.output = $('<ul class="search"/>').appendTo(this.out);
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   303
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   304
    $('#search-progress').text(_('Preparing search...'));
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   305
    this.startPulse();
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   306
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   307
    // index already loaded, the browser was quick!
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   308
    if (this.hasIndex())
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   309
      this.query(query);
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   310
    else
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   311
      this.deferQuery(query);
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   312
  },
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   313
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   314
  /**
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   315
   * execute search (requires search index to be loaded)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   316
   */
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   317
  query : function(query) {
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   318
    var i;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   319
    var stopwords = ["a","and","are","as","at","be","but","by","for","if","in","into","is","it","near","no","not","of","on","or","such","that","the","their","then","there","these","they","this","to","was","will","with"];
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   320
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   321
    // stem the searchterms and add them to the correct list
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   322
    var stemmer = new Stemmer();
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   323
    var searchterms = [];
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   324
    var excluded = [];
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   325
    var hlterms = [];
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   326
    var tmp = query.split(/\s+/);
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   327
    var objectterms = [];
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   328
    for (i = 0; i < tmp.length; i++) {
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   329
      if (tmp[i] !== "") {
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   330
          objectterms.push(tmp[i].toLowerCase());
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   331
      }
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   332
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   333
      if ($u.indexOf(stopwords, tmp[i].toLowerCase()) != -1 || tmp[i].match(/^\d+$/) ||
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   334
          tmp[i] === "") {
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   335
        // skip this "word"
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   336
        continue;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   337
      }
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   338
      // stem the word
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   339
      var word = stemmer.stemWord(tmp[i].toLowerCase());
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   340
      var toAppend;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   341
      // select the correct list
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   342
      if (word[0] == '-') {
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   343
        toAppend = excluded;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   344
        word = word.substr(1);
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   345
      }
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   346
      else {
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   347
        toAppend = searchterms;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   348
        hlterms.push(tmp[i].toLowerCase());
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   349
      }
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   350
      // only add if not already in the list
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   351
      if (!$u.contains(toAppend, word))
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   352
        toAppend.push(word);
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   353
    }
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   354
    var highlightstring = '?highlight=' + $.urlencode(hlterms.join(" "));
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   355
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   356
    // console.debug('SEARCH: searching for:');
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   357
    // console.info('required: ', searchterms);
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   358
    // console.info('excluded: ', excluded);
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   359
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   360
    // prepare search
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   361
    var terms = this._index.terms;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   362
    var titleterms = this._index.titleterms;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   363
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   364
    // array of [filename, title, anchor, descr, score]
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   365
    var results = [];
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   366
    $('#search-progress').empty();
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   367
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   368
    // lookup as object
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   369
    for (i = 0; i < objectterms.length; i++) {
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   370
      var others = [].concat(objectterms.slice(0, i),
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   371
                             objectterms.slice(i+1, objectterms.length));
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   372
      results = results.concat(this.performObjectSearch(objectterms[i], others));
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   373
    }
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   374
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   375
    // lookup as search terms in fulltext
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   376
    results = results.concat(this.performTermsSearch(searchterms, excluded, terms, Scorer.term))
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   377
                     .concat(this.performTermsSearch(searchterms, excluded, titleterms, Scorer.title));
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   378
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   379
    // let the scorer override scores with a custom scoring function
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   380
    if (Scorer.score) {
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   381
      for (i = 0; i < results.length; i++)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   382
        results[i][4] = Scorer.score(results[i]);
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   383
    }
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   384
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   385
    // now sort the results by score (in opposite order of appearance, since the
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   386
    // display function below uses pop() to retrieve items) and then
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   387
    // alphabetically
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   388
    results.sort(function(a, b) {
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   389
      var left = a[4];
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   390
      var right = b[4];
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   391
      if (left > right) {
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   392
        return 1;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   393
      } else if (left < right) {
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   394
        return -1;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   395
      } else {
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   396
        // same score: sort alphabetically
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   397
        left = a[1].toLowerCase();
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   398
        right = b[1].toLowerCase();
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   399
        return (left > right) ? -1 : ((left < right) ? 1 : 0);
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   400
      }
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   401
    });
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   402
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   403
    // for debugging
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   404
    //Search.lastresults = results.slice();  // a copy
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   405
    //console.info('search results:', Search.lastresults);
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   406
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   407
    // print the results
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   408
    var resultCount = results.length;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   409
    function displayNextItem() {
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   410
      // results left, load the summary and display it
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   411
      if (results.length) {
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   412
        var item = results.pop();
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   413
        var listItem = $('<li style="display:none"></li>');
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   414
        if (DOCUMENTATION_OPTIONS.FILE_SUFFIX === '') {
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   415
          // dirhtml builder
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   416
          var dirname = item[0] + '/';
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   417
          if (dirname.match(/\/index\/$/)) {
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   418
            dirname = dirname.substring(0, dirname.length-6);
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   419
          } else if (dirname == 'index/') {
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   420
            dirname = '';
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   421
          }
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   422
          listItem.append($('<a/>').attr('href',
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   423
            DOCUMENTATION_OPTIONS.URL_ROOT + dirname +
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   424
            highlightstring + item[2]).html(item[1]));
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   425
        } else {
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   426
          // normal html builders
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   427
          listItem.append($('<a/>').attr('href',
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   428
            item[0] + DOCUMENTATION_OPTIONS.FILE_SUFFIX +
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   429
            highlightstring + item[2]).html(item[1]));
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   430
        }
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   431
        if (item[3]) {
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   432
          listItem.append($('<span> (' + item[3] + ')</span>'));
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   433
          Search.output.append(listItem);
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   434
          listItem.slideDown(5, function() {
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   435
            displayNextItem();
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   436
          });
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   437
        } else if (DOCUMENTATION_OPTIONS.HAS_SOURCE) {
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   438
          $.ajax({url: DOCUMENTATION_OPTIONS.URL_ROOT + '_sources/' + item[0] + '.txt',
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   439
                  dataType: "text",
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   440
                  complete: function(jqxhr, textstatus) {
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   441
                    var data = jqxhr.responseText;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   442
                    if (data !== '') {
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   443
                      listItem.append(Search.makeSearchSummary(data, searchterms, hlterms));
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   444
                    }
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   445
                    Search.output.append(listItem);
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   446
                    listItem.slideDown(5, function() {
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   447
                      displayNextItem();
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   448
                    });
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   449
                  }});
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   450
        } else {
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   451
          // no source available, just display title
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   452
          Search.output.append(listItem);
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   453
          listItem.slideDown(5, function() {
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   454
            displayNextItem();
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   455
          });
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   456
        }
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   457
      }
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   458
      // search finished, update title and status message
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   459
      else {
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   460
        Search.stopPulse();
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   461
        Search.title.text(_('Search Results'));
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   462
        if (!resultCount)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   463
          Search.status.text(_('Your search did not match any documents. Please make sure that all words are spelled correctly and that you\'ve selected enough categories.'));
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   464
        else
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   465
            Search.status.text(_('Search finished, found %s page(s) matching the search query.').replace('%s', resultCount));
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   466
        Search.status.fadeIn(500);
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   467
      }
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   468
    }
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   469
    displayNextItem();
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   470
  },
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   471
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   472
  /**
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   473
   * search for object names
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   474
   */
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   475
  performObjectSearch : function(object, otherterms) {
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   476
    var filenames = this._index.filenames;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   477
    var objects = this._index.objects;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   478
    var objnames = this._index.objnames;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   479
    var titles = this._index.titles;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   480
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   481
    var i;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   482
    var results = [];
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   483
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   484
    for (var prefix in objects) {
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   485
      for (var name in objects[prefix]) {
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   486
        var fullname = (prefix ? prefix + '.' : '') + name;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   487
        if (fullname.toLowerCase().indexOf(object) > -1) {
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   488
          var score = 0;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   489
          var parts = fullname.split('.');
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   490
          // check for different match types: exact matches of full name or
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   491
          // "last name" (i.e. last dotted part)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   492
          if (fullname == object || parts[parts.length - 1] == object) {
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   493
            score += Scorer.objNameMatch;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   494
          // matches in last name
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   495
          } else if (parts[parts.length - 1].indexOf(object) > -1) {
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   496
            score += Scorer.objPartialMatch;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   497
          }
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   498
          var match = objects[prefix][name];
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   499
          var objname = objnames[match[1]][2];
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   500
          var title = titles[match[0]];
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   501
          // If more than one term searched for, we require other words to be
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   502
          // found in the name/title/description
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   503
          if (otherterms.length > 0) {
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   504
            var haystack = (prefix + ' ' + name + ' ' +
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   505
                            objname + ' ' + title).toLowerCase();
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   506
            var allfound = true;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   507
            for (i = 0; i < otherterms.length; i++) {
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   508
              if (haystack.indexOf(otherterms[i]) == -1) {
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   509
                allfound = false;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   510
                break;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   511
              }
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   512
            }
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   513
            if (!allfound) {
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   514
              continue;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   515
            }
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   516
          }
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   517
          var descr = objname + _(', in ') + title;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   518
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   519
          var anchor = match[3];
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   520
          if (anchor === '')
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   521
            anchor = fullname;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   522
          else if (anchor == '-')
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   523
            anchor = objnames[match[1]][1] + '-' + fullname;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   524
          // add custom score for some objects according to scorer
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   525
          if (Scorer.objPrio.hasOwnProperty(match[2])) {
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   526
            score += Scorer.objPrio[match[2]];
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   527
          } else {
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   528
            score += Scorer.objPrioDefault;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   529
          }
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   530
          results.push([filenames[match[0]], fullname, '#'+anchor, descr, score]);
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   531
        }
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   532
      }
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   533
    }
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   534
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   535
    return results;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   536
  },
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   537
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   538
  /**
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   539
   * search for full-text terms in the index
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   540
   */
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   541
  performTermsSearch : function(searchterms, excluded, terms, score) {
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   542
    var filenames = this._index.filenames;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   543
    var titles = this._index.titles;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   544
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   545
    var i, j, file, files;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   546
    var fileMap = {};
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   547
    var results = [];
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   548
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   549
    // perform the search on the required terms
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   550
    for (i = 0; i < searchterms.length; i++) {
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   551
      var word = searchterms[i];
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   552
      // no match but word was a required one
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   553
      if ((files = terms[word]) === undefined)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   554
        break;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   555
      if (files.length === undefined) {
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   556
        files = [files];
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   557
      }
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   558
      // create the mapping
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   559
      for (j = 0; j < files.length; j++) {
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   560
        file = files[j];
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   561
        if (file in fileMap)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   562
          fileMap[file].push(word);
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   563
        else
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   564
          fileMap[file] = [word];
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   565
      }
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   566
    }
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   567
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   568
    // now check if the files don't contain excluded terms
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   569
    for (file in fileMap) {
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   570
      var valid = true;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   571
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   572
      // check if all requirements are matched
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   573
      if (fileMap[file].length != searchterms.length)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   574
          continue;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   575
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   576
      // ensure that none of the excluded terms is in the search result
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   577
      for (i = 0; i < excluded.length; i++) {
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   578
        if (terms[excluded[i]] == file ||
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   579
          $u.contains(terms[excluded[i]] || [], file)) {
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   580
          valid = false;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   581
          break;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   582
        }
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   583
      }
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   584
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   585
      // if we have still a valid result we can add it to the result list
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   586
      if (valid) {
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   587
        results.push([filenames[file], titles[file], '', null, score]);
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   588
      }
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   589
    }
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   590
    return results;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   591
  },
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   592
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   593
  /**
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   594
   * helper function to return a node containing the
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   595
   * search summary for a given text. keywords is a list
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   596
   * of stemmed words, hlwords is the list of normal, unstemmed
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   597
   * words. the first one is used to find the occurance, the
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   598
   * latter for highlighting it.
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   599
   */
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   600
  makeSearchSummary : function(text, keywords, hlwords) {
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   601
    var textLower = text.toLowerCase();
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   602
    var start = 0;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   603
    $.each(keywords, function() {
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   604
      var i = textLower.indexOf(this.toLowerCase());
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   605
      if (i > -1)
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   606
        start = i;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   607
    });
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   608
    start = Math.max(start - 120, 0);
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   609
    var excerpt = ((start > 0) ? '...' : '') +
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   610
      $.trim(text.substr(start, 240)) +
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   611
      ((start + 240 - text.length) ? '...' : '');
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   612
    var rv = $('<div class="context"></div>').text(excerpt);
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   613
    $.each(hlwords, function() {
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   614
      rv = rv.highlightText(this, 'highlighted');
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   615
    });
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   616
    return rv;
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   617
  }
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   618
};
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   619
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   620
$(document).ready(function() {
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   621
  Search.init();
c6a303a2f8c5 PSARC/2014/362 Jansson
Tomas Heran <tomas.heran@oracle.com>
parents:
diff changeset
   622
});