Skip to content

Commit ffe9fc4

Browse files
committed
Add SAM search helpers to the client API and document usage.
1 parent 245d64c commit ffe9fc4

5 files changed

Lines changed: 78 additions & 1 deletion

File tree

README.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
### hlquery C++ API Client
2020

21-
A C++ client library for hlquery with modular APIs, authentication support, HTTPS support, and type-safe responses.
21+
A C++ client library for hlquery with modular APIs, authentication support, HTTPS support, type-safe responses, and basic SAM search helpers.
2222

2323
### Installation
2424

@@ -221,6 +221,10 @@ nlohmann::json vector_body = {
221221
{"radius", 1.0}
222222
};
223223
auto advanced = client.executeRequest("POST", "/collections/collection/vector_search", vector_body);
224+
225+
// SAM search
226+
auto sam = client.samSearch("collection", "wireless keyboard");
227+
auto sam_all = client.samSearchAll("guide", {{"limit", "5"}});
224228
```
225229
226230
Preferred structure:
@@ -239,6 +243,15 @@ Compatibility note:
239243

240244
still exist for now, but they are compatibility shims. New code should prefer `client.collections()->...` for collection-scoped search operations.
241245

246+
### SAM Search
247+
248+
SAM search calls `/sam/search` directly and is useful for broader intent-style lookup.
249+
250+
```cpp
251+
auto sam = client.samSearch("products", "nineteen");
252+
auto sam_all = client.samSearchAll("benchmark", {{"distributed", "on"}, {"limit", "10"}});
253+
```
254+
242255
### Collections And Documents
243256
244257
```cpp

include/hlquery/client.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ class Client
7070
std::shared_ptr<Search> searchApi();
7171
[[deprecated("Use client.collections()->search(...) for collection-scoped searches.")]]
7272
Response search(const std::string& collection_name, const std::map<std::string, std::string>& params = {});
73+
Response samSearch(const std::string& collection_name, const std::string& query,
74+
const std::map<std::string, std::string>& params = {});
75+
Response samSearchAll(const std::string& query, const std::map<std::string, std::string>& params = {});
7376
[[deprecated("Use client.collections()->sql(...) for collection-scoped SQL searches.")]]
7477
Response sqlSearch(const std::string& collection_name, const std::string& sql,
7578
const std::map<std::string, std::string>& params = {});

include/hlquery/search.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ class Search
3232
Search(std::shared_ptr<Request> request, std::shared_ptr<Collections> collections);
3333

3434
Response search(const std::string& collection_name, const std::map<std::string, std::string>& params = {});
35+
Response samSearch(const std::string& collection_name, const std::string& query,
36+
const std::map<std::string, std::string>& params = {});
37+
Response samSearchAll(const std::string& query, const std::map<std::string, std::string>& params = {});
3538
Response sql(const std::string& collection_name, const std::string& sql,
3639
const std::map<std::string, std::string>& params = {});
3740
Response multiSearch(const std::vector<nlohmann::json>& searches);

src/client.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,17 @@ Response Client::search(const std::string& collection_name, const std::map<std::
161161
return collections_->search(collection_name, params);
162162
}
163163

164+
Response Client::samSearch(const std::string& collection_name, const std::string& query,
165+
const std::map<std::string, std::string>& params)
166+
{
167+
return search_->samSearch(collection_name, query, params);
168+
}
169+
170+
Response Client::samSearchAll(const std::string& query, const std::map<std::string, std::string>& params)
171+
{
172+
return search_->samSearchAll(query, params);
173+
}
174+
164175
Response Client::sqlSearch(const std::string& collection_name, const std::string& sql,
165176
const std::map<std::string, std::string>& params)
166177
{

src/search.cpp

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,53 @@ Response Search::search(const std::string& collection_name, const std::map<std::
9999
return request_->execute("GET", path);
100100
}
101101

102+
Response Search::samSearch(const std::string& collection_name, const std::string& query,
103+
const std::map<std::string, std::string>& params)
104+
{
105+
utils::validateCollectionName(collection_name);
106+
107+
if (query.empty())
108+
{
109+
throw std::invalid_argument("SAM query must be a non-empty string");
110+
}
111+
112+
std::map<std::string, std::string> query_params = params;
113+
query_params["collection"] = collection_name;
114+
query_params["q"] = query;
115+
116+
std::string path = "/sam/search";
117+
std::string query_string = buildQueryString(query_params);
118+
119+
if (!query_string.empty())
120+
{
121+
path += "?" + query_string;
122+
}
123+
124+
return request_->execute("GET", path);
125+
}
126+
127+
Response Search::samSearchAll(const std::string& query, const std::map<std::string, std::string>& params)
128+
{
129+
if (query.empty())
130+
{
131+
throw std::invalid_argument("SAM query must be a non-empty string");
132+
}
133+
134+
std::map<std::string, std::string> query_params = params;
135+
query_params["q"] = query;
136+
query_params["all"] = "true";
137+
138+
std::string path = "/sam/search";
139+
std::string query_string = buildQueryString(query_params);
140+
141+
if (!query_string.empty())
142+
{
143+
path += "?" + query_string;
144+
}
145+
146+
return request_->execute("GET", path);
147+
}
148+
102149
Response Search::sql(const std::string& collection_name, const std::string& sql,
103150
const std::map<std::string, std::string>& params)
104151
{

0 commit comments

Comments
 (0)