Skip to content

Commit

Permalink
Merge remote-tracking branch 'github/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
hayco committed Nov 27, 2024
2 parents 785a612 + fd08847 commit ac2befc
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 14 deletions.
11 changes: 11 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,17 @@
<groupId>io.github.knaw-huc</groupId>
<artifactId>annorepo-client</artifactId>
<version>${annorepo-client.version}</version>
<exclusions>
<exclusion>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
<version>3.25.5</version>
</dependency>

<dependency>
Expand Down
12 changes: 8 additions & 4 deletions src/main/kotlin/nl/knaw/huc/broccoli/api/IndexQuery.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@ data class IndexQuery(
val aggregations: Map<String, Map<String, Any>>? = null
) {
override fun toString(): String = buildString {
text?.let { append(it).append('|') }
date?.let { append(it).append('|') }
range?.let { append(it).append('|') }
terms?.let { append(it).append('|') }
text?.let { append(it) }
append('|')
terms?.let { append(it) }
append('|')
date?.let { append(it) }
append('|')
range?.let { append(it) }
append('|')
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,14 @@ class ProjectsResource(
.fragmentSize(fragmentSize)

val baseQuery = queryBuilder.toElasticQuery()
logger.debug("base ES query: {}", jsonWriter.writeValueAsString(baseQuery))
logger.atTrace().addKeyValue("ES query", jsonWriter.writeValueAsString(baseQuery)).log("base")

val baseResult = client
.target(project.brinta.uri).path(index.name).path("_search")
.request().post(Entity.json(baseQuery))
validateElasticResult(baseResult, queryString)
val baseJson = baseResult.readEntityAsJsonString()
.also { logger.trace("base json: {}", it) }
logger.atTrace().addKeyValue("json", baseJson).log("base")

val result: MutableMap<String, Any> = mutableMapOf()
val aggs: MutableMap<String, Any> = mutableMapOf()
Expand All @@ -121,7 +121,7 @@ class ProjectsResource(
?.let { result["total"] = it }

extractAggregations(index, context)?.let { aggs.putAll(it) }
logger.atDebug().addKeyValue("aggs", aggs).log("base")
logger.atTrace().addKeyValue("aggs", aggs).log("base")

context.read<List<Map<String, Any>>>("$.hits.hits[*]")
?.map { buildHitResult(index, it) }
Expand All @@ -130,12 +130,14 @@ class ProjectsResource(

val auxQueries = queryBuilder.toMultiFacetCountQueries()
auxQueries.forEachIndexed { auxIndex, auxQuery ->
logger.atDebug().log("aux ES query[$auxIndex]: ${jsonWriter.writeValueAsString(auxQuery)}")
logger.atTrace().addKeyValue("query[$auxIndex]", jsonWriter.writeValueAsString(auxQuery)).log("aux")

val auxResult = client.target(project.brinta.uri).path(index.name).path("_search")
.request().post(Entity.json(auxQuery))
validateElasticResult(auxResult, queryString)
val auxJson = auxResult.readEntityAsJsonString()
.also { logger.trace("aux json[{}]: {}", auxIndex, it) }
logger.atTrace().addKeyValue("json", auxJson).log("aux")

jsonParser.parse(auxJson).let { context ->
extractAggregations(index, context)
?.forEach { entry ->
Expand Down Expand Up @@ -184,12 +186,14 @@ class ProjectsResource(
}

private fun logQuery(query: IndexQuery, from: Int, size: Int) {
if (query.text != null) {
logger.atDebug()
.addMarker(queryMarker)
.setMessage("${query}from=$from|size=$size")
.log()
if (query.text.isNullOrBlank() && query.terms.isNullOrEmpty()) {
// nothing useful to log
return
}

logger.atInfo()
.addMarker(queryMarker)
.log("${query}from=$from|size=$size")
}

private fun buildHitResult(index: IndexConfiguration, hit: Map<String, Any>) =
Expand Down

0 comments on commit ac2befc

Please sign in to comment.