ss_tools/tutorials/step_3.rs
1//! # Step 3 - Build QueryParams
2//!
3//! This tutorial covers how to build query parameters for API requests.
4//!
5//! ## QueryParams Overview
6//!
7//! [`QueryParams`](crate::QueryParams) is used to configure API requests.
8//! It uses the builder pattern for easy configuration.
9//!
10//! ```rust
11//! use ss_tools::QueryParams;
12//!
13//! let mut params = QueryParams::default();
14//! params
15//! .paper_id("abc123")
16//! .query_text("deep learning")
17//! .limit(10);
18//! ```
19//!
20//! ## Paper Query Parameters
21//!
22//! ### Basic Search
23//!
24//! ```rust
25//! use ss_tools::QueryParams;
26//! use ss_tools::structs::PaperField;
27//!
28//! let mut params = QueryParams::default();
29//! params
30//! .query_text("transformer architecture")
31//! .fields(vec![
32//! PaperField::Title,
33//! PaperField::Abstract,
34//! PaperField::Year,
35//! ])
36//! .limit(20);
37//! ```
38//!
39//! ### Paper Details by ID
40//!
41//! ```rust
42//! use ss_tools::QueryParams;
43//! use ss_tools::structs::PaperField;
44//!
45//! let mut params = QueryParams::default();
46//! params
47//! .paper_id("204e3073870fae3d05bcbc2f6a8e263d9b72e776")
48//! .fields(vec![
49//! PaperField::Title,
50//! PaperField::CitationCount,
51//! PaperField::ReferenceCount,
52//! PaperField::ExternalIds,
53//! ]);
54//! ```
55//!
56//! ### Filtering Papers
57//!
58//! ```rust
59//! use ss_tools::QueryParams;
60//! use ss_tools::structs::{PublicationTypes, FieldsOfStudy};
61//!
62//! let mut params = QueryParams::default();
63//! params
64//! .query_text("machine learning")
65//! .publication_types(vec![PublicationTypes::JournalArticle])
66//! .fields_of_study(vec![FieldsOfStudy::ComputerScience])
67//! .min_citation_count(100)
68//! .year("2020-2024")
69//! .open_access_pdf(true);
70//! ```
71//!
72//! ## Author Query Parameters
73//!
74//! ### Author Details by ID
75//!
76//! For author APIs, the author ID is passed via the `paper_id` field.
77//!
78//! ```rust
79//! use ss_tools::QueryParams;
80//! use ss_tools::structs::AuthorField;
81//!
82//! let mut params = QueryParams::default();
83//! params
84//! .paper_id("1741101") // author_id
85//! .author_fields(vec![
86//! AuthorField::Name,
87//! AuthorField::PaperCount,
88//! AuthorField::CitationCount,
89//! AuthorField::HIndex,
90//! ]);
91//! ```
92//!
93//! ### Author Search by Name
94//!
95//! ```rust
96//! use ss_tools::QueryParams;
97//! use ss_tools::structs::AuthorField;
98//!
99//! let mut params = QueryParams::default();
100//! params
101//! .query_text("Yann LeCun")
102//! .author_fields(vec![
103//! AuthorField::Name,
104//! AuthorField::Affiliations,
105//! AuthorField::PaperCount,
106//! ]);
107//! ```
108//!
109//! ### Author's Papers
110//!
111//! ```rust
112//! use ss_tools::QueryParams;
113//! use ss_tools::structs::PaperField;
114//!
115//! let mut params = QueryParams::default();
116//! params
117//! .paper_id("1741101") // author_id
118//! .fields(vec![
119//! PaperField::Title,
120//! PaperField::Year,
121//! PaperField::CitationCount,
122//! ])
123//! .limit(10)
124//! .offset(0);
125//! ```
126//!
127//! ## Pagination Parameters
128//!
129//! Use `offset` and `limit` for pagination:
130//!
131//! ```rust
132//! use ss_tools::QueryParams;
133//!
134//! let mut params = QueryParams::default();
135//! params
136//! .query_text("neural network")
137//! .offset(0) // Start from first result
138//! .limit(50); // Get 50 results
139//! ```
140//!
141//! ## Available Builder Methods
142//!
143//! | Method | Description |
144//! |--------|-------------|
145//! | `paper_id(id)` | Set paper ID or author ID |
146//! | `query_text(text)` | Set search query text |
147//! | `fields(fields)` | Set paper fields to retrieve |
148//! | `author_fields(fields)` | Set author fields to retrieve |
149//! | `publication_types(types)` | Filter by publication types |
150//! | `fields_of_study(fields)` | Filter by fields of study |
151//! | `min_citation_count(count)` | Minimum citation count |
152//! | `year(range)` | Year or year range (e.g., "2020-2024") |
153//! | `open_access_pdf(bool)` | Filter for open access papers |
154//! | `offset(n)` | Pagination offset |
155//! | `limit(n)` | Maximum results |
156//! | `sort(field)` | Sort order |