Skip to content

Commit

Permalink
Parameters for match_all query
Browse files Browse the repository at this point in the history
  • Loading branch information
anti-social committed Sep 18, 2023
1 parent 198c817 commit 36d7759
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 6 deletions.
31 changes: 28 additions & 3 deletions elasticmagic/api/elasticmagic.api
Original file line number Diff line number Diff line change
Expand Up @@ -3773,15 +3773,40 @@ public final class dev/evo/elasticmagic/query/Match : dev/evo/elasticmagic/query
public fun visit (Ldev/evo/elasticmagic/serde/Serializer$ObjectCtx;Ldev/evo/elasticmagic/compile/BaseSearchQueryCompiler;)V
}

public final class dev/evo/elasticmagic/query/MatchAll : dev/evo/elasticmagic/query/QueryExpression {
public static final field INSTANCE Ldev/evo/elasticmagic/query/MatchAll;
public final class dev/evo/elasticmagic/query/MatchAll : dev/evo/elasticmagic/query/MatchAllQuery {
public static final field Companion Ldev/evo/elasticmagic/query/MatchAll$Companion;
public fun <init> ()V
public fun <init> (Ljava/lang/Float;Ljava/util/Map;)V
public synthetic fun <init> (Ljava/lang/Float;Ljava/util/Map;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun component1 ()Ljava/lang/Float;
public final fun component2 ()Ljava/util/Map;
public final fun copy (Ljava/lang/Float;Ljava/util/Map;)Ldev/evo/elasticmagic/query/MatchAll;
public static synthetic fun copy$default (Ldev/evo/elasticmagic/query/MatchAll;Ljava/lang/Float;Ljava/util/Map;ILjava/lang/Object;)Ldev/evo/elasticmagic/query/MatchAll;
public fun equals (Ljava/lang/Object;)Z
public fun getBoost ()Ljava/lang/Float;
public fun getParams ()Ljava/util/Map;
public fun hashCode ()I
public fun toString ()Ljava/lang/String;
}

public final class dev/evo/elasticmagic/query/MatchAll$Companion : dev/evo/elasticmagic/query/MatchAllQuery {
public synthetic fun getBoost ()Ljava/lang/Float;
public fun getBoost ()Ljava/lang/Void;
public fun getParams ()Ljava/lang/Void;
public synthetic fun getParams ()Ljava/util/Map;
}

public abstract class dev/evo/elasticmagic/query/MatchAllQuery : dev/evo/elasticmagic/query/QueryExpression {
public fun <init> ()V
public synthetic fun accept (Ldev/evo/elasticmagic/serde/Serializer$Ctx;Ldev/evo/elasticmagic/compile/BaseSearchQueryCompiler;)V
public fun accept (Ldev/evo/elasticmagic/serde/Serializer$ObjectCtx;Ldev/evo/elasticmagic/compile/BaseSearchQueryCompiler;)V
public fun children ()Ljava/util/Iterator;
public synthetic fun clone ()Ldev/evo/elasticmagic/query/Expression;
public fun clone ()Ldev/evo/elasticmagic/query/MatchAll;
public fun clone ()Ldev/evo/elasticmagic/query/MatchAllQuery;
public synthetic fun clone ()Ldev/evo/elasticmagic/query/QueryExpression;
public abstract fun getBoost ()Ljava/lang/Float;
public fun getName ()Ljava/lang/String;
public abstract fun getParams ()Ljava/util/Map;
public synthetic fun reduce ()Ldev/evo/elasticmagic/query/Expression;
public fun reduce ()Ldev/evo/elasticmagic/query/QueryExpression;
public synthetic fun rewrite (Ldev/evo/elasticmagic/query/QueryExpressionNode;)Ldev/evo/elasticmagic/query/Expression;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,17 +109,43 @@ data class MatchPhrase(
}
}

object MatchAll : QueryExpression {
abstract class MatchAllQuery : QueryExpression {
abstract val boost: Float?
abstract val params: Params?

override val name = "match_all"

override fun clone() = this

override fun visit(
ctx: Serializer.ObjectCtx,
compiler: BaseSearchQueryCompiler
) {}
) {
val params = Params(
params,
"boost" to boost,
)
if (params.isNotEmpty()) {
compiler.visit(ctx, params)
}
}
}

data class MatchAll(
override val boost: Float? = null,
override val params: Params? = null,
) : MatchAllQuery() {

// For backward compatibility at source code level.
// Previously match all query was defined as:
// object MatchAll : QueryExpression { ... }
companion object : MatchAllQuery() {
override val boost = null
override val params = null
}
}


/**
* Represents a multi match query that allows to search in several fields at once.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,12 @@ class MatchTests : BaseExpressionTest() {

@Test
fun matchAll() {
MatchAll.compile() shouldContainExactly mapOf("match_all" to emptyMap<String, Any>())
MatchAll.compile() shouldContainExactly mapOf(
"match_all" to emptyMap<String, Any>()
)
MatchAll(boost = 1.2F).compile() shouldContainExactly mapOf(
"match_all" to mapOf("boost" to 1.2F)
)
}

@Test
Expand Down

0 comments on commit 36d7759

Please sign in to comment.