Commit 3c0a7eb5 authored by Jonas Waeber's avatar Jonas Waeber

Add filter field to places & persons.

parent 1a5a77de
......@@ -64,8 +64,7 @@ class SearchDocTransform {
val creatorAgentBuilder = AgentContainerBuilder(emptyList(), KEYS.Agent, KEYS.creator, input)
val placesRelatedBuilder = FacettedContainerBuilder(spatialIds, KEYS.Place, KEYS.name, FacetBuildHelpers::place)
val placeCapturedBuilder =
FacettedContainerBuilder(placeOfCaptureIds, KEYS.Place, KEYS.name, FacetBuildHelpers::place)
val placeCapturedBuilder = FacettedContainerBuilder(placeOfCaptureIds, KEYS.Place, KEYS.name, FacetBuildHelpers::place)
val placeFacetBuilder = PlaceFacetBuilder()
......
......@@ -65,16 +65,17 @@ class AgentContainerBuilder(
} else {
null
}
val facet = if (agentType == KEYS.Person) {
val filterAndFacet = if (agentType == KEYS.Person) {
FacetBuildHelpers.person(jsonObject)
} else {
null
Pair(null, null)
}
containers.add(
AgentWithRelationContainer(
name,
relation,
facet
filter = filterAndFacet.first,
facet = filterAndFacet.second
)
)
return "Created person container for person ${jsonObject[KEYS.entityId]}"
......
......@@ -31,7 +31,7 @@ class FacettedContainerBuilder(
private val identifiers: List<String>,
private val targetType: String,
private val nameProperty: String,
private val facetFunction: (jsonObject: JsonObject) -> List<String>
private val facetFunction: (jsonObject: JsonObject) -> Pair<String?, List<String>>
) : IFieldBuilder {
private val containers = mutableListOf<FacettedContainer>()
......@@ -42,11 +42,13 @@ class FacettedContainerBuilder(
}
override fun append(jsonObject: JsonObject): String {
val filterAndFacet = facetFunction(jsonObject)
containers.add(
FacettedContainer(
Extract.languageContainer("", jsonObject[nameProperty])
.reduce { acc, languageContainer -> acc.merge(languageContainer) },
facet = facetFunction(jsonObject)
filter = filterAndFacet.first,
facet = filterAndFacet.second
)
)
return ""
......
......@@ -40,8 +40,8 @@ class PersonFacetBuilder : IFieldBuilder {
override fun append(jsonObject: JsonObject): String {
val result = FacetBuildHelpers.person(jsonObject)
return if (result.isNotEmpty()) {
personFacetValues.addAll(result)
return if (result.second.isNotEmpty()) {
personFacetValues.addAll(result.second)
""
} else {
val message = "Failed to create facet values for persons: ${jsonObject[KEYS.entityId]}."
......
......@@ -40,8 +40,8 @@ class PlaceFacetBuilder : IFieldBuilder {
override fun append(jsonObject: JsonObject): String {
val result = FacetBuildHelpers.place(jsonObject)
return if (result.isNotEmpty()) {
placeFacetValues.addAll(result)
return if (result.second.isNotEmpty()) {
placeFacetValues.addAll(result.second)
""
} else {
val message = "Failed to create facet values for place: ${jsonObject[KEYS.entityId]}."
......
......@@ -27,9 +27,9 @@ object CarrierType {
Extract.listOfStrings(it["sameAs"]).let { value ->
val name = Extract.languageContainer("carrierType", it["name"]).reduce { acc, languageContainer -> acc.merge(languageContainer) }
if (value.isEmpty()) {
FacettedContainer(name, emptyList())
FacettedContainer(name, null, emptyList())
} else {
FacettedContainer(name, value)
FacettedContainer(name, null, value)
}
}
}
......
......@@ -96,7 +96,7 @@ object Extract {
if (lang.isEmpty()) {
null
} else {
FacettedContainer(lang.first(), lang.first().toList())
FacettedContainer(lang.first(), null, lang.first().toList())
}
}
}
......
......@@ -29,7 +29,7 @@ object FacetBuildHelpers {
private const val level2 = "1"
private val isAlphaChar = Regex("[A-Za-z]")
fun person(jsonObject: JsonObject): List<String> {
fun person(jsonObject: JsonObject): Pair<String?, List<String>> {
val name = when {
jsonObject.containsKey(KEYS.lastName) -> {
jsonObject[KEYS.lastName] as String
......@@ -38,7 +38,7 @@ object FacetBuildHelpers {
jsonObject[KEYS.name] as String
}
else -> {
return emptyList()
return Pair(null, emptyList())
}
}
val displayName = jsonObject[KEYS.lastName].let { lastName ->
......@@ -49,13 +49,13 @@ object FacetBuildHelpers {
}
val capitalLetter = getCapitalLetter(name)
return listOf(
return Pair(displayName as String, listOf(
"$level1$separator$capitalLetter$separator",
"$level2$separator$capitalLetter$separator$displayName$separator"
)
))
}
fun place(jsonObject: JsonObject): List<String> {
fun place(jsonObject: JsonObject): Pair<String?, List<String>> {
if (!jsonObject.containsKey(KEYS.name)) {
throw Exception("Place does not contain a name: ${jsonObject[KEYS.entityId]}.")
}
......@@ -64,10 +64,10 @@ object FacetBuildHelpers {
val capitalLetter = getCapitalLetter(name)
return listOf(
return Pair(name, listOf(
"$level1$separator$capitalLetter$separator",
"$level2$separator$capitalLetter$separator$name$separator"
)
))
}
private fun getCapitalLetter(name: String): Char {
......
......@@ -25,12 +25,14 @@ object Meta {
is String -> listOf(
FacettedContainer(
LanguageContainer(emptyList(), emptyList(), emptyList(), emptyList()),
null,
listOf(removeNamespace(key, items))
)
)
is List<*> -> items.map { item ->
FacettedContainer(
LanguageContainer(emptyList(), emptyList(), emptyList(), emptyList()),
null,
listOf(removeNamespace(key, item as String))
)
}
......
......@@ -21,5 +21,6 @@ package org.memobase.model
data class AgentWithRelationContainer(
val name: LanguageContainer,
val relation: LanguageContainer?,
val filter: String?,
val facet: List<String>?
)
......@@ -23,5 +23,6 @@ import com.fasterxml.jackson.annotation.JsonInclude
@JsonInclude(JsonInclude.Include.NON_NULL)
data class FacettedContainer(
val name: LanguageContainer,
val filter: String?,
val facet: List<String>
)
{"title":[{"de":[],"fr":[],"it":[],"un":["Bern: Altstadt, obere; Bundesplatz 4; Bärenplatz (31); Käfiggässchen; -- Fuhrwerk; Automobil; Lastwagen; Transport, Verkehr; Strassenbeleuchtung"]}],"type":"Foto","sourceID":"216133","id":"https://memobase.ch/record/Burgerbib-Krebser-216133","descriptiveNote":[{"de":[],"fr":[],"it":[],"un":["Datierung: Bundesplatz / Büren-Besitzung<br>"]}],"rightsHolder":[{"de":[],"fr":[],"it":[],"un":["Burgerbibliothek Bern"]}],"sameAs":["http://katalog.burgerbib.ch/detail.aspx?ID=216133"],"keywords":[{"name":{"de":[],"fr":[],"it":[],"un":["Transport, Verkehr"]},"facet":["Transport, Verkehr"]}],"personCreator":[{"name":{"de":[],"fr":[],"it":[],"un":["Anonym"]},"relation":{"de":[],"fr":[],"it":[],"un":["author"]},"facet":["0~A~","1~A~Anonym~"]}],"personContributor":[{"name":{"de":[],"fr":[],"it":[],"un":["Familie Krebser"]},"relation":{"de":[],"fr":[],"it":[],"un":["Collector/Sammler"]},"facet":["0~F~","1~F~Familie Krebser~"]}],"personsFacet":["0~A~","1~A~Anonym~","0~F~","1~F~Familie Krebser~"],"placeRelated":[{"name":{"de":[],"fr":[],"it":[],"un":["Käfiggässchen"]},"facet":["0~K~","1~K~Käfiggässchen~"]}],"placeFacet":["0~K~","1~K~Käfiggässchen~"],"dateCreated":[{"date":"1900/1909","facet":[]}],"institution":[{"name":{"de":[],"fr":[],"it":[],"un":[]},"facet":["Burgerbib"]}],"recordSet":{"name":{"de":[],"fr":[],"it":[],"un":[]},"facet":["Burgerbib-Krebser"]},"memoriavClaim":true,"callNumber":["Historische Sammlung Krebser 13/2"],"physicalCharacteristics":[{"de":[],"fr":[],"it":[],"un":["Weite: 85 mm","Höhe: 100 mm"]}],"format":[{"name":{"de":["Glasplatte"],"fr":[],"it":[],"un":[]},"facet":["http://www.wikidata.org/entity/Q1138868"]},{"name":{"de":[],"fr":[],"it":[],"un":["Glasplatte"]},"facet":[]}],"published":false,"suggest":{"title":["Bern: Altstadt, obere; Bundesplatz 4; Bärenplatz (31); Käfiggässchen; -- Fuhrwerk; Automobil; Lastwagen; Transport, Verkehr; Strassenbeleuchtung"],"seriesTitle":[],"broadcastTitle":[],"keywords":["Transport, Verkehr"]}}
\ No newline at end of file
{"title":[{"de":[],"fr":[],"it":[],"un":["Bern: Altstadt, obere; Bundesplatz 4; Bärenplatz (31); Käfiggässchen; -- Fuhrwerk; Automobil; Lastwagen; Transport, Verkehr; Strassenbeleuchtung"]}],"type":"Foto","sourceID":"216133","id":"https://memobase.ch/record/Burgerbib-Krebser-216133","descriptiveNote":[{"de":[],"fr":[],"it":[],"un":["Datierung: Bundesplatz / Büren-Besitzung<br>"]}],"rightsHolder":[{"de":[],"fr":[],"it":[],"un":["Burgerbibliothek Bern"]}],"sameAs":["http://katalog.burgerbib.ch/detail.aspx?ID=216133"],"keywords":[{"name":{"de":[],"fr":[],"it":[],"un":["Transport, Verkehr"]},"facet":["Transport, Verkehr"]}],"personCreator":[{"name":{"de":[],"fr":[],"it":[],"un":["Anonym"]},"relation":{"de":[],"fr":[],"it":[],"un":["author"]},"filter":"Anonym","facet":["0~A~","1~A~Anonym~"]}],"personContributor":[{"name":{"de":[],"fr":[],"it":[],"un":["Familie Krebser"]},"relation":{"de":[],"fr":[],"it":[],"un":["Collector/Sammler"]},"filter":"Familie Krebser","facet":["0~F~","1~F~Familie Krebser~"]}],"personsFacet":["0~A~","1~A~Anonym~","0~F~","1~F~Familie Krebser~"],"placeRelated":[{"name":{"de":[],"fr":[],"it":[],"un":["Käfiggässchen"]},"filter":"Käfiggässchen","facet":["0~K~","1~K~Käfiggässchen~"]}],"placeFacet":["0~K~","1~K~Käfiggässchen~"],"dateCreated":[{"date":"1900/1909","facet":[]}],"institution":[{"name":{"de":[],"fr":[],"it":[],"un":[]},"facet":["Burgerbib"]}],"recordSet":{"name":{"de":[],"fr":[],"it":[],"un":[]},"facet":["Burgerbib-Krebser"]},"memoriavClaim":true,"callNumber":["Historische Sammlung Krebser 13/2"],"physicalCharacteristics":[{"de":[],"fr":[],"it":[],"un":["Weite: 85 mm","Höhe: 100 mm"]}],"format":[{"name":{"de":["Glasplatte"],"fr":[],"it":[],"un":[]},"facet":["http://www.wikidata.org/entity/Q1138868"]},{"name":{"de":[],"fr":[],"it":[],"un":["Glasplatte"]},"facet":[]}],"published":false,"suggest":{"title":["Bern: Altstadt, obere; Bundesplatz 4; Bärenplatz (31); Käfiggässchen; -- Fuhrwerk; Automobil; Lastwagen; Transport, Verkehr; Strassenbeleuchtung"],"seriesTitle":[],"broadcastTitle":[],"keywords":["Transport, Verkehr"]}}
\ No newline at end of file
{"title":[{"de":[],"fr":[],"it":[],"un":["Anonym -- Armut"]}],"type":"Foto","sourceID":"208576","id":"https://memobase.ch/record/Burgerbib-Krebser-208576","abstract":[{"de":[],"fr":[],"it":[],"un":["Bildeintrag: auf der Verpackung: 49543<br>"]}],"descriptiveNote":[{"de":[],"fr":[],"it":[],"un":["Datierung: Negativnummer<br>"]}],"rightsHolder":[{"de":[],"fr":[],"it":[],"un":["Burgerbibliothek Bern"]}],"sameAs":["http://katalog.burgerbib.ch/detail.aspx?ID=208576"],"keywords":[{"name":{"de":[],"fr":[],"it":[],"un":["Armut"]},"facet":["Armut"]}],"personCreator":[{"name":{"de":[],"fr":[],"it":[],"un":["Moeglé, Jean"]},"relation":{"de":[],"fr":[],"it":[],"un":["author"]},"facet":["0~M~","1~M~Moeglé, Jean~"]}],"personContributor":[{"name":{"de":[],"fr":[],"it":[],"un":["Familie Krebser"]},"relation":{"de":[],"fr":[],"it":[],"un":["Collector/Sammler"]},"facet":["0~F~","1~F~Familie Krebser~"]}],"personsFacet":["0~F~","1~F~Familie Krebser~","0~M~","1~M~Moeglé, Jean~"],"dateCreated":[{"date":"20. Jh.","facet":[]}],"institution":[{"name":{"de":[],"fr":[],"it":[],"un":[]},"facet":["Burgerbib"]}],"recordSet":{"name":{"de":[],"fr":[],"it":[],"un":[]},"facet":["Burgerbib-Krebser"]},"memoriavClaim":true,"callNumber":["Historische Sammlung Krebser 64/21"],"physicalCharacteristics":[{"de":[],"fr":[],"it":[],"un":["Weite: 165 mm","Höhe: 120 mm"]}],"format":[{"name":{"de":["Glasplatte"],"fr":[],"it":[],"un":[]},"facet":["http://www.wikidata.org/entity/Q1138868"]},{"name":{"de":[],"fr":[],"it":[],"un":["Glasplatte"]},"facet":[]}],"published":false,"suggest":{"title":["Anonym -- Armut"],"seriesTitle":[],"broadcastTitle":[],"keywords":["Armut"]}}
\ No newline at end of file
{"title":[{"de":[],"fr":[],"it":[],"un":["Anonym -- Armut"]}],"type":"Foto","sourceID":"208576","id":"https://memobase.ch/record/Burgerbib-Krebser-208576","abstract":[{"de":[],"fr":[],"it":[],"un":["Bildeintrag: auf der Verpackung: 49543<br>"]}],"descriptiveNote":[{"de":[],"fr":[],"it":[],"un":["Datierung: Negativnummer<br>"]}],"rightsHolder":[{"de":[],"fr":[],"it":[],"un":["Burgerbibliothek Bern"]}],"sameAs":["http://katalog.burgerbib.ch/detail.aspx?ID=208576"],"keywords":[{"name":{"de":[],"fr":[],"it":[],"un":["Armut"]},"facet":["Armut"]}],"personCreator":[{"name":{"de":[],"fr":[],"it":[],"un":["Moeglé, Jean"]},"relation":{"de":[],"fr":[],"it":[],"un":["author"]},"filter":"Moeglé, Jean","facet":["0~M~","1~M~Moeglé, Jean~"]}],"personContributor":[{"name":{"de":[],"fr":[],"it":[],"un":["Familie Krebser"]},"relation":{"de":[],"fr":[],"it":[],"un":["Collector/Sammler"]},"filter":"Familie Krebser","facet":["0~F~","1~F~Familie Krebser~"]}],"personsFacet":["0~F~","1~F~Familie Krebser~","0~M~","1~M~Moeglé, Jean~"],"dateCreated":[{"date":"20. Jh.","facet":[]}],"institution":[{"name":{"de":[],"fr":[],"it":[],"un":[]},"facet":["Burgerbib"]}],"recordSet":{"name":{"de":[],"fr":[],"it":[],"un":[]},"facet":["Burgerbib-Krebser"]},"memoriavClaim":true,"callNumber":["Historische Sammlung Krebser 64/21"],"physicalCharacteristics":[{"de":[],"fr":[],"it":[],"un":["Weite: 165 mm","Höhe: 120 mm"]}],"format":[{"name":{"de":["Glasplatte"],"fr":[],"it":[],"un":[]},"facet":["http://www.wikidata.org/entity/Q1138868"]},{"name":{"de":[],"fr":[],"it":[],"un":["Glasplatte"]},"facet":[]}],"published":false,"suggest":{"title":["Anonym -- Armut"],"seriesTitle":[],"broadcastTitle":[],"keywords":["Armut"]}}
\ No newline at end of file
Markdown is supported
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