예제 #1
0
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
0
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)
		}
	}
}