Skip to content

Commit

Permalink
modify the should terms query
Browse files Browse the repository at this point in the history
  • Loading branch information
jdhayhurst committed Oct 21, 2024
1 parent 7944e53 commit d9573a1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
8 changes: 7 additions & 1 deletion app/models/Backend.scala
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,13 @@ class Backend @Inject() (implicit
val indexName = getIndexOrDefault("variant_index")

//esRetriever.getByIds(indexName, ids, fromJsValue[VariantIndex])
esRetriever.getByIndexedTermsMust(indexName, Map("variantId.keyword" -> ids), Pagination.mkDefault, fromJsValue[VariantIndex]).map(_._1)
esRetriever
.getByIndexedTermsMust(indexName,
Map("variantId.keyword" -> ids),
Pagination.mkDefault,
fromJsValue[VariantIndex]
)
.map(_._1)
}

def getBiosample(id: String): Future[Option[Biosample]] = {
Expand Down
6 changes: 6 additions & 0 deletions app/models/ElasticRetriever.scala
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@ class ElasticRetriever @Inject() (
getByIndexedQuery(searchRequest, sortByField, buildF)
}

/** This fn represents a query where each kv from the map is used in
* a bool 'must' (AND) with optional filters that are 'must' (AND).
*/
def getByIndexedTermsMust[A, V](
esIndex: String,
kv: Map[String, V],
Expand All @@ -184,6 +187,9 @@ class ElasticRetriever @Inject() (
getByIndexedQuery(searchRequest, sortByField, buildF)
}

/** This fn represents a query where each kv from the map is used in
* a bool 'should' (OR) with optional filters that are 'must' (AND).
*/
def getByIndexedTermsShould[A, V](
esIndex: String,
kv: Map[String, V],
Expand Down
8 changes: 4 additions & 4 deletions app/models/ElasticRetrieverQueryBuilders.scala
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,12 @@ trait ElasticRetrieverQueryBuilders extends QueryApi with Logging {
val limitClause = indexQuery.pagination.toES
val query: Iterable[Query] = {
val querySeq = indexQuery.kv.toSeq
querySeq.flatMap { it =>
Iterable(f(querySeq.map { it =>
val terms = it._2.asInstanceOf[Iterable[String]]
Iterable(should(termsQuery(it._1, terms)))
}
termsQuery(it._1, terms)
}))
}
val boolQuery: BoolQuery = f(query).filter(indexQuery.filters)
val boolQuery: BoolQuery = must(query).filter(indexQuery.filters)
logger.debug(s"Query: $boolQuery")
search(indexQuery.esIndex)
.bool(boolQuery)
Expand Down

0 comments on commit d9573a1

Please sign in to comment.