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