Commit 6a2bb627 authored by Mohamed, Fawzi Roberto (fawzi)'s avatar Mohamed, Fawzi Roberto (fawzi)
Browse files

hack to support repository_main_file_uri.split

parent 38ee6df4
......@@ -23,9 +23,10 @@ import com.sksamuel.elastic4s.http.ElasticDsl.{ matchAllQuery, search }
import com.sksamuel.elastic4s.searches.SearchDefinition
import com.sksamuel.elastic4s.searches.queries.matches.MatchQueryDefinition
import com.sksamuel.elastic4s.searches.queries.term.{ TermQueryDefinition, TermsQueryDefinition }
import com.sksamuel.elastic4s.searches.queries.{ BoolQueryDefinition, ExistsQueryDefinition, QueryDefinition, RangeQueryDefinition }
import com.sksamuel.elastic4s.searches.queries.{ BoolQueryDefinition, ExistsQueryDefinition, QueryDefinition, RangeQueryDefinition, RegexQueryDefinition }
import eu.nomad_lab.jsonapi
import eu.nomad_lab.meta.MetaInfoEnv
import eu.nomad_lab.JsonUtils
import eu.nomad_lab.query.QueryQuantifier.QueryQuantifier
import eu.nomad_lab.query._
import org.{ json4s => jn }
......@@ -35,6 +36,9 @@ object ConnectorElasticSearch {
val queryAuxiliaryDataName = "query_auxiliary_data"
val countSection = "value_counts"
val special_meta = Map(
"repository_main_file_uri" -> "section_repository_info.main_file_uri"
)
object FieldUsage extends Enumeration {
val Search = Value
......@@ -51,9 +55,13 @@ object ConnectorElasticSearch {
* @throws ApiCallException if a meta-data name is unknown
*/
def metaNameToField(metaName: String)(implicit metaData: MetaInfoEnv): String = {
val fieldName = metaData.pathViaSections(metaName).drop(1).replace("/", ".")
if (fieldName.isEmpty) throw ApiCallException(s"unknown metadata $metaName")
fieldName
special_meta.get(metaName) match {
case Some(v) => v
case None =>
val fieldName = metaData.pathViaSections(metaName).drop(1).replace("/", ".")
if (fieldName.isEmpty) throw ApiCallException(s"unknown metadata $metaName")
fieldName
}
}
/**
......@@ -116,10 +124,14 @@ class ConnectorElasticSearch protected[elasticsearch] (val metaInfo: MetaInfoEnv
* @throws ApiCallException if a meta-data name is unknown or not an indexed field
*/
def metaNameToField(metaName: String): String = {
val fieldName = metaInfo.pathViaSections(metaName).drop(1).replace("/", ".")
if (fieldName.isEmpty) throw ApiCallException(s"unknown metadata $metaName")
if (!allFields.contains(metaName)) throw ApiCallException(s"metadata $metaName is not indexed")
fieldName
ConnectorElasticSearch.special_meta.get(metaName) match {
case Some(v) => v
case None =>
val fieldName = metaInfo.pathViaSections(metaName).drop(1).replace("/", ".")
if (fieldName.isEmpty) throw ApiCallException(s"unknown metadata $metaName")
if (!allFields.contains(metaName)) throw ApiCallException(s"metadata $metaName is not indexed")
fieldName
}
}
/**
......@@ -196,11 +208,13 @@ class ConnectorElasticSearch protected[elasticsearch] (val metaInfo: MetaInfoEnv
}
private def convertAtomicTerm(term: AtomicTerm): Either[jsonapi.Error, QueryDefinition] = {
if (metaInfo.pathViaSections(term.metaName) == "")
val specialMeta = ConnectorElasticSearch.special_meta
val isSpecialMeta = specialMeta.contains(term.metaName)
if (metaInfo.pathViaSections(term.metaName) == "" && !isSpecialMeta)
Left(jsonapi.Error(errorTitle, s"unknown meta-data ${term.metaName}", term.toString))
else if (!allFields.contains(term.metaName))
else if (!allFields.contains(term.metaName) && !isSpecialMeta)
Left(jsonapi.Error(errorTitle, s"metadata ${term.metaName} is not indexed", term.toString))
else if (allFields(term.metaName) == "nested")
else if (!isSpecialMeta && allFields(term.metaName) == "nested")
Left(jsonapi.Error(errorTitle, s"metadata ${term.metaName} is a nested field", term.toString))
else if (term.compareOp.isEmpty && term.values.nonEmpty)
Left(jsonapi.Error(errorTitle, "empty set of values", term.toString))
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment