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//! ]);
53//! ```
54//!
55//! ### Filtering Papers
56//!
57//! ```rust
58//! use ss_tools::QueryParams;
59//! use ss_tools::structs::{PublicationTypes, FieldsOfStudy};
60//!
61//! let mut params = QueryParams::default();
62//! params
63//! .query_text("machine learning")
64//! .publication_types(vec![PublicationTypes::JournalArticle])
65//! .fields_of_study(vec![FieldsOfStudy::ComputerScience])
66//! .min_citation_count(100)
67//! .year("2020-2024")
68//! .open_access_pdf(true);
69//! ```
70//!
71//! ## Author Query Parameters
72//!
73//! ### Author Details by ID
74//!
75//! For author APIs, the author ID is passed via the `paper_id` field.
76//!
77//! ```rust
78//! use ss_tools::QueryParams;
79//! use ss_tools::structs::AuthorField;
80//!
81//! let mut params = QueryParams::default();
82//! params
83//! .paper_id("1741101") // author_id
84//! .author_fields(vec![
85//! AuthorField::Name,
86//! AuthorField::PaperCount,
87//! AuthorField::CitationCount,
88//! AuthorField::HIndex,
89//! ]);
90//! ```
91//!
92//! ### Author Search by Name
93//!
94//! ```rust
95//! use ss_tools::QueryParams;
96//! use ss_tools::structs::AuthorField;
97//!
98//! let mut params = QueryParams::default();
99//! params
100//! .query_text("Yann LeCun")
101//! .author_fields(vec![
102//! AuthorField::Name,
103//! AuthorField::Affiliations,
104//! AuthorField::PaperCount,
105//! ]);
106//! ```
107//!
108//! ### Author's Papers
109//!
110//! ```rust
111//! use ss_tools::QueryParams;
112//! use ss_tools::structs::PaperField;
113//!
114//! let mut params = QueryParams::default();
115//! params
116//! .paper_id("1741101") // author_id
117//! .fields(vec![
118//! PaperField::Title,
119//! PaperField::Year,
120//! PaperField::CitationCount,
121//! ])
122//! .limit(10)
123//! .offset(0);
124//! ```
125//!
126//! ## Pagination Parameters
127//!
128//! Use `offset` and `limit` for pagination:
129//!
130//! ```rust
131//! use ss_tools::QueryParams;
132//!
133//! let mut params = QueryParams::default();
134//! params
135//! .query_text("neural network")
136//! .offset(0) // Start from first result
137//! .limit(50); // Get 50 results
138//! ```
139//!
140//! ## Available Builder Methods
141//!
142//! | Method | Description |
143//! |--------|-------------|
144//! | `paper_id(id)` | Set paper ID or author ID |
145//! | `query_text(text)` | Set search query text |
146//! | `fields(fields)` | Set paper fields to retrieve |
147//! | `author_fields(fields)` | Set author fields to retrieve |
148//! | `publication_types(types)` | Filter by publication types |
149//! | `fields_of_study(fields)` | Filter by fields of study |
150//! | `min_citation_count(count)` | Minimum citation count |
151//! | `year(range)` | Year or year range (e.g., "2020-2024") |
152//! | `open_access_pdf(bool)` | Filter for open access papers |
153//! | `offset(n)` | Pagination offset |
154//! | `limit(n)` | Maximum results |
155//! | `sort(field)` | Sort order |