Skip to content

Commit

Permalink
Add autoGenerateSynonymsPhraseQuery to MatchQuery (#3058)
Browse files Browse the repository at this point in the history
  • Loading branch information
Philippus committed May 5, 2024
1 parent ab34744 commit 0a5c0af
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,16 @@ case class MatchQuery(field: String,
operator: Option[Operator] = None,
prefixLength: Option[Int] = None,
queryName: Option[String] = None,
zeroTerms: Option[String] = None)
zeroTerms: Option[String] = None,
autoGenerateSynonymsPhraseQuery: Option[Boolean] = None)
extends Query {

def analyzer(an: String): MatchQuery = copy(analyzer = an.some)
def analyzer(an: Analyzer): MatchQuery = copy(analyzer = an.name.some)

def autoGenerateSynonymsPhraseQuery(autoGenerate: Boolean): MatchQuery =
copy(autoGenerateSynonymsPhraseQuery = autoGenerate.some)

def boost(boost: Double): MatchQuery = copy(boost = boost.some)
def cutoffFrequency(f: Double): MatchQuery = copy(cutoffFrequency = f.some)
def lenient(lenient: Boolean): MatchQuery = copy(lenient = lenient.some)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ object MatchQueryBuilderFn {

q.queryName.foreach(builder.field("_name", _))
q.analyzer.foreach(builder.field("analyzer", _))
q.autoGenerateSynonymsPhraseQuery.foreach(builder.field("auto_generate_synonyms_phrase_query", _))
q.boost.foreach(builder.field("boost", _))
q.cutoffFrequency.map(_.toString).foreach(builder.field("cutoff_frequency", _))
q.fuzziness.foreach(builder.field("fuzziness", _))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"name": {
"query": "coldplay",
"analyzer": "french",
"auto_generate_synonyms_phrase_query": false,
"cutoff_frequency": "3.4",
"fuzziness": "2",
"fuzzy_transpositions": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ class SearchDslTest extends AnyFlatSpec with MockitoSugar with JsonSugar with On
.fuzziness("2")
.prefixLength(4)
.analyzer(FrenchLanguageAnalyzer)
.autoGenerateSynonymsPhraseQuery(false)
}
req.request.entity.get.get should matchJsonResource("/json/search/search_match.json")
}
Expand Down

0 comments on commit 0a5c0af

Please sign in to comment.