Skip to content

Commit 873a3f5

Browse files
authored
add query param (#8)
1 parent 7eea937 commit 873a3f5

File tree

2 files changed

+153
-1
lines changed

2 files changed

+153
-1
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ apply plugin: 'java'
22
apply plugin: 'maven-publish'
33

44
group = 'com.github.outscraper'
5-
version = '2.1.3'
5+
version = '2.1.4'
66

77
repositories {
88
mavenCentral()

examples/Businesses.md

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
# Businesses Search With Java
2+
3+
Search businesses using the `/businesses` endpoint.
4+
5+
This endpoint supports:
6+
- **Structured JSON parameters** (`filters`, `fields`, etc.)
7+
- **AI-powered plain text query** via the `query` parameter
8+
- **Both together** (server merges both inputs)
9+
10+
When both `parameters` and `query` are provided:
11+
- `filters` and `fields` are merged
12+
- for `limit`, `cursor`, and `include_total`, plain text values have priority (if explicitly specified)
13+
- if not specified anywhere, default API values are used
14+
15+
## Installation
16+
17+
Java 11 or later.
18+
19+
### Gradle
20+
21+
Edit your `build.gradle` file:
22+
23+
```sh
24+
repositories {
25+
maven { url "https://jitpack.io" }
26+
}
27+
28+
dependencies {
29+
implementation 'com.github.outscraper:outscraper-java:v2.1.0'
30+
}
31+
```
32+
33+
### Maven
34+
35+
Add the JitPack repository to your build file:
36+
37+
```sh
38+
<repositories>
39+
<repository>
40+
<id>jitpack.io</id>
41+
<url>https://jitpack.io</url>
42+
</repository>
43+
</repositories>
44+
```
45+
46+
Add the dependency:
47+
48+
```sh
49+
<dependency>
50+
<groupId>com.github.outscraper</groupId>
51+
<artifactId>outscraper-java</artifactId>
52+
<version>v2.1.0</version>
53+
</dependency>
54+
```
55+
56+
### Others
57+
58+
You'll need to manually install the following JARs:
59+
- [The Outscraper JAR](https://jitpack.io/com/github/outscraper/outscraper-java/v2.1.0/outscraper-java-v2.1.0.jar)
60+
- [Json](https://repo1.maven.org/maven2/org/json/json/20090211/json-20090211.jar)
61+
- [Httpcomponents](https://repo1.maven.org/maven2/org/apache/httpcomponents/httpclient/4.5.13/httpclient-4.5.13.jar)
62+
- [Guava](https://repo1.maven.org/maven2/com/google/guava/guava/30.1.1-jre/guava-30.1.1-jre.jar)
63+
64+
## Initialization
65+
66+
```java
67+
OutscraperClient client = new OutscraperClient("SECRET_API_KEY");
68+
```
69+
70+
[Link to the profile page to create the API key](https://app.outscraper.com/profile)
71+
72+
## Usage
73+
74+
### 1) Search with structured parameters (JSON)
75+
76+
```java
77+
HashMap<String, Object> params = new HashMap<>();
78+
79+
HashMap<String, Object> filters = new HashMap<>();
80+
filters.put("country_code", "US");
81+
filters.put("states", new String[] {"NY"});
82+
filters.put("cities", new String[] {"New York", "Buffalo"});
83+
filters.put("types", new String[] {"restaurant", "cafe"});
84+
filters.put("has_website", true);
85+
filters.put("has_phone", true);
86+
filters.put("business_statuses", new String[] {"operational"});
87+
88+
params.put("filters", filters);
89+
params.put("limit", 50);
90+
params.put("include_total", false);
91+
params.put("fields", new String[] {"name", "phone", "website", "address", "rating", "reviews"});
92+
93+
JSONObject page = client.businessesSearch(params);
94+
System.out.println(page);
95+
```
96+
97+
### 2) AI-powered search (plain text)
98+
99+
```java
100+
String query =
101+
"Find restaurants and cafes in California and Illinois with rating 4.2+ and status operational. " +
102+
"Return fields name, address, rating and reviews. " +
103+
"Limit results to 15.";
104+
105+
JSONObject page = client.businessesSearch(new HashMap<>(), query);
106+
System.out.println(page);
107+
```
108+
109+
### 3) Combine JSON + plain text (merge rules)
110+
111+
```java
112+
HashMap<String, Object> params = new HashMap<>();
113+
114+
HashMap<String, Object> filters = new HashMap<>();
115+
filters.put("country_code", "US");
116+
filters.put("states", new String[] {"CA"});
117+
filters.put("types", new String[] {"restaurant"});
118+
119+
params.put("filters", filters);
120+
params.put("fields", new String[] {"name", "phone"});
121+
params.put("limit", 15);
122+
123+
String query =
124+
"Add cafes too. " +
125+
"Return address and reviews. " +
126+
"Limit 20. " +
127+
"Include total.";
128+
129+
JSONObject page = client.businessesSearch(params, query);
130+
System.out.println(page);
131+
132+
// Result behavior:
133+
// - filters merged (restaurant + cafe, plus JSON filters)
134+
// - fields merged (name, phone, address, reviews, ...)
135+
// - limit/include_total taken from plain text when present
136+
```
137+
138+
### 4) Iterate over all results (auto-pagination)
139+
140+
```java
141+
HashMap<String, Object> params = new HashMap<>();
142+
HashMap<String, Object> filters = new HashMap<>();
143+
filters.put("country_code", "US");
144+
filters.put("states", new String[] {"NY"});
145+
filters.put("business_statuses", new String[] {"operational"});
146+
147+
params.put("filters", filters);
148+
params.put("limit", 100);
149+
150+
JSONArray all = client.businessesIterSearch(params);
151+
System.out.println(all.length());
152+
```

0 commit comments

Comments
 (0)