server/src/app/Repositories/RdfDocumentRepository.php
changeset 502 74fba571487e
parent 499 b5cff30efa0a
child 506 8a5bb4b48b85
--- a/server/src/app/Repositories/RdfDocumentRepository.php	Mon Feb 06 16:05:02 2017 +0100
+++ b/server/src/app/Repositories/RdfDocumentRepository.php	Wed Feb 08 15:25:24 2017 +0100
@@ -423,4 +423,30 @@
 
         return $docList;
     }
+
+    /**
+     * Add country info for document.
+     * This modify the document
+     *
+     * @param $doc the document instance
+     * @return nothing
+     */
+    public function addCountryInfo($doc) {
+        $params = [
+            'index' => config('corpusparole.elasticsearch_index'),
+            'type' => 'document',
+            'id' => $doc->getId()
+        ];
+        $esRes = Es::get($params);
+
+        if(!empty($esRes) && $esRes['found']) {
+            $source = $esRes["_source"];
+            if(array_key_exists('geonames_country', $source)) {
+                $doc->setCountryCode($source['geonames_country']);
+            }
+        } else {
+            Log::error("RdfDocumentRepository::addCountryInfo : Document ".$doc->getId()." not found in index.");
+        }
+    }
+
 }