summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorRobin Appelman <icewind@owncloud.com>2012-04-14 11:29:44 +0200
committerRobin Appelman <icewind@owncloud.com>2012-04-14 11:29:54 +0200
commit3babb8c22cf5d08ad4c4d79efee26fd1fb9a8472 (patch)
treea1e466f4875a4766124427f91a5db35c57e0fffd /lib
parent8ed4606685f93f5fea002aecaf5279f482e78115 (diff)
downloadnextcloud-server-3babb8c22cf5d08ad4c4d79efee26fd1fb9a8472.tar.gz
nextcloud-server-3babb8c22cf5d08ad4c4d79efee26fd1fb9a8472.zip
improve flexibility of search providers a bit
Diffstat (limited to 'lib')
-rw-r--r--lib/search.php30
-rw-r--r--lib/search/provider.php6
-rw-r--r--lib/search/provider/file.php4
3 files changed, 33 insertions, 7 deletions
diff --git a/lib/search.php b/lib/search.php
index 6b33fa38140..12055418687 100644
--- a/lib/search.php
+++ b/lib/search.php
@@ -26,13 +26,22 @@
*/
class OC_Search{
static private $providers=array();
+ static private $registeredProviders=array();
+
+ /**
+ * remove all registered search providers
+ */
+ public static function clearProviders(){
+ self::$providers=array();
+ self::$registeredProviders=array();
+ }
/**
* register a new search provider to be used
* @param string $provider class name of a OC_Search_Provider
*/
- public static function registerProvider($provider){
- self::$providers[]=$provider;
+ public static function registerProvider($class,$options=array()){
+ self::$registeredProviders[]=array('class'=>$class,'options'=>$options);
}
/**
@@ -41,10 +50,25 @@ class OC_Search{
* @return array An array of OC_Search_Result's
*/
public static function search($query){
+ self::initProviders();
$results=array();
foreach(self::$providers as $provider){
- $results=array_merge($results, $provider::search($query));
+ $results=array_merge($results, $provider->search($query));
}
return $results;
}
+
+ /**
+ * create instances of all the registered search providers
+ */
+ private static function initProviders(){
+ if(count(self::$providers)>0){
+ return;
+ }
+ foreach(self::$registeredProviders as $provider){
+ $class=$provider['class'];
+ $options=$provider['options'];
+ self::$providers[]=new $class($options);
+ }
+ }
}
diff --git a/lib/search/provider.php b/lib/search/provider.php
index 9487ca51f2b..838ab696d04 100644
--- a/lib/search/provider.php
+++ b/lib/search/provider.php
@@ -2,11 +2,13 @@
/**
* provides search functionalty
*/
-interface OC_Search_Provider {
+class OC_Search_Provider {
+ public function __construct($options){}
+
/**
* search for $query
* @param string $query
* @return array An array of OC_Search_Result's
*/
- static function search($query);
+ public function search($query){}
}
diff --git a/lib/search/provider/file.php b/lib/search/provider/file.php
index 3bdb3bcd2af..a37af495599 100644
--- a/lib/search/provider/file.php
+++ b/lib/search/provider/file.php
@@ -1,7 +1,7 @@
<?php
-class OC_Search_Provider_File implements OC_Search_Provider{
- static function search($query){
+class OC_Search_Provider_File extends OC_Search_Provider{
+ function search($query){
$files=OC_FileCache::search($query,true);
$results=array();
foreach($files as $fileData){