rjack-solr 3.6.0.0-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. data/History.rdoc +2 -0
  2. data/Manifest.txt +62 -0
  3. data/NOTICE.txt +7 -0
  4. data/README.rdoc +71 -0
  5. data/Rakefile +12 -0
  6. data/assembly.xml +20 -0
  7. data/bin/rjack-solr-fg +53 -0
  8. data/config/config.rb +9 -0
  9. data/init/rjack-solr +44 -0
  10. data/lib/rjack-solr.rb +30 -0
  11. data/lib/rjack-solr/base.rb +28 -0
  12. data/lib/rjack-solr/commons-fileupload-1.2.1.jar +0 -0
  13. data/lib/rjack-solr/commons-io-2.1.jar +0 -0
  14. data/lib/rjack-solr/commons-lang-2.6.jar +0 -0
  15. data/lib/rjack-solr/config.rb +24 -0
  16. data/lib/rjack-solr/server.rb +70 -0
  17. data/lib/rjack-solr/solr-core-3.6.0.jar +0 -0
  18. data/lib/rjack-solr/solr-solrj-3.6.0.jar +0 -0
  19. data/pom.xml +96 -0
  20. data/test/test_solr.rb +43 -0
  21. data/webapp/META-INF/LICENSE.txt +1166 -0
  22. data/webapp/META-INF/MANIFEST.MF +13 -0
  23. data/webapp/META-INF/NOTICE.txt +438 -0
  24. data/webapp/WEB-INF/web.xml +153 -0
  25. data/webapp/WEB-INF/weblogic.xml +12 -0
  26. data/webapp/admin/_info.jsp +120 -0
  27. data/webapp/admin/action.jsp +94 -0
  28. data/webapp/admin/analysis.jsp +496 -0
  29. data/webapp/admin/analysis.xsl +179 -0
  30. data/webapp/admin/dataimport.jsp +53 -0
  31. data/webapp/admin/debug.jsp +103 -0
  32. data/webapp/admin/distributiondump.jsp +160 -0
  33. data/webapp/admin/favicon.ico +0 -0
  34. data/webapp/admin/form.jsp +152 -0
  35. data/webapp/admin/get-file.jsp +72 -0
  36. data/webapp/admin/get-properties.jsp +24 -0
  37. data/webapp/admin/header.jsp +44 -0
  38. data/webapp/admin/index.jsp +162 -0
  39. data/webapp/admin/jquery-1.4.3.min.js +166 -0
  40. data/webapp/admin/meta.xsl +34 -0
  41. data/webapp/admin/ping.jsp +52 -0
  42. data/webapp/admin/ping.xsl +71 -0
  43. data/webapp/admin/raw-schema.jsp +38 -0
  44. data/webapp/admin/registry.jsp +107 -0
  45. data/webapp/admin/registry.xsl +321 -0
  46. data/webapp/admin/replication/header.jsp +89 -0
  47. data/webapp/admin/replication/index.jsp +378 -0
  48. data/webapp/admin/schema.jsp +690 -0
  49. data/webapp/admin/solr-admin.css +215 -0
  50. data/webapp/admin/solr_small.png +0 -0
  51. data/webapp/admin/stats.jsp +92 -0
  52. data/webapp/admin/stats.xsl +220 -0
  53. data/webapp/admin/tabular.xsl +141 -0
  54. data/webapp/admin/threaddump.jsp +110 -0
  55. data/webapp/admin/threaddump.xsl +103 -0
  56. data/webapp/favicon.ico +0 -0
  57. data/webapp/index.jsp +49 -0
  58. metadata +217 -0
@@ -0,0 +1,690 @@
1
+ <%@ page contentType="text/html; charset=utf-8" pageEncoding="UTF-8"%>
2
+ <%--
3
+ Licensed to the Apache Software Foundation (ASF) under one or more
4
+ contributor license agreements. See the NOTICE file distributed with
5
+ this work for additional information regarding copyright ownership.
6
+ The ASF licenses this file to You under the Apache License, Version 2.0
7
+ (the "License"); you may not use this file except in compliance with
8
+ the License. You may obtain a copy of the License at
9
+
10
+ http://www.apache.org/licenses/LICENSE-2.0
11
+
12
+ Unless required by applicable law or agreed to in writing, software
13
+ distributed under the License is distributed on an "AS IS" BASIS,
14
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ See the License for the specific language governing permissions and
16
+ limitations under the License.
17
+ --%>
18
+
19
+ <%-- $Id: index.jsp 608150 2008-01-02 17:15:30Z ryan $ --%>
20
+ <%-- $Source: /cvs/main/searching/SolrServer/resources/admin/index.jsp,v $ --%>
21
+ <%-- $Name: $ --%>
22
+
23
+ <script src="jquery-1.4.3.min.js"></script>
24
+ <script>
25
+
26
+ (function($, libName) {
27
+ var solr = {
28
+
29
+ //The default location of the luke handler relative to this page
30
+ // Can be overridden in the init(url) method
31
+ pathToLukeHandler: 'luke',
32
+
33
+ // Base properties to hold schema information
34
+ schemaInfo: {},
35
+ schemaFields: {},
36
+ schemaDynamicFields: {},
37
+ schemaTypes: {},
38
+ schemaFlags: {},
39
+
40
+ //The basic function to call to make the initail JSON calls
41
+ // takes one option parameter, the path to the luke handler
42
+ // if undefined, it will use the default, 'luke', which means
43
+ // this is being called from the same relative URL path
44
+ init: function(pathToLukeHandler) {
45
+ if (pathToLukeHandler != undefined) {
46
+ solr.pathToLukeHandler = pathToLukeHandler;
47
+ }
48
+ solr.loadSchema(function() {
49
+ solr.loadFromLukeHandler(function () {
50
+ solr.createMenu('menu');
51
+ solr.displaySchemaInfo();
52
+ });
53
+ });
54
+
55
+ },
56
+ // get the reportDocCount parameter, could ask for others
57
+ getParamDefault: function(paramName, defaultVal) {
58
+ var searchString = window.location.search.substring(1),
59
+ i, val, params = searchString.split("&");
60
+
61
+ for (i=0;i<params.length;i++) {
62
+ val = params[i].split("=");
63
+ if (val[0] == paramName) {
64
+ return unescape(val[1]);
65
+ }
66
+ }
67
+ return defaultVal;
68
+ },
69
+
70
+ //load the Schema from the LukeRequestHandler
71
+ // this loads every field, and in each field the copy source/dests and flags
72
+ // we also load the list of field types, and the list of flags
73
+ loadSchema: function(func) {
74
+ $.getJSON(solr.pathToLukeHandler +'?show=schema&wt=json', function(data) {
75
+ //populate all non field/type/flag data in the info block
76
+ $.each(data.index, function(i, item) {
77
+ solr.schemaInfo[i] = item;
78
+ });
79
+
80
+ //LukeRequestHandler places these two attributes outside of the "index" node, but
81
+ // we want it here so we can more easily display it in the "HOME" block
82
+ solr.schemaInfo['uniqueKeyField'] = data.schema.uniqueKeyField;
83
+ solr.schemaInfo['defaultSearchField'] = data.schema.defaultSearchField;
84
+ //a one-off hack, because the directory string is so long and unbroken
85
+ // that it can break CSS layouts
86
+ solr.schemaInfo['directory'] = solr.schemaInfo['directory'].substring(0, solr.schemaInfo['directory'].indexOf('@')+1) + ' ' + solr.schemaInfo['directory'].substring(solr.schemaInfo['directory'].indexOf('@') +1);
87
+
88
+ // populate the list of fields
89
+ $.each(data.schema.fields, function(i,item){
90
+ solr.schemaFields[i]=item;
91
+ });
92
+ // populate the list of field types
93
+ $.each(data.schema.types, function(type, ft) {
94
+ solr.schemaTypes[type] = ft;
95
+ });
96
+ //populate the list of dynamic fields
97
+ $.each(data.schema.dynamicFields, function(i, dynField) {
98
+ solr.schemaDynamicFields[i] = dynField;
99
+ });
100
+ //populate the list of flags, so we can convert flags to text in display
101
+ $.each(data.info.key, function(i, flag) {
102
+ solr.schemaFlags[i] = flag;
103
+ });
104
+
105
+ //LukeRequestHandler returns copyFields src/dest as the entire toString of the field
106
+ // we only need the field name, so here we loop through the fields, and replace the full
107
+ // field definitions with the name in the copySources/copyDests properties
108
+ $.each(solr.schemaFields, function(i, field) {
109
+ $.each(['copySources', 'copyDests'], function(i, copyProp) {
110
+ var newFields = new Array();
111
+ $.each(field[copyProp], function(i, fullName) {
112
+ newFields.push(fullName.substring(fullName.lastIndexOf(':')+1, fullName.indexOf('{')));
113
+ });
114
+ field[copyProp] = newFields;
115
+ });
116
+
117
+ });
118
+ //An additional optional callback
119
+ // used in init to trigger the 2nd call to LukeRequestHandler only
120
+ // after the first one is finished
121
+ if ($.isFunction(func)) {
122
+ func(solr);
123
+ }
124
+ });
125
+ },
126
+
127
+ //further populates the loaded schema with information gathered
128
+ // from the no argument LukeRequestHandler
129
+ loadFromLukeHandler: function(func) {
130
+
131
+ $.getJSON(solr.pathToLukeHandler+'?wt=json' + '&reportDocCount=' + solr.getParamDefault('reportDocCount', 'false'), function(data) {
132
+ $.each(data.fields, function(i, item) {
133
+ var field = solr.schemaFields[i];
134
+
135
+ //If undefined, then we have a dynamicField which does not show up
136
+ // in the LukeRequestHandler show=schema variant
137
+ if (field == undefined) {
138
+ field = item;
139
+ //Attach this field to its dynamicField
140
+ var base = field.dynamicBase;
141
+ var dynField = solr.schemaDynamicFields[base];
142
+
143
+ //Some fields in a multicore setting have no dynamic base, either
144
+ // the name of the core is a field that has no type or flags
145
+ if (dynField != undefined) {
146
+ var synFields = dynField['fields'];
147
+ if (synFields== undefined) {
148
+ synFields= new Array();
149
+ }
150
+ synFields.push(i);
151
+ dynField['fields'] = synFields;
152
+ }
153
+ solr.schemaFields[i] = item;
154
+ }
155
+ //Populate other data in this field that would not have been loaded in
156
+ // the show=schema variant
157
+ $.each(item, function(k, v) {
158
+ if (k == 'topTerms' || k == 'histogram') {
159
+ solr.schemaFields[i][k] = solr.lukeArrayToHash(v);
160
+ } else {
161
+ solr.schemaFields[i][k] = v;
162
+ }
163
+ });
164
+ });
165
+ //another optional callback; used in the init case to lay out the page
166
+ // after the data is loaded
167
+ if ($.isFunction(func)) {
168
+ func();
169
+ }
170
+ });
171
+ },
172
+ //some elements in the JSON response are arrays, where odd/even elements
173
+ // are the name/value, and convert it to a standard map/associative array
174
+ // incoming: ['foo', 'bar', 'bat', 'baz']
175
+ // output: {'foo':'bar', 'bat':baz'}
176
+ lukeArrayToHash: function(termsArr) {
177
+ var hash = new Object();
178
+ var temp;
179
+ //topTerms comes in as an array, with odd indexes the field name
180
+ // and even indexes the number
181
+ $.each(termsArr, function(i, item) {
182
+ if (i%2 ==0) {
183
+ temp = item;
184
+ } else {
185
+ hash[temp] = item;
186
+ }
187
+ });
188
+ return hash;
189
+ },
190
+
191
+ //gets the top Terms via an Ajax call the LukeRequestHandler for that field
192
+ // The callback is used here to redraw the table after the ajax call returns
193
+ getTopTerms: function(fieldName, numTerms, func) {
194
+ if (numTerms == undefined) {
195
+ var numTerms = 10;
196
+ }
197
+ if (isNaN(numTerms) || numTerms <=0 || numTerms.indexOf('.') != -1) {
198
+ return;
199
+ }
200
+
201
+ $.getJSON(solr.pathToLukeHandler+'?fl='+fieldName+'&wt=json&numTerms='+numTerms+'&reportDocCount=' + solr.getParamDefault('reportDocCount', 'false'), function(data) {
202
+ solr.schemaFields[fieldName]['topTerms'] = solr.lukeArrayToHash(data.fields[fieldName].topTerms);
203
+ if ($.isFunction(func)) {
204
+ func(solr.schemaFields[fieldName]['topTerms'], fieldName);
205
+ }
206
+ });
207
+ },
208
+
209
+ // Displays the SchemaInfo in the main content panel
210
+ // dispayed on data load, and also when 'Home' is clicked
211
+ displaySchemaInfo: function() {
212
+ $('#mainInfo').html('');
213
+ $('#topTerms').html('');
214
+ $('#histogram').html('');
215
+ $('#mainInfo').append(solr.createSimpleText('Schema Information'));
216
+ //Make sure the uniqueKeyField and defaultSearchFields come first
217
+ $.each({'Unique Key':'uniqueKeyField', 'Default Search Field':'defaultSearchField'}, function(text, prop) {
218
+ if (solr.schemaInfo[prop] != undefined) {
219
+ $('#mainInfo').append(solr.createNameValueText(text, function(p) {
220
+ p.appendChild(solr.createLink(solr.schemaInfo[prop], solr.schemaInfo[prop]));
221
+ return p;
222
+ }));
223
+ }
224
+ });
225
+ $.each(solr.schemaInfo, function(i, item) {
226
+ if (i == 'uniqueKeyField' || i == 'defaultSearchField') {
227
+ //noop; we took care of this above
228
+ } else {
229
+ $('#mainInfo').append(solr.createNameValueText(i, item));
230
+ }
231
+ });
232
+ //Close all menus when we display schema home
233
+ solr.toggleMenus(undefined, ['fields', 'types', 'dynFields']);
234
+ },
235
+
236
+ // display a dynamic field in the main content panel
237
+ displayDynamicField: function(dynamicPattern) {
238
+ var df = solr.schemaDynamicFields[dynamicPattern];
239
+ $('#mainInfo').html('');
240
+ $('#topTerms').html('');
241
+ $('#histogram').html('');
242
+ $('#mainInfo').append(solr.createSimpleText('Dynamic Field: ' + dynamicPattern));
243
+ $('#mainInfo').append(solr.createNameValueText('Fields', function(p) {
244
+ if (df.fields != undefined) {
245
+ $.each(df.fields, function(i, item) {
246
+ p.appendChild(solr.createLink(item, item));
247
+ });
248
+ } else {
249
+ p.appendChild(document.createTextNode(' None currently in index'));
250
+ }
251
+ return p;
252
+ }));
253
+ var ft = solr.schemaTypes[df.type];
254
+ $('#mainInfo').append(solr.createNameValueText('Field Type', function(p) {
255
+ p.appendChild(solr.createLink(df.type, df.type, solr.displayFieldType));
256
+ return p;
257
+ }));
258
+ if (df.flags != undefined) {
259
+ $('#mainInfo').append(solr.createNameValueText('Properties', solr.createTextFromFlags(df.flags, df.type)));
260
+ }
261
+ solr.displayAnalyzer(ft.indexAnalyzer, 'Index Analyzer', true);
262
+ solr.displayAnalyzer(ft.queryAnalyzer, 'Query Analyzer', true);
263
+
264
+ solr.toggleMenus('dynFields', ['fields', 'types'], dynamicPattern);
265
+ },
266
+
267
+ // display a field type in the main area
268
+ displayFieldType: function(typeName) {
269
+ var ft = solr.schemaTypes[typeName];
270
+ $('#mainInfo').html('');
271
+ $('#topTerms').html('');
272
+ $('#histogram').html('');
273
+ $('#mainInfo').append(solr.createSimpleText('Field Type: ' + typeName));
274
+ $('#mainInfo').append(solr.createNameValueText('Fields', function(p) {
275
+ if (ft.fields != undefined) {
276
+ $.each(ft.fields, function(i, item) {
277
+ if (solr.schemaFields[item] != undefined) {
278
+ p.appendChild(solr.createLink(item, item));
279
+ } else {
280
+ p.appendChild(solr.createLink(item, item, solr.displayDynamicField));
281
+ }
282
+ p.appendChild(document.createTextNode(' '));
283
+ });
284
+ } else {
285
+ p.appendChild(document.createTextNode('No fields in index'));
286
+ }
287
+ return p;
288
+ }));
289
+ $('#mainInfo').append(solr.createNameValueText('Tokenized', ft.tokenized));
290
+ $('#mainInfo').append(solr.createNameValueText('Class Name', ft.className));
291
+
292
+ solr.displayAnalyzer(ft.indexAnalyzer, 'Index Analyzer');
293
+ solr.displayAnalyzer(ft.queryAnalyzer, 'Query Analyzer');
294
+ solr.toggleMenus('types', ['fields', 'dynFields'], typeName);
295
+ },
296
+
297
+ //Displays information about an Analyzer in the main content area
298
+ displayAnalyzer: function(analyzer, type, shouldCollapse) {
299
+ var tid = type.replace(' ', '');
300
+ var collapse = shouldCollapse && (analyzer.charFilters != undefined || analyzer.tokenizer != undefined || analyzer.filters != undefined);
301
+ $('#mainInfo').append(solr.createNameValueText(type, function(p) {
302
+ p.appendChild(document.createTextNode(analyzer.className + ' '));
303
+ if (collapse) {
304
+ p.appendChild(solr.createLink(type, 'Details', function() {
305
+ $('#'+tid).toggle("slow");
306
+ }));
307
+ }
308
+ return p;
309
+ }));
310
+ var adiv = document.createElement('div');
311
+ adiv.id=tid;
312
+ adiv.className='analyzer';
313
+ if (collapse) {
314
+ adiv.style.display='none';
315
+ }
316
+ if (analyzer.charFilters != undefined) {
317
+ adiv.appendChild(solr.createNameValueText('Char Filters', ''));
318
+ var f = document.createElement('ol');
319
+ $.each(analyzer.charFilters, function(i, item) {
320
+ var fil = document.createElement('li');
321
+ var filterText = item.className;
322
+ if (item.args != undefined) {
323
+ filterText += ' args:{'
324
+ $.each(item.args, function(fi, fitem) {
325
+ filterText += fi + ': ' + fitem + ' ';
326
+ });
327
+ filterText +='}';
328
+ fil.innerHTML = filterText;
329
+ f.appendChild(fil);
330
+ }
331
+ });
332
+ adiv.appendChild(f);
333
+ }
334
+ if (analyzer.tokenizer != undefined) {
335
+ adiv.appendChild(solr.createNameValueText("Tokenizer Class", analyzer.tokenizer.className));
336
+ }
337
+ if (analyzer.filters != undefined) {
338
+ adiv.appendChild(solr.createNameValueText('Filters', ''));
339
+ var f = document.createElement('ol');
340
+ $.each(analyzer.filters, function(i, item) {
341
+ var fil = document.createElement('li');
342
+ var filterText = item.className;
343
+ if (item.args != undefined) {
344
+ filterText += ' args:{'
345
+ $.each(item.args, function(fi, fitem) {
346
+ filterText += fi + ': ' + fitem + ' ';
347
+ });
348
+ filterText +='}';
349
+ fil.innerHTML = filterText;
350
+ f.appendChild(fil);
351
+ }
352
+ });
353
+ adiv.appendChild(f);
354
+ }
355
+ $('#mainInfo').append(adiv);
356
+ },
357
+
358
+ // display information about a Field in the main content area
359
+ // and its TopTerms and Histogram in related divs
360
+ displayField: function(fieldName) {
361
+ var field = solr.schemaFields[fieldName];
362
+ var isDynamic = field.dynamicBase != undefined ? true : false;
363
+ var ft;
364
+ var ftName;
365
+ $('#mainInfo').html('');
366
+ $('#topTerms').html('');
367
+ $('#histogram').html('');
368
+ $('#mainInfo').append(solr.createSimpleText('Field: ' + fieldName));
369
+
370
+ //For regular fields, we take their properties; for dynamicFields,
371
+ // we take them from their dynamicField definitions
372
+ if (isDynamic) {
373
+ ftName = solr.schemaDynamicFields[field.dynamicBase].type
374
+ $('#mainInfo').append(solr.createNameValueText('Dynamically Created From Pattern', function(p) {
375
+ p.appendChild(solr.createLink(field.dynamicBase, field.dynamicBase, solr.displayDynamicField));
376
+ return p;
377
+ }));
378
+ } else {
379
+ ftName = field.type;
380
+ }
381
+ ft = solr.schemaTypes[field.type];
382
+ $('#mainInfo').append(solr.createNameValueText('Field Type', function(p) {
383
+ p.appendChild(solr.createLink(ftName, ftName, solr.displayFieldType));
384
+ return p;
385
+ }));
386
+ if (solr.schemaFlags != '') {
387
+ $.each({'flags':'Properties', 'schema':'Schema', 'index':'Index'}, function(prop, text) {
388
+ if (field[prop] != undefined) {
389
+ $('#mainInfo').append(solr.createNameValueText(text, solr.createTextFromFlags(field[prop], ft)));
390
+ }
391
+ });
392
+ }
393
+ $.each({'copySources':'Copied From', 'copyDests':'Copied Into'}, function(prop, text) {
394
+ if (field[prop] != undefined && field[prop] != '') {
395
+ $('#mainInfo').append(solr.createNameValueText(text, function(p) {
396
+ $.each(field[prop], function(i, item) {
397
+ p.appendChild(solr.createLink(item, item));
398
+ p.appendChild(document.createTextNode(' '));
399
+ });
400
+ return p;
401
+ }));
402
+ }
403
+ });
404
+ if (field.positionIncrementGap != undefined) {
405
+ $('#mainInfo').append(solr.createNameValueText('Position Increment Gap', field.positionIncrementGap));
406
+ }
407
+ solr.displayAnalyzer(ft.indexAnalyzer, 'Index Analyzer', true);
408
+ solr.displayAnalyzer(ft.queryAnalyzer, 'Query Analyzer', true);
409
+ if (field.docs != undefined) {
410
+ $('#mainInfo').append(solr.createNameValueText('Docs', field.docs));
411
+ }
412
+ if (field.distinct != undefined) {
413
+ $('#mainInfo').append(solr.createNameValueText('Distinct', field.distinct));
414
+ }
415
+
416
+ if (field.topTerms != undefined) {
417
+ solr.displayTopTerms(field.topTerms, fieldName);
418
+ }
419
+
420
+ if (field.histogram != undefined) {
421
+ solr.drawHistogram(field.histogram);
422
+ }
423
+ solr.toggleMenus('fields', ['types', 'dynFields'], fieldName);
424
+ },
425
+
426
+ //utility method to create a single sentence list of properties from a flag set
427
+ // or pass it on, if the flags are (unstored field)
428
+ createTextFromFlags: function(fieldFlags, fieldType) {
429
+ var value;
430
+ if (fieldFlags != '(unstored field)') {
431
+ var value = '';
432
+ for (var i=0;i<fieldFlags.length;i++) {
433
+ if (fieldFlags.charAt(i) != '-') {
434
+ value += solr.schemaFlags[fieldFlags.charAt(i)];
435
+ value += ', ';
436
+ }
437
+ }
438
+ value = value.substring(0, value.length-2);
439
+ } else {
440
+ value = fieldFlags;
441
+ }
442
+ return value;
443
+ },
444
+
445
+ //Store the currently highlighted menu item, as otherwise we
446
+ // must traverse all li menu items, which is very slow on schemas with
447
+ // large number of fields
448
+ // for example $('#menu ul li').siblings().removeClass('selected');
449
+ currentlyHighlightedMenuId: undefined,
450
+
451
+ //add a highlight to the currently selected menu item, and remove
452
+ // the highlights from all other menu items
453
+ highlightMenuItem: function(idToSelect) {
454
+ if (solr.currentlyHighlightedMenuId != undefined) {
455
+ $('#'+solr.currentlyHighlightedMenuId).removeClass('selected');
456
+ }
457
+ $('#'+idToSelect).addClass('selected');
458
+ solr.currentlyHighlightedMenuId = idToSelect;
459
+ },
460
+
461
+ //Opens one menu group, close the others, and optionally highlight one
462
+ // item, which should be in the opened menu
463
+ toggleMenus: function(idToShow, idsToHide, idToSelect) {
464
+ if (idToSelect != undefined) {
465
+ solr.highlightMenuItem(idToShow + idToSelect);
466
+ }
467
+ $('#'+idToShow).show("slow");
468
+ $.each(idsToHide, function(i, idToHide) {
469
+ $('#'+idToHide).hide("slow");
470
+ });
471
+ },
472
+
473
+ //A utility method to create a paragraph, which takes two arguments;
474
+ // an opening text, and either text or a callback function to follow
475
+ // any callback function must return the node passed into it
476
+ createNameValueText: function(openingText, func) {
477
+ var p = document.createElement('p');
478
+ p.appendChild(solr.createSimpleText(openingText + ': ', 'b'));
479
+ return solr.applyFuncToNode(p, func);
480
+ },
481
+
482
+ //utility method to create an HTML text element node
483
+ // with the literal text to place, and an optional function to apply
484
+ // any callback function must return the node passed into it
485
+ createSimpleText: function(text, n, func) {
486
+ if (n == undefined) {
487
+ n = 'h2';
488
+ }
489
+ var no= document.createElement(n);
490
+ no.appendChild(document.createTextNode(text));
491
+ return solr.applyFuncToNode(no, func);
492
+ },
493
+
494
+ //Utility method that applies a function or a string to append
495
+ // an additional child to a node
496
+ applyFuncToNode: function(no, func) {
497
+ if ($.isFunction(func)) {
498
+ no = func(no);
499
+ } else {
500
+ // if it is not a function, append it as a string
501
+ if (func != undefined) {
502
+ no.appendChild(document.createTextNode(' ' + func));
503
+ }
504
+ }
505
+ return no;
506
+ },
507
+
508
+ //show a table of top terms for a given field
509
+ displayTopTerms: function(topTerms, fieldName) {
510
+ $('#topTerms').html('');
511
+ var tbl = document.createElement('table');
512
+ tbl.className='topTerms';
513
+ var thead= document.createElement('thead');
514
+ var headerRow = document.createElement('tr');
515
+ $.each(['term', 'frequency'], function() {
516
+ var cell = document.createElement('th');
517
+ cell.innerHTML= this;
518
+ headerRow.appendChild(cell);
519
+ });
520
+ thead.appendChild(headerRow);
521
+ tbl.appendChild(thead);
522
+ var tbody = document.createElement('tbody');
523
+
524
+ var numTerms = 0;
525
+ $.each(topTerms, function(term, count) {
526
+ var c1 = $('<td>').text(term);
527
+ var c2 = $('<td>').text(count);
528
+ var row = $('<tr>').append(c1).append(c2);
529
+ tbody.appendChild(row.get(0));
530
+ numTerms++;
531
+ });
532
+ tbl.appendChild(tbody);
533
+
534
+ //create a header along with an input widget so the user
535
+ // can request a different number of Top Terms
536
+ var h2 = document.createElement('h2');
537
+ h2.appendChild(document.createTextNode('Top '));
538
+ var termsGetter = document.createElement('input');
539
+ termsGetter.type='text';
540
+ termsGetter.size=5;
541
+ termsGetter.value=numTerms;
542
+
543
+ termsGetter.onchange=function() {
544
+ solr.getTopTerms(fieldName, this.value, solr.displayTopTerms);
545
+ }
546
+ h2.appendChild(termsGetter);
547
+ h2.appendChild(document.createTextNode(' Terms'));
548
+ $('#topTerms').append(h2);
549
+
550
+ document.getElementById('topTerms').appendChild(tbl);
551
+ $('#topTerms').append(tbl);
552
+ },
553
+
554
+ //draws a histogram, taking a map of values and an optional total height and width for the table
555
+ drawHistogram: function(histogram, totalHeightArg, totalWidthArg) {
556
+ $('#histogram').html('');
557
+ $('#histogram').append(solr.createSimpleText('Histogram'));
558
+ var max = 0;
559
+ var bars =0;
560
+ //find the # of columns and max value in the histogram
561
+ // so we can create an appropriately scaled chart
562
+ $.each(histogram, function(i, item) {
563
+ if (item > max) max = item;
564
+ bars += 1;
565
+ });
566
+ if (max ==0) {
567
+ $('#histogram').append(solr.createNameValueText('No histogram available'));
568
+ } else {
569
+ var totalHeight = totalHeightArg == undefined ? 208 : totalHeightArg;
570
+ var totalWidth = totalWidthArg == undefined ? 160 : totalWidthArg;
571
+ var tbl = document.createElement('table');
572
+ tbl.style.width=totalWidth+'px';
573
+ tbl.className = 'histogram';
574
+ var h = document.createElement('tbody');
575
+ var r = document.createElement('tr');
576
+ var r2 = document.createElement('tr');
577
+ $.each(histogram, function(i, item) {
578
+ var c = document.createElement('td');
579
+ c.innerHTML=item+'<div style="width:'+totalWidth/bars+'px;height:'+(item*totalHeight/max)+'px;background:blue">&nbsp</div>';
580
+ r.appendChild(c);
581
+ var c2 = document.createElement('td');
582
+ c2.innerHTML='' + i;
583
+ r2.appendChild(c2);
584
+ });
585
+ h.appendChild(r);
586
+ h.appendChild(r2);
587
+ tbl.appendChild(h);
588
+ $('#histogram').append(tbl);
589
+ }
590
+ },
591
+
592
+ //dynamically creates a link to be appended
593
+ createLink: function(idToDisplay, linkText, linkFunction) {
594
+ var link = document.createElement('a');
595
+ if (!$.isFunction(linkFunction)) {
596
+ linkFunction = solr.displayField
597
+ }
598
+ link.onclick=function() {
599
+ linkFunction(idToDisplay);
600
+ return false;
601
+ };
602
+ link.href='#';
603
+ link.innerHTML=linkText;
604
+ return link;
605
+ },
606
+
607
+ //Creates a menu header that can expand or collapse its children
608
+ createMenuHeader: function(text, idToShow, idsToHide) {
609
+ var head = document.createElement('h3');
610
+ var a = document.createElement('a');
611
+ a.onclick=function() {
612
+ solr.toggleMenus(idToShow, idsToHide);
613
+ return false;
614
+ };
615
+ a.href='#';
616
+ a.innerHTML=text;
617
+ head.appendChild(a);
618
+ return head;
619
+ },
620
+
621
+ //Creates an element in a menu (e.g. each field in a list of fields)
622
+ createMenuItem: function(tagName, text, link, type, func) {
623
+ var fieldEle = document.createElement('li');
624
+ fieldEle.id=type+text;
625
+ var funct = func == undefined ? undefined : func;
626
+ fieldEle.appendChild(solr.createLink(text, link, funct));
627
+ return fieldEle;
628
+ },
629
+
630
+ //populates the menu div
631
+ createMenu: function(menuId) {
632
+ var m = $('#'+menuId);
633
+ var home = document.createElement('h2');
634
+ home.appendChild(solr.createLink('Home', 'Home', solr.displaySchemaInfo));
635
+ m.append(home);
636
+ m.append(solr.createMenuHeader('Fields', 'fields', ['types', 'dynFields']));
637
+ var fields= document.createElement('ul');
638
+ fields.style.display='none';
639
+ fields.id = 'fields';
640
+ $.each(solr.schemaFields, function(i, item) {
641
+ fields.appendChild(solr.createMenuItem('li', i, i, fields.id));
642
+ });
643
+ m.append(fields);
644
+ m.append(solr.createMenuHeader('Dynamic Fields', 'dynFields', ['fields', 'types']));
645
+ var dyns = document.createElement('ul');
646
+ dyns.style.display = 'none';
647
+ dyns.id = 'dynFields';
648
+ $.each(solr.schemaDynamicFields, function(i, item) {
649
+ dyns.appendChild(solr.createMenuItem('li', i,i, dyns.id, solr.displayDynamicField));
650
+ });
651
+ m.append(dyns);
652
+ m.append(solr.createMenuHeader('Field Types', 'types', ['fields', 'dynFields']));
653
+ var types = document.createElement('ul');
654
+ types.style.display='none';
655
+ types.id='types';
656
+ $.each(this.schemaTypes, function(i, item) {
657
+ types.appendChild(solr.createMenuItem('li', i, i,types.id, solr.displayFieldType));
658
+ });
659
+ m.append(types);
660
+ }
661
+ };
662
+
663
+ window[libName] = solr;
664
+ })(jQuery, 'solr');
665
+ $(document).ready(function() {
666
+ solr.init();
667
+ });
668
+
669
+ $(window).unload( function() {
670
+ solr = null;
671
+ $('#mainInfo').html('');
672
+ $('#menu').html('');
673
+ $('#topTerms').html('');
674
+ $('#histogram').html('');
675
+ });
676
+
677
+ </script>
678
+ <%-- do a verbatim include so we can use the local vars --%>
679
+ <%@include file="header.jsp" %>
680
+ <div id="schemaTop">
681
+ <h2>Schema Browser | See <a href="file/?file=schema.xml">Raw Schema.xml</a></h2>
682
+ </div>
683
+ <div id="menu"></div>
684
+ <div id="content">
685
+ <div id="mainInfo"><h2>Please wait...loading and parsing Schema Information from LukeRequestHandler</h2><p>If it does not load or your browser is not javascript or ajax-capable, you may wish to examine your schema using the <a href="luke?wt=xslt&tr=luke.xsl">Server side transformed LukeRequestHandler</a> or the raw <a href="file/?file=schema.xml">schema.xml</a> instead.</div>
686
+ <div id="topTerms"></div>
687
+ <div id="histogram"></div>
688
+ </div>
689
+ </body>
690
+ </html>