Skip to content
This repository was archived by the owner on Oct 30, 2018. It is now read-only.

Commit ee9ffc4

Browse files
committed
add missing search.js
1 parent 98c0f1f commit ee9ffc4

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

js/search.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
(function() {
2+
OCA.Search.Lucene = {
3+
attach: function(search) {
4+
5+
search.setRenderer('lucene', OCA.Search.Lucene.renderFileResult);
6+
search.setHandler('lucene', OCA.Search.Lucene.handleFileClick);
7+
},
8+
renderFileResult: function($row, result) {
9+
var $fileResultRow = OCA.Search.files.renderFileResult($row, result);
10+
if (!$fileResultRow && result.name.toLowerCase().indexOf(OC.Search.getLastQuery()) === -1) {
11+
/*render preview icon, show path beneath filename,
12+
show size and last modified date on the right */
13+
14+
$pathDiv = $('<div class="path"></div>').text(result.path);
15+
$row.find('td.info div.name').after($pathDiv).text(result.name);
16+
17+
$row.find('td.result a').attr('href', result.link);
18+
19+
if (OCA.Search.files.fileAppLoaded()) {
20+
OCA.Files.App.fileList.lazyLoadPreview({
21+
path: result.path,
22+
mime: result.mime,
23+
callback: function (url) {
24+
$row.find('td.icon').css('background-image', 'url(' + url + ')');
25+
}
26+
});
27+
} else {
28+
// FIXME how to get mime icon if not in files app
29+
var mimeicon = result.mime.replace('/', '-');
30+
$row.find('td.icon').css('background-image', 'url(' + OC.imagePath('core', 'filetypes/' + mimeicon) + ')');
31+
var dir = OC.dirname(result.path);
32+
if (dir === '') {
33+
dir = '/';
34+
}
35+
$row.find('td.info a').attr('href',
36+
OC.generateUrl('/apps/files/?dir={dir}&scrollto={scrollto}', {dir: dir, scrollto: result.name})
37+
);
38+
}
39+
$fileResultRow = $row;
40+
}
41+
if ($fileResultRow && typeof result.highlights === 'object') {
42+
var highlights = result.highlights.join(' … ');
43+
var $highlightsDiv = $('<div class="highlights"></div>').html(highlights);
44+
$row.find('td.info div.path').after($highlightsDiv);
45+
}
46+
return $fileResultRow;
47+
},
48+
handleFileClick: function($row, result, event) {
49+
OCA.Search.files.handleFileClick($row, result, event);
50+
}
51+
};
52+
})();
53+
54+
OC.Plugins.register('OCA.Search', OCA.Search.Lucene);

0 commit comments

Comments
 (0)