Skip to content

Commit 61954ff

Browse files
authored
Merge pull request #15 from sonesuke/feature/add-language-filter-for-country
feat: add language filter for JP and CN country codes
2 parents cc24105 + 4d78afe commit 61954ff

2 files changed

Lines changed: 25 additions & 3 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/models.rs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,12 @@ impl SearchOptions {
112112

113113
if let Some(country) = &self.country {
114114
params.push(format!("country={}", country));
115+
// Add language filter for JP and CN
116+
match country.to_uppercase().as_str() {
117+
"JP" => params.push("language=JAPANESE".to_string()),
118+
"CN" => params.push("language=CHINESE".to_string()),
119+
_ => {}
120+
}
115121
}
116122

117123
if let Some(after) = &self.after_date {
@@ -193,13 +199,29 @@ mod tests {
193199
"https://patents.google.com/?q=foo&assignee=\"Google+LLC\""
194200
);
195201

196-
// Test query with country
202+
// Test query with country (JP should add language=JAPANESE)
197203
let options = SearchOptions {
198204
query: Some("foo".to_string()),
199205
country: Some("JP".to_string()),
200206
..Default::default()
201207
};
202-
assert_eq!(options.to_url().unwrap(), "https://patents.google.com/?q=foo&country=JP");
208+
assert_eq!(options.to_url().unwrap(), "https://patents.google.com/?q=foo&country=JP&language=JAPANESE");
209+
210+
// Test query with country (CN should add language=CHINESE)
211+
let options = SearchOptions {
212+
query: Some("foo".to_string()),
213+
country: Some("CN".to_string()),
214+
..Default::default()
215+
};
216+
assert_eq!(options.to_url().unwrap(), "https://patents.google.com/?q=foo&country=CN&language=CHINESE");
217+
218+
// Test query with country (US should NOT add language)
219+
let options = SearchOptions {
220+
query: Some("foo".to_string()),
221+
country: Some("US".to_string()),
222+
..Default::default()
223+
};
224+
assert_eq!(options.to_url().unwrap(), "https://patents.google.com/?q=foo&country=US");
203225

204226
// Test query with dates
205227
let options = SearchOptions {

0 commit comments

Comments
 (0)