server/src/app/Repositories/RdfDocumentRepository.php
changeset 378 5b47eab083f3
parent 376 02f113d43f18
child 405 f239c8c5bb94
--- a/server/src/app/Repositories/RdfDocumentRepository.php	Thu Oct 20 17:27:36 2016 +0200
+++ b/server/src/app/Repositories/RdfDocumentRepository.php	Thu Oct 20 19:14:37 2016 +0200
@@ -141,67 +141,11 @@
             $sort = [$sort];
         }
         if(is_null($filters)) {
-            //$filters = ['language' => ["http://lexvo.org/id/iso639-3/oci", "http://lexvo.org/id/iso639-3/bre"]];
             $filters = [];
         }
 
-        $qFilterParts = [];
-
-        if(array_key_exists('language', $filters) && !empty($filters['language'])) {
-            $languages = $filters['language'];
-            if(is_string($languages)) {
-                $languages = [ $languages, ];
-            }
-            $languages = array_slice($languages, config('corpusparole.filter_max_languages_nb', 200));
-            $fp = CorpusFilterManager::getLanguagesFilterPart($languages);
-            if(!empty($fp)) {
-                $qFilterParts[] = $fp;
-            }
-        }
-        if(array_key_exists('location', $filters) && !empty($filters['location'])) {
-            $location = $filters['location'];
-            if(is_array($location)) {
-                $location = $location[0]; // we know it is not empty
-            }
-            $fp = CorpusFilterManager::getLocationFilterPart($location);
-            if(!empty($fp)) {
-                $qFilterParts[] = $fp;
-            }
-
-        }
-        if(array_key_exists('themes', $filters) && !empty($filters['themes'])) {
-            $themes = $filters['themes'];
-            if(is_string($themes)) {
-                $themes = [$themes,]; // we know it is not empty
-            }
-            $fp = CorpusFilterManager::getThemeFilterPart($themes);
-            if(!empty($fp)) {
-                $qFilterParts[] = $fp;
-            }
-
-        }
-        if(array_key_exists('discourses', $filters) && !empty($filters['discourses'])) {
-            $discourses = $filters['discourses'];
-            if(is_string($discourses)) {
-                $discourses = [$discourses,]; // we know it is not empty
-            }
-            $fp = CorpusFilterManager::getDiscourseFilterPart($discourses);
-            if(!empty($fp)) {
-                $qFilterParts[] = $fp;
-            }
-
-        }
-        if(array_key_exists('dates', $filters) && !empty($filters['dates'])) {
-            $dates = $filters['dates'];
-            if(is_string($dates)) {
-                $dates = [$dates,]; // we know it is not empty
-            }
-            $fp = CorpusFilterManager::getDateFilterPart($dates);
-            if(!empty($fp)) {
-                $qFilterParts[] = $fp;
-            }
-        }
-
+        $filterManager = new CorpusFilterManager();
+        $qFilterParts = $filterManager->buildESFilters($filters);
 
         $query = [
             'index' => config('corpusparole.elasticsearch_index'),
@@ -222,6 +166,11 @@
             ] ];
         }
 
+        Log::debug("QUERY :");
+        Log::debug(json_encode($query, JSON_PRETTY_PRINT));
+        Log::debug("FILTERS :");
+        Log::debug(json_encode($filters, JSON_PRETTY_PRINT));
+
         $esRes = Es::search($query);
 
         return ['total' => $esRes['hits']['total'], 'documents' => array_map(function($r) {