From 2a08d39723b7f4df92b96e2dff891a60952714d6 Mon Sep 17 00:00:00 2001 From: Oliver Eilhard Date: Tue, 26 Sep 2017 22:05:24 +0200 Subject: [PATCH] Add MaxExpansions method in MatchPhrasePrefixQuery Close #615 --- .travis.yml | 2 +- client.go | 2 +- search_queries_match_phrase_prefix.go | 6 ++++++ search_queries_match_phrase_prefix_test.go | 4 ++-- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index ade07bd63..703fa01be 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,5 +12,5 @@ services: - docker before_install: - sudo sysctl -w vm.max_map_count=262144 - - docker run --rm --privileged=true -p 9200:9200 -p 9300:9300 -e "bootstrap.memory_lock=true" -e "ES_JAVA_OPTS=-Xms1g -Xmx1g" docker.elastic.co/elasticsearch/elasticsearch:5.6.0 elasticsearch -Expack.security.enabled=false -Escript.inline=true -Escript.stored=true -Escript.file=true -Enetwork.host=_local_,_site_ -Enetwork.publish_host=_local_ >& /dev/null & + - docker run --rm --privileged=true -p 9200:9200 -p 9300:9300 -e "bootstrap.memory_lock=true" -e "ES_JAVA_OPTS=-Xms1g -Xmx1g" docker.elastic.co/elasticsearch/elasticsearch:5.6.1 elasticsearch -Expack.security.enabled=false -Escript.inline=true -Escript.stored=true -Escript.file=true -Enetwork.host=_local_,_site_ -Enetwork.publish_host=_local_ >& /dev/null & - sleep 30 diff --git a/client.go b/client.go index c192b2dd0..13b45d831 100644 --- a/client.go +++ b/client.go @@ -26,7 +26,7 @@ import ( const ( // Version is the current version of Elastic. - Version = "5.0.47" + Version = "5.0.48" // DefaultURL is the default endpoint of Elasticsearch on the local machine. // It is used e.g. when initializing a new Client without a specific URL. diff --git a/search_queries_match_phrase_prefix.go b/search_queries_match_phrase_prefix.go index 5a527c362..1eeba8af5 100644 --- a/search_queries_match_phrase_prefix.go +++ b/search_queries_match_phrase_prefix.go @@ -37,6 +37,12 @@ func (q *MatchPhrasePrefixQuery) Slop(slop int) *MatchPhrasePrefixQuery { return q } +// MaxExpansions sets the number of term expansions to use. +func (q *MatchPhrasePrefixQuery) MaxExpansions(n int) *MatchPhrasePrefixQuery { + q.maxExpansions = &n + return q +} + // Boost sets the boost to apply to this query. func (q *MatchPhrasePrefixQuery) Boost(boost float64) *MatchPhrasePrefixQuery { q.boost = &boost diff --git a/search_queries_match_phrase_prefix_test.go b/search_queries_match_phrase_prefix_test.go index 06f6a79ab..82a02f17d 100644 --- a/search_queries_match_phrase_prefix_test.go +++ b/search_queries_match_phrase_prefix_test.go @@ -10,7 +10,7 @@ import ( ) func TestMatchPhrasePrefixQuery(t *testing.T) { - q := NewMatchPhrasePrefixQuery("message", "this is a test").Boost(0.3) + q := NewMatchPhrasePrefixQuery("message", "this is a test").Boost(0.3).MaxExpansions(5) src, err := q.Source() if err != nil { t.Fatal(err) @@ -20,7 +20,7 @@ func TestMatchPhrasePrefixQuery(t *testing.T) { t.Fatalf("marshaling to JSON failed: %v", err) } got := string(data) - expected := `{"match_phrase_prefix":{"message":{"boost":0.3,"query":"this is a test"}}}` + expected := `{"match_phrase_prefix":{"message":{"boost":0.3,"max_expansions":5,"query":"this is a test"}}}` if got != expected { t.Errorf("expected\n%s\n,got:\n%s", expected, got) }