From 26ce1cae934abb05611c554122959b594196c0f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ken-H=C3=A5vard=20Lieng?= Date: Fri, 22 Jan 2016 19:07:47 +0100 Subject: [PATCH] Use a fuzzy match query to search messages --- storage/user_messages.go | 5 +++-- storage/user_test.go | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/storage/user_messages.go b/storage/user_messages.go index f2c4863d..6494750a 100644 --- a/storage/user_messages.go +++ b/storage/user_messages.go @@ -109,13 +109,14 @@ func (u *User) GetMessages(server, channel string, count int, fromID uint64) ([] return nil, nil } -func (u *User) SearchMessages(server, channel, phrase string) ([]Message, error) { +func (u *User) SearchMessages(server, channel, q string) ([]Message, error) { serverQuery := bleve.NewMatchQuery(server) serverQuery.SetField("server") channelQuery := bleve.NewMatchQuery(channel) channelQuery.SetField("to") - contentQuery := bleve.NewFuzzyQuery(phrase) + contentQuery := bleve.NewMatchQuery(q) contentQuery.SetField("content") + contentQuery.SetFuzziness(2) query := bleve.NewBooleanQuery([]bleve.Query{serverQuery, channelQuery, contentQuery}, nil, nil) diff --git a/storage/user_test.go b/storage/user_test.go index 114fd937..501ea150 100644 --- a/storage/user_test.go +++ b/storage/user_test.go @@ -136,7 +136,7 @@ func TestMessages(t *testing.T) { messages, err = user.SearchMessages("irc.freenode.net", "#go-nuts", "message") assert.Nil(t, err) - assert.Len(t, messages, 5) + assert.True(t, len(messages) > 0) Close() }