diff -r c622fa18eb32 -r 145561ff51ff server/src/app/Console/Commands/IndexDocuments.php --- a/server/src/app/Console/Commands/IndexDocuments.php Thu Oct 20 12:56:24 2016 +0530 +++ b/server/src/app/Console/Commands/IndexDocuments.php Thu Oct 20 11:24:45 2016 +0200 @@ -109,6 +109,13 @@ 'creation_date' => ['type' => 'date', 'index' => 'not_analyzed'], 'language' => ['type' => 'string', 'index' => 'not_analyzed'], 'discourse_types' => ['type' => 'string', 'index' => 'not_analyzed'], + 'creation_years' => [ + 'type' => 'nested', + 'properties' => [ + 'year' => [ 'type' => 'short', 'index' => 'not_analyzed'], + 'weight' => [ 'type' => 'float', 'index' => 'not_analyzed'], + ] + ] , 'subject' => [ 'type' => 'nested', 'properties' => [ @@ -405,7 +412,7 @@ return $date; } - private function processPeriod($periodStr) { + private function processPeriod($periodStr, $asDate=false) { $start = null; $end = null; foreach(explode(";", $periodStr) as $elem) { @@ -436,18 +443,59 @@ return null; } - return array_map(function($y) { - return \DateTime::createFromFormat("Y", "$y")->format(\DateTime::W3C); + return array_map(function($y) use ($asDate){ + $date = \DateTime::createFromFormat("Y", "$y"); + if($asDate) { + return $date; + } else { + return $date->format(\DateTime::W3C); + } + }, range($start, $end)); } - private function processDate($dateStr) { + private function processDate($dateStr, $asDate=false) { $date = $this->extractDate($dateStr); if(is_null($date)) { return null; } else { - return $date->format(\DateTime::W3C); + if($asDate) { + return $date; + } else { + return $date->format(\DateTime::W3C); + } + + } + } + + private function getCreationYears($doc) { + $created = $doc->getCreated(); + if(is_null($created)) { + return []; } + $dateType = $created->getDatatypeUri(); + $dates = null; + + if($dateType === "http://purl.org/dc/terms/Period") { + $dates = $this->processPeriod($created->getValue(), true); + } + elseif($dateType === "http://purl.org/dc/terms/W3CDTF") { + $dates = $this->processDate($created->getValue(), true); + if(!is_null($dates)) { + $dates = [ $dates, ]; + } + } + if(is_null($dates)) { + return []; + } + $count = count($dates); + return array_map(function($d) use ($count) { + return [ + 'year' => intval($d->format("Y")), + 'weight' => 1/$count + ]; + + }, $dates); } private function getDiscourseTypes($doc) { @@ -472,6 +520,7 @@ 'date' => (string)$doc->getModified(), 'location' => $this->getLocation($doc), 'creation_date' => $this->getCreationDate($doc), + 'creation_years' => $this->getCreationYears($doc), 'language' => $doc->getLanguagesValue(), 'discourse_types' => $this->getDiscourseTypes($doc), 'geonames_hierarchy' => $this->getGeonamesHierarchy($doc),