Skip to content

Commit

Permalink
Add PlaceholderSearch boolean to perform placehold search. Update tes…
Browse files Browse the repository at this point in the history
…ts (#71)
  • Loading branch information
eskombro authored Aug 3, 2020
1 parent dae07f7 commit 2cfaace
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 @@ -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

0 comments on commit 2cfaace

Please sign in to comment.