Skip to content

Commit a05fd72

Browse files
authored
add query param (#36)
* add query param * changed docstring
1 parent 5ed080c commit a05fd72

File tree

3 files changed

+70
-14
lines changed

3 files changed

+70
-14
lines changed

examples/Businesses.md

Lines changed: 64 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -88,21 +88,21 @@ json = {
8888
'include_total': False,
8989
'fields': ['name', 'types', 'address', 'state', 'postal_code', 'country', 'website', 'phone', 'rating', 'reviews', 'photo'],
9090
'filters': {
91-
"country_code": "US",
92-
"states": [
93-
"NY"
91+
'country_code': 'US',
92+
'states': [
93+
'NY'
9494
],
95-
"cities": [
96-
"New York",
97-
"Buffalo"
95+
'cities': [
96+
'New York',
97+
'Buffalo'
9898
],
99-
"types": [
100-
"restaurant",
101-
"cafe"
99+
'types': [
100+
'restaurant',
101+
'cafe'
102102
],
103-
"has_website": True,
104-
"has_phone": True,
105-
"business_statuses": ["operational"],
103+
'has_website': True,
104+
'has_phone': True,
105+
'business_statuses': ['operational'],
106106
}
107107
}
108108
result = client.businesses.search(**json)
@@ -119,4 +119,56 @@ for business in client.businesses.iter_search(
119119
):
120120
# business is a Business dataclass instance
121121
print(business)
122+
123+
```
124+
125+
---
126+
127+
## 🚀 AI-Powered Natural Language Search
128+
129+
> [!IMPORTANT]
130+
> **Use plain English to search businesses.**
131+
>
132+
> You can now pass a `query` string, and AI will automatically convert it into structured `filters`, `fields`, and other search parameters.
133+
134+
### AI-Powered Search (Plain Text)
135+
136+
```python
137+
# Describe your request in plain English using the query parameter.
138+
result = client.businesses.search(
139+
query=(
140+
'Find restaurants and cafes in California and Illinois with rating 4.2+ and status operational. Return fields name, address, rating and reviews. Limit results to 15.'
141+
)
142+
)
143+
144+
for business in result.items:
145+
print(business.name, business.rating)
146+
```
147+
148+
### Combine JSON + Plain Text (Merge Rules)
149+
150+
When you pass both `filters`/`fields` and `query`:
151+
152+
- `filters` are merged
153+
- `fields` are merged
154+
- `limit`, `cursor`, and `include_total` come from plain text first (if present)
155+
156+
```python
157+
result = client.businesses.search(
158+
filters={
159+
'country_code': 'US',
160+
'states': ['CA'],
161+
'types': ['restaurant']
162+
},
163+
fields=['name', 'phone'],
164+
limit=15,
165+
query=(
166+
'Add cafes too. Return address and reviews. Limit 20. Include total.'
167+
),
168+
)
169+
170+
# Result behavior:
171+
# - filters merged (types include restaurant + cafe, plus other JSON filters)
172+
# - fields merged (name, phone, address, reviews, ...)
173+
# - limit=20 and include_total=True are taken from plain text
122174
```

outscraper/businesses.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def __init__(self, client: OutscraperClient) -> None:
1212
self._client = client
1313

1414
def search(self, *, filters: FiltersLike = None, limit: int = 10, cursor: Optional[str] = None, include_total: bool = False,
15-
fields: Optional[list[str]] = None) -> BusinessSearchResult:
15+
fields: Optional[list[str]] = None, query: str = '') -> BusinessSearchResult:
1616
'''
1717
Retrieve business records with optional enrichment data.
1818
@@ -30,6 +30,7 @@ def search(self, *, filters: FiltersLike = None, limit: int = 10, cursor: Option
3030
include_total (bool): Whether to include the total count of matching records in the response. This could increase response time.
3131
Default: False.
3232
fields (list[str] | None): List of fields to include in the response. If not specified, all fields will be returned.
33+
query (str): natural language search.
3334
3435
Returns:
3536
BusinessSearchResult: Page of businesses with pagination info.
@@ -56,6 +57,9 @@ def search(self, *, filters: FiltersLike = None, limit: int = 10, cursor: Option
5657
if fields:
5758
payload['fields'] = list(fields)
5859

60+
if query:
61+
payload['query'] = query
62+
5963
response = self._client._request('POST', '/businesses', use_handle_response=False, json=payload)
6064
data = response.json()
6165

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ def readme():
88

99
setup(
1010
name='outscraper',
11-
version='6.0.1',
11+
version='6.0.2',
1212
description='Python bindings for the Outscraper API',
1313
long_description=readme(),
1414
classifiers = ['Programming Language :: Python',

0 commit comments

Comments
 (0)