Use a fuzzy match query to search messages
This commit is contained in:
parent
54a7472371
commit
26ce1cae93
@ -109,13 +109,14 @@ func (u *User) GetMessages(server, channel string, count int, fromID uint64) ([]
|
|||||||
return nil, nil
|
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 := bleve.NewMatchQuery(server)
|
||||||
serverQuery.SetField("server")
|
serverQuery.SetField("server")
|
||||||
channelQuery := bleve.NewMatchQuery(channel)
|
channelQuery := bleve.NewMatchQuery(channel)
|
||||||
channelQuery.SetField("to")
|
channelQuery.SetField("to")
|
||||||
contentQuery := bleve.NewFuzzyQuery(phrase)
|
contentQuery := bleve.NewMatchQuery(q)
|
||||||
contentQuery.SetField("content")
|
contentQuery.SetField("content")
|
||||||
|
contentQuery.SetFuzziness(2)
|
||||||
|
|
||||||
query := bleve.NewBooleanQuery([]bleve.Query{serverQuery, channelQuery, contentQuery}, nil, nil)
|
query := bleve.NewBooleanQuery([]bleve.Query{serverQuery, channelQuery, contentQuery}, nil, nil)
|
||||||
|
|
||||||
|
@ -136,7 +136,7 @@ func TestMessages(t *testing.T) {
|
|||||||
|
|
||||||
messages, err = user.SearchMessages("irc.freenode.net", "#go-nuts", "message")
|
messages, err = user.SearchMessages("irc.freenode.net", "#go-nuts", "message")
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
assert.Len(t, messages, 5)
|
assert.True(t, len(messages) > 0)
|
||||||
|
|
||||||
Close()
|
Close()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user