Filter stop words when searching posts in mysql (#14509)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
2055c49dfe
Коммит
6a50106cd9
@@ -4,6 +4,7 @@
|
||||
package sqlstore
|
||||
|
||||
import (
|
||||
"github.com/stretchr/testify/require"
|
||||
"testing"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v5/store/searchtest"
|
||||
@@ -17,3 +18,47 @@ func TestPostStore(t *testing.T) {
|
||||
func TestSearchPostStore(t *testing.T) {
|
||||
StoreTestWithSearchTestEngine(t, searchtest.TestSearchPostStore)
|
||||
}
|
||||
|
||||
func TestMysqlStopWords(t *testing.T) {
|
||||
mysqlStopWordsTests := []struct {
|
||||
Name string
|
||||
Args []string
|
||||
Expected []string
|
||||
Empty bool
|
||||
}{
|
||||
{
|
||||
Name: "Should remove only the stop words",
|
||||
Args: []string{"where is my car", "so this is real", "test this-and-that is awesome"},
|
||||
Expected: []string{"my car", "so real", "test this-and-that awesome"},
|
||||
},
|
||||
{
|
||||
Name: "Should not remove part of a word containg stop words",
|
||||
Args: []string{"whereabouts", "wherein", "tothis", "thisorthat", "waswhen", "whowas", "inthe", "whowill", "thewww"},
|
||||
Expected: []string{"whereabouts", "wherein", "tothis", "thisorthat", "waswhen", "whowas", "inthe", "whowill", "thewww"},
|
||||
},
|
||||
{
|
||||
Name: "Should remove all words from terms",
|
||||
Args: []string{"where about", "where in", "to this", "this or that", "was when", "who was", "in the", "who will", "the www"},
|
||||
Empty: true,
|
||||
},
|
||||
{
|
||||
Name: "Should not remove part of a word containg stop words separated by hyphens",
|
||||
Args: []string{"where-about", "where-in", "to-this", "this-or-that", "was-when", "who-was", "in-the", "who-will", "the-www"},
|
||||
Expected: []string{"where-about", "where-in", "to-this", "this-or-that", "was-when", "who-was", "in-the", "who-will", "the-www"},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range mysqlStopWordsTests {
|
||||
t.Run(tc.Name, func(t *testing.T) {
|
||||
for i, term := range tc.Args {
|
||||
got, err := removeMysqlStopWordsFromTerms(term)
|
||||
require.NoError(t, err)
|
||||
if tc.Empty {
|
||||
require.Empty(t, got)
|
||||
} else {
|
||||
require.Equal(t, tc.Expected[i], got)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user