21
21
22
22
defined ('AJXP_EXEC ' ) or die ( 'Access not allowed ' );
23
23
24
-
25
- /**
26
- * Autoload function for Elastica classes
27
- * @param $class
28
- */
29
- function __autoload_elastica ($ class )
30
- {
31
- $ path = AJXP_INSTALL_PATH ."/plugins/index.elasticsearch/ " ;
32
- $ class = str_replace ('\\' , '/ ' , $ class );
33
-
34
- if (file_exists ($ path . $ class . '.php ' )) {
35
- require_once ($ path . $ class . '.php ' );
36
- }
37
- }
38
-
39
- spl_autoload_register ('__autoload_elastica ' );
40
-
24
+ require_once (dirname (__FILE__ )."/vendor/autoload.php " );
41
25
42
26
/**
43
27
* Encapsultion of the Elastica component as a plugin
@@ -55,7 +39,7 @@ class AjxpElasticSearch extends AbstractSearchEngineIndexer
55
39
private $ nextId ;
56
40
private $ lastIdPath ;
57
41
58
- private $ metaFields = array () ;
42
+ private $ metaFields = [] ;
59
43
private $ indexContent = false ;
60
44
private $ specificId = "" ;
61
45
private $ verboseIndexation = false ;
@@ -90,9 +74,9 @@ public function initMeta($accessDriver)
90
74
$ el = $ this ->getXPath ()->query ("/indexer " )->item (0 );
91
75
if ($ this ->indexContent ) {
92
76
if ($ this ->indexContent ) $ metaFields [] = "ajxp_document_content " ;
93
- $ data = array ( "indexed_meta_fields " => $ metaFields ,
94
- "additionnal_meta_columns " => array ( "ajxp_document_content " => "Content " )
95
- ) ;
77
+ $ data = [ "indexed_meta_fields " => $ metaFields ,
78
+ "additionnal_meta_columns " => [ "ajxp_document_content " => "Content " ]
79
+ ] ;
96
80
$ el ->setAttribute ("indexed_meta_fields " , json_encode ($ data ));
97
81
} else {
98
82
$ el ->setAttribute ("indexed_meta_fields " , json_encode ($ metaFields ));
@@ -154,15 +138,14 @@ public function applyAction($actionName, $httpVars, $fileVars)
154
138
}
155
139
}
156
140
157
-
158
141
$ this ->currentIndex ->open ();
159
142
$ fieldQuery = new Elastica \Query \QueryString ();
160
- $ fieldQuery ->setAllowLeadingWildcard (false );
143
+ $ fieldQuery ->setAllowLeadingWildcard (true );
161
144
$ fieldQuery ->setFuzzyMinSim (0.8 );
162
145
163
146
if ($ textQuery == "* " ){
164
147
165
- $ fields = array ( "ajxp_node " ) ;
148
+ $ fields = [ "ajxp_node " ] ;
166
149
$ fieldQuery ->setQuery ("yes " );
167
150
$ fieldQuery ->setFields ($ fields );
168
151
@@ -175,7 +158,7 @@ public function applyAction($actionName, $httpVars, $fileVars)
175
158
176
159
} else {
177
160
178
- $ fields = array ( "basename " ,"ajxp_meta_* " , "node_* " , " body ") ;
161
+ $ fields = [ "basename " ,"ajxp_meta_* " , "body " ] ;
179
162
$ fieldQuery ->setQuery ($ textQuery );
180
163
$ fieldQuery ->setFields ($ fields );
181
164
@@ -214,25 +197,21 @@ public function applyAction($actionName, $httpVars, $fileVars)
214
197
if (isSet ($ httpVars ['limit ' ])){
215
198
$ maxResults = intval ($ httpVars ['limit ' ]);
216
199
}
217
- $ searchOptions = array (
200
+ $ searchOptions = [
218
201
\Elastica \Search::OPTION_SEARCH_TYPE => \Elastica \Search::OPTION_SEARCH_TYPE_QUERY_THEN_FETCH ,
219
- \Elastica \Search::OPTION_SIZE => $ maxResults) ;
202
+ \Elastica \Search::OPTION_SIZE => $ maxResults] ;
220
203
221
204
$ this ->logDebug (__FUNCTION__ ,"Executing query: " , $ textQuery );
222
205
$ fullQuery = new Elastica \Query ();
223
206
$ fullQuery ->setQuery ($ fieldQuery );
224
207
225
208
$ qb = new Elastica \QueryBuilder ();
226
209
$ fullQuery = new Elastica \Query ();
210
+ $ filter = $ qb ->query ()->match ("ajxp_scope " , "shared " );
227
211
$ fullQuery ->setQuery (
228
- $ qb ->query ()->filtered (
229
- $ fieldQuery ,
230
- $ qb ->filter ()->bool ()
231
- ->addMust (new Elastica \Filter \Term (array ("ajxp_scope " => "shared " )))
232
- )
212
+ $ qb ->query ()->bool ()->addMust ($ fieldQuery )->addFilter ($ filter )
233
213
);
234
214
235
-
236
215
$ result = $ search ->search ($ fullQuery , $ searchOptions );
237
216
$ this ->logDebug (__FUNCTION__ ,"Search finished. " );
238
217
$ hits = $ result ->getResults ();
@@ -268,9 +247,12 @@ public function applyAction($actionName, $httpVars, $fileVars)
268
247
} catch (Exception $ ex ) {
269
248
throw new Exception ($ messages ["index.lucene.7 " ]);
270
249
}
250
+
251
+ /*
271
252
$sParts = array();
272
253
$searchField = $httpVars["field"];
273
254
255
+
274
256
if ($scope == "user") {
275
257
if (AuthService::usersEnabled() && AuthService::getLoggedUser() == null) {
276
258
throw new Exception("Cannot find current user");
@@ -281,8 +263,9 @@ public function applyAction($actionName, $httpVars, $fileVars)
281
263
$sParts[] = "ajxp_scope:shared";
282
264
}
283
265
$query = implode(" AND ", $sParts);
284
- $ this ->logDebug ("Query : $ query " );
266
+ $this->logDebug("Query : $query");*/
285
267
268
+ $ searchField = AJXP_Utils::sanitize ($ httpVars ["field " ], AJXP_SANITIZE_ALPHANUM );
286
269
287
270
$ fieldQuery = new Elastica \Query \QueryString ();
288
271
$ fields = array ($ searchField );
@@ -304,18 +287,17 @@ public function applyAction($actionName, $httpVars, $fileVars)
304
287
\Elastica \Search::OPTION_SEARCH_TYPE => \Elastica \Search::OPTION_SEARCH_TYPE_QUERY_THEN_FETCH ,
305
288
\Elastica \Search::OPTION_SIZE => $ maxResults );
306
289
307
- // ADD SCOPE FILTER
290
+ /* ADD SCOPE FILTER
308
291
$term = new Elastica\Filter\Term();
309
- $ term ->setTerm ("ajxp_scope " , "user " );
292
+ $term->setTerm("ajxp_scope", "user");*/
310
293
311
294
$ qb = new Elastica \QueryBuilder ();
312
295
$ fullQuery = new Elastica \Query ();
313
296
$ fullQuery ->setQuery (
314
- $ qb ->query ()->filtered (
315
- $ fieldQuery ,
316
- $ qb ->filter ()->bool ()
317
- ->addMust (new Elastica \Filter \Term (array ("ajxp_scope " => "user " )))
318
- ->addMust (new Elastica \Filter \Term (array ("user " => AuthService::getLoggedUser ()->getId ())))
297
+ $ qb ->query ()->bool ()
298
+ ->addMust ($ fieldQuery )
299
+ ->addMust ($ qb ->query ()->match ("ajxp_scope " , "user " ))
300
+ ->addMust ($ qb ->query ()->match ("user " , AuthService::getLoggedUser ()->getId ())
319
301
)
320
302
);
321
303
@@ -324,6 +306,8 @@ public function applyAction($actionName, $httpVars, $fileVars)
324
306
$ hits = $ result ->getResults ();
325
307
326
308
AJXP_XMLWriter::header ();
309
+
310
+ $ leafNodes = [];
327
311
foreach ($ hits as $ hit ) {
328
312
if ($ hit ->serialized_metadata !=null ) {
329
313
$ meta = unserialize (base64_decode ($ hit ->serialized_metadata ));
@@ -337,13 +321,26 @@ public function applyAction($actionName, $httpVars, $fileVars)
337
321
continue ;
338
322
}
339
323
$ tmpNode ->search_score = sprintf ("%0.2f " , $ hit ->score );
340
- AJXP_XMLWriter::renderAjxpNode ($ tmpNode );
324
+
325
+ if ($ tmpNode ->isLeaf ()){
326
+ $ leafNodes []= $ tmpNode ;
327
+ } else {
328
+ AJXP_XMLWriter::renderAjxpNode ($ tmpNode );
329
+ }
330
+
331
+ }
332
+ foreach ($ leafNodes as $ leaf ) {
333
+ AJXP_XMLWriter::renderAjxpNode ($ leaf );
341
334
}
335
+
342
336
AJXP_XMLWriter::close ();
343
337
}
344
338
345
339
}
346
340
341
+ /**
342
+ * @param $url
343
+ */
347
344
public function recursiveIndexation ($ url )
348
345
{
349
346
//print("Indexing $url \n");
@@ -501,7 +498,7 @@ public function createIndexedDocument($ajxpNode)
501
498
$ parseContent = false ;
502
499
}
503
500
504
- $ data = array () ;
501
+ $ data = [] ;
505
502
$ data ["node_url " ] = $ ajxpNode ->getUrl ();
506
503
$ data ["node_path " ] = str_replace ("/ " , "AJXPFAKESEP " , $ ajxpNode ->getPath ());
507
504
$ data ["basename " ] = basename ($ ajxpNode ->getPath ());
@@ -575,22 +572,27 @@ public function createIndexedDocument($ajxpNode)
575
572
576
573
}
577
574
575
+ /**
576
+ * Transform not data to ready to store mapping
577
+ * @param $data
578
+ * @return array
579
+ */
578
580
protected function dataToMappingProperties ($ data ){
579
581
580
- $ mapping_properties = array () ;
582
+ $ mapping_properties = [] ;
581
583
foreach ($ data as $ key => $ value ) {
582
584
if ($ key == "node_url " || $ key == "node_path " ) {
583
- $ mapping_properties [$ key ] = array ( "type " => "string " , "index " => "not_analyzed " ) ;
585
+ $ mapping_properties [$ key ] = [ "type " => "string " , "index " => "not_analyzed " ] ;
584
586
} else if ($ key == "serialized_metadata " ){
585
- $ mapping_properties [$ key ] = array ( "type " => "string " /*, "index" => "no" */ ) ;
587
+ $ mapping_properties [$ key ] = [ "type " => "string " /*, "index" => "no" */ ] ;
586
588
} else if ($ key == "ajxp_bytesize " ){
587
- $ mapping_properties [$ key ] = array ( "type " => "long " ) ;
589
+ $ mapping_properties [$ key ] = [ "type " => "long " ] ;
588
590
} else {
589
591
$ type = gettype ($ value );
590
592
if ($ type != "integer " && $ type != "boolean " && $ type != "double " ) {
591
593
$ type = "string " ;
592
594
}
593
- $ mapping_properties [$ key ] = array ( "type " => $ type) ;
595
+ $ mapping_properties [$ key ] = [ "type " => $ type] ;
594
596
}
595
597
}
596
598
return $ mapping_properties ;
0 commit comments