Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement placeholder search. Update tests #71

Merged
merged 1 commit into from
Aug 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion client_search.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ func (c clientSearch) Search(request SearchRequest) (*SearchResponse, error) {
request.Limit = 20
}

searchPostRequestParams["q"] = request.Query
if !request.PlaceholderSearch {
searchPostRequestParams["q"] = request.Query
}
if request.Filters != "" {
searchPostRequestParams["filters"] = request.Filters
}
Expand Down
46 changes: 46 additions & 0 deletions client_search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,36 @@ func TestClientSearch_Search(t *testing.T) {
t.Fatalf("Basic search: wrong number of hits, should have 3, got %d\n", resp.NbHits)
}

// Test basic empty search

resp, err = client.Search(indexUID).Search(SearchRequest{
Query: "",
})

if err != nil {
t.Fatal(err)
}

if len(resp.Hits) != 0 {
fmt.Println(resp)
t.Fatal("Basic search: empty search should return 0 results")
}

// Test basic placeholder search

resp, err = client.Search(indexUID).Search(SearchRequest{
PlaceholderSearch: true,
})

if err != nil {
t.Fatal(err)
}

if len(resp.Hits) != len(booksTest) {
fmt.Println(resp)
t.Fatal("Basic placeholder search: should return placeholder results")
}

// Test basic search with limit

resp, err = client.Search(indexUID).Search(SearchRequest{
Expand All @@ -81,6 +111,22 @@ func TestClientSearch_Search(t *testing.T) {
t.Fatalf("Basic search: should have found %s\n", booksTest[1].Title)
}

// Test basic placeholder search with limit

resp, err = client.Search(indexUID).Search(SearchRequest{
PlaceholderSearch: true,
Limit: 3,
})

if err != nil {
t.Fatal(err)
}

if len(resp.Hits) != 3 {
fmt.Println(resp)
t.Fatal("Basic placeholder search with limit: should return 3 results")
}

// Test basic search with offset

resp, err = client.Search(indexUID).Search(SearchRequest{
Expand Down
1 change: 1 addition & 0 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ type SearchRequest struct {
Matches bool
FacetsDistribution []string
FacetFilters interface{}
PlaceholderSearch bool
}

// SearchResponse is the response body for search method
Expand Down