Skip to content

Commit

Permalink
Add MaxExpansions method in MatchPhrasePrefixQuery
Browse files Browse the repository at this point in the history
Close #615
  • Loading branch information
olivere committed Sep 26, 2017
1 parent 575dcf5 commit 2a08d39
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 6 additions & 0 deletions search_queries_match_phrase_prefix.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions search_queries_match_phrase_prefix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
}
Expand Down

0 comments on commit 2a08d39

Please sign in to comment.