Use a fuzzy match query to search messages

This commit is contained in:
Ken-Håvard Lieng 2016-01-22 19:07:47 +01:00
parent 54a7472371
commit 26ce1cae93
2 changed files with 4 additions and 3 deletions

View File

@ -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)

View File

@ -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()
}