Skip to content

Commit

Permalink
Add PlaceholderSearch boolean to perform placehold search. Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
eskombro committed Jul 21, 2020
1 parent 298b2bc commit 624ec9a
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
4 changes: 3 additions & 1 deletion client_search.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ func (c clientSearch) Search(request SearchRequest) (*SearchResponse, error) {
request.Limit = 20
}

values.Add("q", request.Query)
if !request.PlaceholderSearch {
values.Add("q", request.Query)
}
if request.Filters != "" {
values.Add("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 @@ -127,6 +127,7 @@ type SearchRequest struct {
Matches bool
FacetsDistribution []string
FacetFilters interface{}
PlaceholderSearch bool
}

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

0 comments on commit 624ec9a

Please sign in to comment.