author | hannesw |
Thu, 25 Apr 2019 09:12:40 +0200 | |
changeset 54619 | b43cc3b9ef40 |
parent 54589 | 3babb3ed24c6 |
permissions | -rw-r--r-- |
33920 | 1 |
/* |
54619
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
2 |
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved. |
33920 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
24 |
*/ |
|
25 |
||
26 |
var noResult = {l: "No results found"}; |
|
40511 | 27 |
var catModules = "Modules"; |
33920 | 28 |
var catPackages = "Packages"; |
29 |
var catTypes = "Types"; |
|
30 |
var catMembers = "Members"; |
|
31 |
var catSearchTags = "SearchTags"; |
|
41523
da4f500b886d
8141636: Javadoc search should support camelCase search
bpatel
parents:
41032
diff
changeset
|
32 |
var highlight = "<span class=\"resultHighlight\">$&</span>"; |
54619
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
33 |
var searchPattern = ""; |
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
34 |
var RANKING_THRESHOLD = 2; |
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
35 |
var NO_MATCH = 0xffff; |
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
36 |
var MAX_RESULTS_PER_CATEGORY = 500; |
51607
5eb48e9d607a
8176453: Javadoc search: there are issues with generics in parameters
hannesw
parents:
50856
diff
changeset
|
37 |
function escapeHtml(str) { |
5eb48e9d607a
8176453: Javadoc search: there are issues with generics in parameters
hannesw
parents:
50856
diff
changeset
|
38 |
return str.replace(/</g, "<").replace(/>/g, ">"); |
5eb48e9d607a
8176453: Javadoc search: there are issues with generics in parameters
hannesw
parents:
50856
diff
changeset
|
39 |
} |
54619
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
40 |
function getHighlightedText(item, matcher) { |
51607
5eb48e9d607a
8176453: Javadoc search: there are issues with generics in parameters
hannesw
parents:
50856
diff
changeset
|
41 |
var escapedItem = escapeHtml(item); |
54619
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
42 |
return escapedItem.replace(matcher, highlight); |
41523
da4f500b886d
8141636: Javadoc search should support camelCase search
bpatel
parents:
41032
diff
changeset
|
43 |
} |
48991
978c3036fbfc
8198522: Javadoc search broken after output files organization for modules
bpatel
parents:
47216
diff
changeset
|
44 |
function getURLPrefix(ui) { |
978c3036fbfc
8198522: Javadoc search broken after output files organization for modules
bpatel
parents:
47216
diff
changeset
|
45 |
var urlPrefix=""; |
54589
3babb3ed24c6
8215580: Remove support for `--no-module-directories`
pmuthuswamy
parents:
54358
diff
changeset
|
46 |
var slash = "/"; |
3babb3ed24c6
8215580: Remove support for `--no-module-directories`
pmuthuswamy
parents:
54358
diff
changeset
|
47 |
if (ui.item.category === catModules) { |
3babb3ed24c6
8215580: Remove support for `--no-module-directories`
pmuthuswamy
parents:
54358
diff
changeset
|
48 |
return ui.item.l + slash; |
3babb3ed24c6
8215580: Remove support for `--no-module-directories`
pmuthuswamy
parents:
54358
diff
changeset
|
49 |
} else if (ui.item.category === catPackages && ui.item.m) { |
3babb3ed24c6
8215580: Remove support for `--no-module-directories`
pmuthuswamy
parents:
54358
diff
changeset
|
50 |
return ui.item.m + slash; |
3babb3ed24c6
8215580: Remove support for `--no-module-directories`
pmuthuswamy
parents:
54358
diff
changeset
|
51 |
} else if ((ui.item.category === catTypes && ui.item.p) || ui.item.category === catMembers) { |
3babb3ed24c6
8215580: Remove support for `--no-module-directories`
pmuthuswamy
parents:
54358
diff
changeset
|
52 |
$.each(packageSearchIndex, function(index, item) { |
3babb3ed24c6
8215580: Remove support for `--no-module-directories`
pmuthuswamy
parents:
54358
diff
changeset
|
53 |
if (item.m && ui.item.p == item.l) { |
3babb3ed24c6
8215580: Remove support for `--no-module-directories`
pmuthuswamy
parents:
54358
diff
changeset
|
54 |
urlPrefix = item.m + slash; |
3babb3ed24c6
8215580: Remove support for `--no-module-directories`
pmuthuswamy
parents:
54358
diff
changeset
|
55 |
} |
3babb3ed24c6
8215580: Remove support for `--no-module-directories`
pmuthuswamy
parents:
54358
diff
changeset
|
56 |
}); |
3babb3ed24c6
8215580: Remove support for `--no-module-directories`
pmuthuswamy
parents:
54358
diff
changeset
|
57 |
return urlPrefix; |
3babb3ed24c6
8215580: Remove support for `--no-module-directories`
pmuthuswamy
parents:
54358
diff
changeset
|
58 |
} else { |
3babb3ed24c6
8215580: Remove support for `--no-module-directories`
pmuthuswamy
parents:
54358
diff
changeset
|
59 |
return urlPrefix; |
48991
978c3036fbfc
8198522: Javadoc search broken after output files organization for modules
bpatel
parents:
47216
diff
changeset
|
60 |
} |
978c3036fbfc
8198522: Javadoc search broken after output files organization for modules
bpatel
parents:
47216
diff
changeset
|
61 |
return urlPrefix; |
978c3036fbfc
8198522: Javadoc search broken after output files organization for modules
bpatel
parents:
47216
diff
changeset
|
62 |
} |
54619
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
63 |
function makeCamelCaseRegex(term) { |
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
64 |
var pattern = ""; |
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
65 |
var isWordToken = false; |
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
66 |
term.replace(/,\s*/g, ", ").trim().split(/\s+/).forEach(function(w, index) { |
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
67 |
if (index > 0) { |
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
68 |
// whitespace between identifiers is significant |
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
69 |
pattern += (isWordToken && /^\w/.test(w)) ? "\\s+" : "\\s*"; |
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
70 |
} |
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
71 |
var tokens = w.split(/(?=[A-Z,.()<>[\/])/); |
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
72 |
for (var i = 0; i < tokens.length; i++) { |
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
73 |
var s = tokens[i]; |
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
74 |
if (s === "") { |
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
75 |
continue; |
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
76 |
} |
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
77 |
pattern += $.ui.autocomplete.escapeRegex(s); |
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
78 |
isWordToken = /\w$/.test(s); |
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
79 |
if (isWordToken) { |
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
80 |
pattern += "([a-z0-9_$<>\\[\\]]*?)"; |
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
81 |
} |
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
82 |
} |
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
83 |
}); |
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
84 |
return pattern; |
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
85 |
} |
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
86 |
function createMatcher(pattern, flags) { |
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
87 |
var isCamelCase = /[A-Z]/.test(pattern); |
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
88 |
return new RegExp(pattern, flags + (isCamelCase ? "" : "i")); |
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
89 |
} |
33920 | 90 |
var watermark = 'Search'; |
91 |
$(function() { |
|
47047
91082c3c1d05
8182263: Search box and reset button needs to be a11y fixed.
bpatel
parents:
45496
diff
changeset
|
92 |
$("#search").val(''); |
33920 | 93 |
$("#search").prop("disabled", false); |
94 |
$("#reset").prop("disabled", false); |
|
95 |
$("#search").val(watermark).addClass('watermark'); |
|
41523
da4f500b886d
8141636: Javadoc search should support camelCase search
bpatel
parents:
41032
diff
changeset
|
96 |
$("#search").blur(function() { |
33920 | 97 |
if ($(this).val().length == 0) { |
98 |
$(this).val(watermark).addClass('watermark'); |
|
99 |
} |
|
100 |
}); |
|
54358 | 101 |
$("#search").on('click keydown paste', function() { |
41523
da4f500b886d
8141636: Javadoc search should support camelCase search
bpatel
parents:
41032
diff
changeset
|
102 |
if ($(this).val() == watermark) { |
33920 | 103 |
$(this).val('').removeClass('watermark'); |
104 |
} |
|
105 |
}); |
|
41523
da4f500b886d
8141636: Javadoc search should support camelCase search
bpatel
parents:
41032
diff
changeset
|
106 |
$("#reset").click(function() { |
da4f500b886d
8141636: Javadoc search should support camelCase search
bpatel
parents:
41032
diff
changeset
|
107 |
$("#search").val(''); |
da4f500b886d
8141636: Javadoc search should support camelCase search
bpatel
parents:
41032
diff
changeset
|
108 |
$("#search").focus(); |
33920 | 109 |
}); |
110 |
$("#search").focus(); |
|
41523
da4f500b886d
8141636: Javadoc search should support camelCase search
bpatel
parents:
41032
diff
changeset
|
111 |
$("#search")[0].setSelectionRange(0, 0); |
33920 | 112 |
}); |
113 |
$.widget("custom.catcomplete", $.ui.autocomplete, { |
|
114 |
_create: function() { |
|
115 |
this._super(); |
|
116 |
this.widget().menu("option", "items", "> :not(.ui-autocomplete-category)"); |
|
117 |
}, |
|
118 |
_renderMenu: function(ul, items) { |
|
54619
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
119 |
var rMenu = this; |
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
120 |
var currentCategory = ""; |
52961
d67b37917e82
8214468: jQuery UI upgrade from 1.11.4 to 1.12.1
pmuthuswamy
parents:
52391
diff
changeset
|
121 |
rMenu.menu.bindings = $(); |
33920 | 122 |
$.each(items, function(index, item) { |
123 |
var li; |
|
124 |
if (item.l !== noResult.l && item.category !== currentCategory) { |
|
125 |
ul.append("<li class=\"ui-autocomplete-category\">" + item.category + "</li>"); |
|
126 |
currentCategory = item.category; |
|
127 |
} |
|
128 |
li = rMenu._renderItemData(ul, item); |
|
129 |
if (item.category) { |
|
130 |
li.attr("aria-label", item.category + " : " + item.l); |
|
131 |
li.attr("class", "resultItem"); |
|
132 |
} else { |
|
133 |
li.attr("aria-label", item.l); |
|
134 |
li.attr("class", "resultItem"); |
|
135 |
} |
|
136 |
}); |
|
137 |
}, |
|
138 |
_renderItem: function(ul, item) { |
|
139 |
var label = ""; |
|
54619
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
140 |
var matcher = createMatcher(escapeHtml(searchPattern), "g"); |
40511 | 141 |
if (item.category === catModules) { |
54619
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
142 |
label = getHighlightedText(item.l, matcher); |
40511 | 143 |
} else if (item.category === catPackages) { |
144 |
label = (item.m) |
|
54619
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
145 |
? getHighlightedText(item.m + "/" + item.l, matcher) |
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
146 |
: getHighlightedText(item.l, matcher); |
33920 | 147 |
} else if (item.category === catTypes) { |
50167
cc705c956798
8196201: Generate pages to list all classes and all packages in javadoc output
bpatel
parents:
49427
diff
changeset
|
148 |
label = (item.p) |
54619
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
149 |
? getHighlightedText(item.p + "." + item.l, matcher) |
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
150 |
: getHighlightedText(item.l, matcher); |
33920 | 151 |
} else if (item.category === catMembers) { |
54619
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
152 |
label = getHighlightedText(item.p + "." + (item.c + "." + item.l), matcher); |
33920 | 153 |
} else if (item.category === catSearchTags) { |
54619
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
154 |
label = getHighlightedText(item.l, matcher); |
33920 | 155 |
} else { |
156 |
label = item.l; |
|
157 |
} |
|
51740
f79cfb07f13f
8209914: javadoc search sometimes generates bad URIs
hannesw
parents:
51607
diff
changeset
|
158 |
var li = $("<li/>").appendTo(ul); |
52961
d67b37917e82
8214468: jQuery UI upgrade from 1.11.4 to 1.12.1
pmuthuswamy
parents:
52391
diff
changeset
|
159 |
var div = $("<div/>").appendTo(li); |
33920 | 160 |
if (item.category === catSearchTags) { |
161 |
if (item.d) { |
|
52961
d67b37917e82
8214468: jQuery UI upgrade from 1.11.4 to 1.12.1
pmuthuswamy
parents:
52391
diff
changeset
|
162 |
div.html(label + "<span class=\"searchTagHolderResult\"> (" + item.h + ")</span><br><span class=\"searchTagDescResult\">" |
51740
f79cfb07f13f
8209914: javadoc search sometimes generates bad URIs
hannesw
parents:
51607
diff
changeset
|
163 |
+ item.d + "</span><br>"); |
33920 | 164 |
} else { |
52961
d67b37917e82
8214468: jQuery UI upgrade from 1.11.4 to 1.12.1
pmuthuswamy
parents:
52391
diff
changeset
|
165 |
div.html(label + "<span class=\"searchTagHolderResult\"> (" + item.h + ")</span>"); |
33920 | 166 |
} |
167 |
} else { |
|
52961
d67b37917e82
8214468: jQuery UI upgrade from 1.11.4 to 1.12.1
pmuthuswamy
parents:
52391
diff
changeset
|
168 |
div.html(label); |
33920 | 169 |
} |
51740
f79cfb07f13f
8209914: javadoc search sometimes generates bad URIs
hannesw
parents:
51607
diff
changeset
|
170 |
return li; |
33920 | 171 |
} |
172 |
}); |
|
54619
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
173 |
function rankMatch(match, category) { |
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
174 |
if (!match) { |
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
175 |
return NO_MATCH; |
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
176 |
} |
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
177 |
var index = match.index; |
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
178 |
var input = match.input; |
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
179 |
var leftBoundaryMatch = 2; |
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
180 |
var periferalMatch = 0; |
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
181 |
var delta = 0; |
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
182 |
// make sure match is anchored on a left word boundary |
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
183 |
if (index === 0 || /\W/.test(input[index - 1]) || "_" === input[index - 1] || "_" === input[index]) { |
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
184 |
leftBoundaryMatch = 0; |
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
185 |
} else if (input[index] === input[index].toUpperCase() && !/^[A-Z0-9_$]+$/.test(input)) { |
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
186 |
leftBoundaryMatch = 1; |
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
187 |
} |
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
188 |
var matchEnd = index + match[0].length; |
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
189 |
var leftParen = input.indexOf("("); |
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
190 |
// exclude peripheral matches |
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
191 |
if (category !== catModules && category !== catSearchTags) { |
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
192 |
var endOfName = leftParen > -1 ? leftParen : input.length; |
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
193 |
var delim = category === catPackages ? "/" : "."; |
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
194 |
if (leftParen > -1 && leftParen < index) { |
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
195 |
periferalMatch += 2; |
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
196 |
} else if (input.lastIndexOf(delim, endOfName) >= matchEnd) { |
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
197 |
periferalMatch += 2; |
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
198 |
} |
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
199 |
} |
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
200 |
for (var i = 1; i < match.length; i++) { |
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
201 |
// lower ranking if parts of the name are missing |
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
202 |
if (match[i]) |
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
203 |
delta += match[i].length; |
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
204 |
} |
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
205 |
if (category === catTypes) { |
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
206 |
// lower ranking if a type name contains unmatched camel-case parts |
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
207 |
if (/[A-Z]/.test(input.substring(matchEnd))) |
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
208 |
delta += 5; |
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
209 |
if (/[A-Z]/.test(input.substring(0, index))) |
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
210 |
delta += 5; |
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
211 |
} |
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
212 |
return leftBoundaryMatch + periferalMatch + (delta / 200); |
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
213 |
|
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
214 |
} |
33920 | 215 |
$(function() { |
216 |
$("#search").catcomplete({ |
|
217 |
minLength: 1, |
|
52391
ac5a55c19bad
8210405: Javadoc search doesn't always consider full input upon Enter
hannesw
parents:
51740
diff
changeset
|
218 |
delay: 300, |
33920 | 219 |
source: function(request, response) { |
54619
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
220 |
var result = []; |
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
221 |
var newResults = []; |
43762
515fe48569fe
8168965: search items are not listed in any sensible order
bpatel
parents:
41523
diff
changeset
|
222 |
|
54619
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
223 |
searchPattern = makeCamelCaseRegex(request.term); |
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
224 |
if (searchPattern === "") { |
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
225 |
return this.close(); |
43762
515fe48569fe
8168965: search items are not listed in any sensible order
bpatel
parents:
41523
diff
changeset
|
226 |
} |
54619
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
227 |
var camelCaseMatcher = createMatcher(searchPattern, ""); |
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
228 |
var boundaryMatcher = createMatcher("\\b" + searchPattern, ""); |
43762
515fe48569fe
8168965: search items are not listed in any sensible order
bpatel
parents:
41523
diff
changeset
|
229 |
|
50856
1857ca5aca37
8190876: javadoc search on "java.se" shows "java.se" the last one among other modules
hannesw
parents:
50167
diff
changeset
|
230 |
function concatResults(a1, a2) { |
54619
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
231 |
a2.sort(function(e1, e2) { |
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
232 |
return e1.ranking - e2.ranking; |
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
233 |
}); |
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
234 |
a1 = a1.concat(a2.map(function(e) { return e.item; })); |
43762
515fe48569fe
8168965: search items are not listed in any sensible order
bpatel
parents:
41523
diff
changeset
|
235 |
a2.length = 0; |
515fe48569fe
8168965: search items are not listed in any sensible order
bpatel
parents:
41523
diff
changeset
|
236 |
return a1; |
515fe48569fe
8168965: search items are not listed in any sensible order
bpatel
parents:
41523
diff
changeset
|
237 |
} |
515fe48569fe
8168965: search items are not listed in any sensible order
bpatel
parents:
41523
diff
changeset
|
238 |
|
40511 | 239 |
if (moduleSearchIndex) { |
240 |
$.each(moduleSearchIndex, function(index, item) { |
|
50856
1857ca5aca37
8190876: javadoc search on "java.se" shows "java.se" the last one among other modules
hannesw
parents:
50167
diff
changeset
|
241 |
item.category = catModules; |
54619
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
242 |
var ranking = rankMatch(boundaryMatcher.exec(item.l), catModules); |
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
243 |
if (ranking < RANKING_THRESHOLD) { |
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
244 |
newResults.push({ ranking: ranking, item: item }); |
33920 | 245 |
} |
54619
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
246 |
return newResults.length < MAX_RESULTS_PER_CATEGORY; |
33920 | 247 |
}); |
54619
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
248 |
result = concatResults(result, newResults); |
40511 | 249 |
} |
250 |
if (packageSearchIndex) { |
|
251 |
$.each(packageSearchIndex, function(index, item) { |
|
50856
1857ca5aca37
8190876: javadoc search on "java.se" shows "java.se" the last one among other modules
hannesw
parents:
50167
diff
changeset
|
252 |
item.category = catPackages; |
54619
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
253 |
var name = (item.m && request.term.indexOf("/") > -1) |
40511 | 254 |
? (item.m + "/" + item.l) |
255 |
: item.l; |
|
54619
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
256 |
var ranking = rankMatch(boundaryMatcher.exec(name), catPackages); |
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
257 |
if (ranking < RANKING_THRESHOLD) { |
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
258 |
newResults.push({ ranking: ranking, item: item }); |
40511 | 259 |
} |
54619
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
260 |
return newResults.length < MAX_RESULTS_PER_CATEGORY; |
40511 | 261 |
}); |
54619
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
262 |
result = concatResults(result, newResults); |
33920 | 263 |
} |
264 |
if (typeSearchIndex) { |
|
265 |
$.each(typeSearchIndex, function(index, item) { |
|
50856
1857ca5aca37
8190876: javadoc search on "java.se" shows "java.se" the last one among other modules
hannesw
parents:
50167
diff
changeset
|
266 |
item.category = catTypes; |
54619
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
267 |
var name = request.term.indexOf(".") > -1 |
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
268 |
? item.p + "." + item.l |
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
269 |
: item.l; |
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
270 |
var ranking = rankMatch(camelCaseMatcher.exec(name), catTypes); |
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
271 |
if (ranking < RANKING_THRESHOLD) { |
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
272 |
newResults.push({ ranking: ranking, item: item }); |
33920 | 273 |
} |
54619
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
274 |
return newResults.length < MAX_RESULTS_PER_CATEGORY; |
33920 | 275 |
}); |
54619
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
276 |
result = concatResults(result, newResults); |
33920 | 277 |
} |
278 |
if (memberSearchIndex) { |
|
279 |
$.each(memberSearchIndex, function(index, item) { |
|
50856
1857ca5aca37
8190876: javadoc search on "java.se" shows "java.se" the last one among other modules
hannesw
parents:
50167
diff
changeset
|
280 |
item.category = catMembers; |
54619
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
281 |
var name = request.term.indexOf(".") > -1 |
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
282 |
? item.p + "." + item.c + "." + item.l |
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
283 |
: item.l; |
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
284 |
var ranking = rankMatch(camelCaseMatcher.exec(name), catMembers); |
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
285 |
if (ranking < RANKING_THRESHOLD) { |
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
286 |
newResults.push({ ranking: ranking, item: item }); |
33920 | 287 |
} |
54619
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
288 |
return newResults.length < MAX_RESULTS_PER_CATEGORY; |
33920 | 289 |
}); |
54619
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
290 |
result = concatResults(result, newResults); |
33920 | 291 |
} |
292 |
if (tagSearchIndex) { |
|
293 |
$.each(tagSearchIndex, function(index, item) { |
|
50856
1857ca5aca37
8190876: javadoc search on "java.se" shows "java.se" the last one among other modules
hannesw
parents:
50167
diff
changeset
|
294 |
item.category = catSearchTags; |
54619
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
295 |
var ranking = rankMatch(boundaryMatcher.exec(item.l), catSearchTags); |
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
296 |
if (ranking < RANKING_THRESHOLD) { |
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
297 |
newResults.push({ ranking: ranking, item: item }); |
33920 | 298 |
} |
54619
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
299 |
return newResults.length < MAX_RESULTS_PER_CATEGORY; |
33920 | 300 |
}); |
54619
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
301 |
result = concatResults(result, newResults); |
33920 | 302 |
} |
54619
b43cc3b9ef40
8220497: Improve Javadoc search feature and add test coverage
hannesw
parents:
54589
diff
changeset
|
303 |
response(result); |
33920 | 304 |
}, |
305 |
response: function(event, ui) { |
|
306 |
if (!ui.content.length) { |
|
307 |
ui.content.push(noResult); |
|
308 |
} else { |
|
309 |
$("#search").empty(); |
|
310 |
} |
|
311 |
}, |
|
312 |
autoFocus: true, |
|
313 |
position: { |
|
314 |
collision: "flip" |
|
315 |
}, |
|
316 |
select: function(event, ui) { |
|
317 |
if (ui.item.l !== noResult.l) { |
|
48991
978c3036fbfc
8198522: Javadoc search broken after output files organization for modules
bpatel
parents:
47216
diff
changeset
|
318 |
var url = getURLPrefix(ui); |
40511 | 319 |
if (ui.item.category === catModules) { |
54589
3babb3ed24c6
8215580: Remove support for `--no-module-directories`
pmuthuswamy
parents:
54358
diff
changeset
|
320 |
url += "module-summary.html"; |
40511 | 321 |
} else if (ui.item.category === catPackages) { |
50167
cc705c956798
8196201: Generate pages to list all classes and all packages in javadoc output
bpatel
parents:
49427
diff
changeset
|
322 |
if (ui.item.url) { |
cc705c956798
8196201: Generate pages to list all classes and all packages in javadoc output
bpatel
parents:
49427
diff
changeset
|
323 |
url = ui.item.url; |
cc705c956798
8196201: Generate pages to list all classes and all packages in javadoc output
bpatel
parents:
49427
diff
changeset
|
324 |
} else { |
48991
978c3036fbfc
8198522: Javadoc search broken after output files organization for modules
bpatel
parents:
47216
diff
changeset
|
325 |
url += ui.item.l.replace(/\./g, '/') + "/package-summary.html"; |
50167
cc705c956798
8196201: Generate pages to list all classes and all packages in javadoc output
bpatel
parents:
49427
diff
changeset
|
326 |
} |
33920 | 327 |
} else if (ui.item.category === catTypes) { |
50167
cc705c956798
8196201: Generate pages to list all classes and all packages in javadoc output
bpatel
parents:
49427
diff
changeset
|
328 |
if (ui.item.url) { |
cc705c956798
8196201: Generate pages to list all classes and all packages in javadoc output
bpatel
parents:
49427
diff
changeset
|
329 |
url = ui.item.url; |
cc705c956798
8196201: Generate pages to list all classes and all packages in javadoc output
bpatel
parents:
49427
diff
changeset
|
330 |
} else if (ui.item.p === "<Unnamed>") { |
48991
978c3036fbfc
8198522: Javadoc search broken after output files organization for modules
bpatel
parents:
47216
diff
changeset
|
331 |
url += ui.item.l + ".html"; |
33920 | 332 |
} else { |
48991
978c3036fbfc
8198522: Javadoc search broken after output files organization for modules
bpatel
parents:
47216
diff
changeset
|
333 |
url += ui.item.p.replace(/\./g, '/') + "/" + ui.item.l + ".html"; |
33920 | 334 |
} |
335 |
} else if (ui.item.category === catMembers) { |
|
336 |
if (ui.item.p === "<Unnamed>") { |
|
48991
978c3036fbfc
8198522: Javadoc search broken after output files organization for modules
bpatel
parents:
47216
diff
changeset
|
337 |
url += ui.item.c + ".html" + "#"; |
33920 | 338 |
} else { |
48991
978c3036fbfc
8198522: Javadoc search broken after output files organization for modules
bpatel
parents:
47216
diff
changeset
|
339 |
url += ui.item.p.replace(/\./g, '/') + "/" + ui.item.c + ".html" + "#"; |
33920 | 340 |
} |
341 |
if (ui.item.url) { |
|
342 |
url += ui.item.url; |
|
343 |
} else { |
|
49427
d2fd2581325b
8199278: Javadoc search results does not link to anchors on a page
bpatel
parents:
48991
diff
changeset
|
344 |
url += ui.item.l; |
33920 | 345 |
} |
346 |
} else if (ui.item.category === catSearchTags) { |
|
347 |
url += ui.item.u; |
|
348 |
} |
|
349 |
if (top !== window) { |
|
350 |
parent.classFrame.location = pathtoroot + url; |
|
351 |
} else { |
|
352 |
window.location.href = pathtoroot + url; |
|
353 |
} |
|
51740
f79cfb07f13f
8209914: javadoc search sometimes generates bad URIs
hannesw
parents:
51607
diff
changeset
|
354 |
$("#search").focus(); |
33920 | 355 |
} |
356 |
} |
|
357 |
}); |
|
43762
515fe48569fe
8168965: search items are not listed in any sensible order
bpatel
parents:
41523
diff
changeset
|
358 |
}); |