Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions redisearch/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ const (
// Fetch document payloads as well as fields. See documentation for payloads on redisearch.io
QueryWithPayloads Flag = 0x10

// The query will not filter stopwords
QueryWithStopWords Flag = 0x20

// ... more to come!

DefaultOffset = 0
Expand Down Expand Up @@ -146,6 +149,9 @@ func (q Query) serialize() redis.Args {
args = args.Add("SLOP", *q.Slop)
}

if q.Flags&QueryWithStopWords != 0 {
args = args.Add("NOSTOPWORDS")
}
if q.Flags&QueryInOrder != 0 {
args = args.Add("INORDER")
}
Expand Down
1 change: 1 addition & 0 deletions redisearch/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ func TestQuery_serialize(t *testing.T) {
{"QueryInOrder", fields{Raw: raw, Flags: QueryInOrder}, redis.Args{raw, "LIMIT", 0, 0, "INORDER"}},
{"QueryWithPayloads", fields{Raw: raw, Flags: QueryWithPayloads}, redis.Args{raw, "LIMIT", 0, 0, "WITHPAYLOADS"}},
{"QueryWithScores", fields{Raw: raw, Flags: QueryWithScores}, redis.Args{raw, "LIMIT", 0, 0, "WITHSCORES"}},
{"QueryWithStopWords", fields{Raw: raw, Flags: QueryWithStopWords}, redis.Args{raw, "LIMIT", 0, 0, "NOSTOPWORDS"}},
{"InKeys", fields{Raw: raw, InKeys: []string{"test_key"}}, redis.Args{raw, "LIMIT", 0, 0, "INKEYS", 1, "test_key"}},
{"InFields", fields{Raw: raw, InFields: []string{"test_key"}}, redis.Args{raw, "LIMIT", 0, 0, "INFIELDS", 1, "test_key"}},
{"ReturnFields", fields{Raw: raw, ReturnFields: []string{"test_field"}}, redis.Args{raw, "LIMIT", 0, 0, "RETURN", 1, "test_field"}},
Expand Down
31 changes: 27 additions & 4 deletions redisearch/redisearch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,14 +200,14 @@ func TestNoIndex(t *testing.T) {
assert.Nil(t, err)
assert.Equal(t, 0, total)

_, total, err = c.Search(NewQuery("@f2:Mark*"))
_, total, _ = c.Search(NewQuery("@f2:Mark*"))
assert.Equal(t, 2, total)

docs, total, err := c.Search(NewQuery("@f2:Mark*").SetSortBy("f1", false))
docs, total, _ := c.Search(NewQuery("@f2:Mark*").SetSortBy("f1", false))
assert.Equal(t, 2, total)
assert.Equal(t, "TestNoIndex-doc1", docs[0].Id)

docs, total, err = c.Search(NewQuery("@f2:Mark*").SetSortBy("f1", true))
docs, total, _ = c.Search(NewQuery("@f2:Mark*").SetSortBy("f1", true))
assert.Equal(t, 2, total)
assert.Equal(t, "TestNoIndex-doc2", docs[0].Id)
teardown(c)
Expand Down Expand Up @@ -439,7 +439,7 @@ func TestFilter(t *testing.T) {
assert.Equal(t, 1, total)
assert.Equal(t, "18", docs[0].Properties["age"])

docs, total, err = c.Search(NewQuery("hello world").
_, total, err = c.Search(NewQuery("hello world").
AddFilter(Filter{Field: "location", Options: GeoFilterOptions{Lon: 10, Lat: 13, Radius: 1, Unit: KILOMETERS}}).
SetSortBy("age", true).
SetReturnFields("body"))
Expand Down Expand Up @@ -511,6 +511,29 @@ func TestReturnFields(t *testing.T) {
assert.Equal(t, "25", docs[0].Properties["years"])
}

func TestNoStopWords(t *testing.T) {
c := createClient("testung")

sc := NewSchema(DefaultOptions).
AddField(NewTextField("title"))
c.Drop()

err := c.CreateIndex(sc)
assert.Nil(t, err)

vanillaConnection := c.pool.Get()
_, err = vanillaConnection.Do("HSET", "doc1", "title", "hello world")
assert.Nil(t, err)

// Searching
_, total, err := c.Search(NewQuery("hello a world").SetFlags((QueryNoContent)))
assert.Nil(t, err)
assert.Equal(t, 1, total)
_, total, err = c.Search(NewQuery("hello a world").SetFlags((QueryNoContent | QueryWithStopWords)))
assert.Nil(t, err)
assert.Equal(t, 0, total)
}

func TestParams(t *testing.T) {
c := createClient("TestParams")
version, _ := c.getRediSearchVersion()
Expand Down