本文整理汇总了Golang中github.com/anchepiece/suggest.Suggest.Query方法的典型用法代码示例。如果您正苦于以下问题:Golang Suggest.Query方法的具体用法?Golang Suggest.Query怎么用?Golang Suggest.Query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/anchepiece/suggest.Suggest
的用法示例。
在下文中一共展示了Suggest.Query方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: simpleExample3
func simpleExample3() {
// make sure our example in doc.go works
suggester := suggest.Suggest{}
suggester.Options.SimilarityMinimum = 7
suggester.Options.AutocorrectDisabled = false
query := "proflie"
commands := []string{"perfil", "profiel", "profile", "profil", "account"}
suggester.Commands = commands
if result, err := suggester.Query(query); err == nil {
if !result.Success() {
fmt.Println("No close matches")
} else {
fmt.Println("Similar matches:", result.Matches) // [profile profil profiel]
fmt.Println("Autocorrect:", result.Autocorrect) // profile
}
}
os.Exit(0)
}
示例2: TestQueryMatchOrder
func TestQueryMatchOrder(t *testing.T) {
s := suggest.Suggest{}
for _, tt := range queryTests {
query := tt.query
s.Commands = tt.commands
result, err := s.Query(query)
actual := result.Matches
if err != nil {
t.Errorf("TestQueryMatchOrder(%v) returned error %v", tt.query, err)
continue
}
if !reflect.DeepEqual(actual, tt.expected) {
t.Errorf("TestQueryMatchOrder(%q, %v) = %q, want %q", tt.query, tt.commands, actual, tt.expected)
}
}
}