pub struct SearchQuery { /* private fields */ }Expand description
Builder for constructing PubMed search queries
Implementations§
Source§impl SearchQuery
impl SearchQuery
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new search query builder
§Example
use pubmed_client::pubmed::SearchQuery;
let query = SearchQuery::new();Sourcepub async fn search(&self, client: &PubMedClient) -> Result<Vec<String>>
pub async fn search(&self, client: &PubMedClient) -> Result<Vec<String>>
Execute the search using the provided PubMed client
§Arguments
client- PubMed client to use for the search
§Returns
Returns a list of PMIDs matching the query
§Example
use pubmed_client::{PubMedClient, pubmed::SearchQuery};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = PubMedClient::new();
let pmids = SearchQuery::new()
.query("covid-19")
.limit(10)
.search(&client)
.await?;
println!("Found {} articles", pmids.len());
Ok(())
}Sourcepub async fn search_and_fetch(
&self,
client: &PubMedClient,
) -> Result<Vec<PubMedArticle>>
pub async fn search_and_fetch( &self, client: &PubMedClient, ) -> Result<Vec<PubMedArticle>>
Execute the search and fetch full article metadata
§Arguments
client- PubMed client to use for the search
§Returns
Returns a list of PubMed articles with metadata
§Example
use pubmed_client::{PubMedClient, pubmed::SearchQuery};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = PubMedClient::new();
let articles = SearchQuery::new()
.query("machine learning medicine")
.limit(5)
.search_and_fetch(&client)
.await?;
for article in articles {
println!("{}: {}", article.pmid, article.title);
}
Ok(())
}Sourcepub async fn search_with_details(
&self,
client: &PubMedClient,
) -> Result<SearchResult>
pub async fn search_with_details( &self, client: &PubMedClient, ) -> Result<SearchResult>
Execute the search and return detailed results including query translation
This method uses the NCBI history server and returns a SearchResult that includes
the query translation (how PubMed interpreted the query), total count, and session
information for paginated fetching.
§Arguments
client- PubMed client to use for the search
§Returns
Returns a SearchResult with PMIDs, total count, query translation, and history session
§Example
use pubmed_client::{PubMedClient, pubmed::SearchQuery};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = PubMedClient::new();
let result = SearchQuery::new()
.query("asthma")
.limit(10)
.search_with_details(&client)
.await?;
println!("Total: {}", result.total_count);
if let Some(translation) = &result.query_translation {
println!("PubMed interpreted query as: {}", translation);
}
Ok(())
}Source§impl SearchQuery
impl SearchQuery
Sourcepub fn mesh_major_topic<S: Into<String>>(self, mesh_term: S) -> Self
pub fn mesh_major_topic<S: Into<String>>(self, mesh_term: S) -> Self
Sourcepub fn mesh_terms<S: AsRef<str>>(self, mesh_terms: &[S]) -> Self
pub fn mesh_terms<S: AsRef<str>>(self, mesh_terms: &[S]) -> Self
Sourcepub fn mesh_subheading<S: Into<String>>(self, subheading: S) -> Self
pub fn mesh_subheading<S: Into<String>>(self, subheading: S) -> Self
Sourcepub fn affiliation<S: Into<String>>(self, institution: S) -> Self
pub fn affiliation<S: Into<String>>(self, institution: S) -> Self
Sourcepub fn organism_mesh<S: Into<String>>(self, organism: S) -> Self
pub fn organism_mesh<S: Into<String>>(self, organism: S) -> Self
Filter by organism using MeSH terms (scientific or common name)
§Arguments
organism- Organism name (scientific or common name)
§Examples
use pubmed_client::pubmed::SearchQuery;
// Using scientific name
let query = SearchQuery::new()
.query("gene expression")
.organism_mesh("Mus musculus");
// Using common name
let query = SearchQuery::new()
.query("metabolism")
.organism_mesh("Mice");
// Using bacteria
let query = SearchQuery::new()
.query("antibiotic resistance")
.organism_mesh("Escherichia coli");Sourcepub fn human_studies_only(self) -> Self
pub fn human_studies_only(self) -> Self
Filter to human studies only
§Example
use pubmed_client::pubmed::SearchQuery;
let query = SearchQuery::new()
.query("drug treatment")
.human_studies_only();Sourcepub fn animal_studies_only(self) -> Self
pub fn animal_studies_only(self) -> Self
Filter to animal studies only
§Example
use pubmed_client::pubmed::SearchQuery;
let query = SearchQuery::new()
.query("preclinical research")
.animal_studies_only();Source§impl SearchQuery
impl SearchQuery
Sourcepub fn and(self, other: SearchQuery) -> Self
pub fn and(self, other: SearchQuery) -> Self
Sourcepub fn or(self, other: SearchQuery) -> Self
pub fn or(self, other: SearchQuery) -> Self
Sourcepub fn negate(self) -> Self
pub fn negate(self) -> Self
Negate this query using NOT logic
§Example
use pubmed_client::pubmed::SearchQuery;
let query = SearchQuery::new()
.query("cancer")
.negate();Sourcepub fn exclude(self, excluded: SearchQuery) -> Self
pub fn exclude(self, excluded: SearchQuery) -> Self
Exclude articles matching the given query
§Arguments
excluded- SearchQuery representing articles to exclude
§Example
use pubmed_client::pubmed::SearchQuery;
let base_query = SearchQuery::new().query("cancer treatment");
let exclude_query = SearchQuery::new().query("animal studies");
let filtered = base_query.exclude(exclude_query);Source§impl SearchQuery
impl SearchQuery
Sourcepub fn date_range(self, start_year: u32, end_year: Option<u32>) -> Self
pub fn date_range(self, start_year: u32, end_year: Option<u32>) -> Self
Sourcepub fn published_between<S, E>(self, start: S, end: Option<E>) -> Self
pub fn published_between<S, E>(self, start: S, end: Option<E>) -> Self
Filter by publication date range with flexible precision
§Arguments
start- Start date (can be year, (year, month), or (year, month, day))end- End date (optional, same format as start)
§Examples
use pubmed_client::pubmed::SearchQuery;
// Year range
let query = SearchQuery::new()
.query("covid vaccines")
.published_between(2020, Some(2023));
// Month precision
let query = SearchQuery::new()
.query("pandemic response")
.published_between((2020, 3), Some((2021, 12)));
// Day precision
let query = SearchQuery::new()
.query("outbreak analysis")
.published_between((2020, 3, 15), Some((2020, 12, 31)));
// Open-ended (from date onwards)
let query = SearchQuery::new()
.query("recent research")
.published_between(2023, None::<u32>);Sourcepub fn published_in_year(self, year: u32) -> Self
pub fn published_in_year(self, year: u32) -> Self
Sourcepub fn entry_date_between<S, E>(self, start: S, end: Option<E>) -> Self
pub fn entry_date_between<S, E>(self, start: S, end: Option<E>) -> Self
Filter by entry date (when added to PubMed database)
§Arguments
start- Start date (can be year, (year, month), or (year, month, day))end- End date (optional, same format as start)
§Example
use pubmed_client::pubmed::SearchQuery;
let query = SearchQuery::new()
.query("recent discoveries")
.entry_date_between(2023, Some(2024));Sourcepub fn modification_date_between<S, E>(self, start: S, end: Option<E>) -> Self
pub fn modification_date_between<S, E>(self, start: S, end: Option<E>) -> Self
Filter by modification date (when last updated in PubMed database)
§Arguments
start- Start date (can be year, (year, month), or (year, month, day))end- End date (optional, same format as start)
§Example
use pubmed_client::pubmed::SearchQuery;
let query = SearchQuery::new()
.query("updated articles")
.modification_date_between(2023, None::<u32>);Sourcepub fn published_after<D>(self, date: D) -> Self
pub fn published_after<D>(self, date: D) -> Self
Filter to articles published after a specific date
§Arguments
date- Date after which articles were published (can be year, (year, month), or (year, month, day))
§Examples
use pubmed_client::pubmed::SearchQuery;
// After a specific year
let query = SearchQuery::new()
.query("crispr")
.published_after(2020);
// After a specific month
let query = SearchQuery::new()
.query("covid treatment")
.published_after((2020, 3));
// After a specific date
let query = SearchQuery::new()
.query("pandemic response")
.published_after((2020, 3, 15));Sourcepub fn published_before<D>(self, date: D) -> Self
pub fn published_before<D>(self, date: D) -> Self
Filter to articles published before a specific date
§Arguments
date- Date before which articles were published (can be year, (year, month), or (year, month, day))
§Examples
use pubmed_client::pubmed::SearchQuery;
// Before a specific year
let query = SearchQuery::new()
.query("genome sequencing")
.published_before(2020);
// Before a specific month
let query = SearchQuery::new()
.query("early research")
.published_before((2020, 3));
// Before a specific date
let query = SearchQuery::new()
.query("pre-pandemic studies")
.published_before((2020, 3, 15));Source§impl SearchQuery
impl SearchQuery
Sourcepub fn title_contains<S: Into<String>>(self, title: S) -> Self
pub fn title_contains<S: Into<String>>(self, title: S) -> Self
Sourcepub fn abstract_contains<S: Into<String>>(self, abstract_text: S) -> Self
pub fn abstract_contains<S: Into<String>>(self, abstract_text: S) -> Self
Sourcepub fn title_or_abstract<S: Into<String>>(self, text: S) -> Self
pub fn title_or_abstract<S: Into<String>>(self, text: S) -> Self
Sourcepub fn journal_abbreviation<S: Into<String>>(self, abbreviation: S) -> Self
pub fn journal_abbreviation<S: Into<String>>(self, abbreviation: S) -> Self
Sourcepub fn grant_number<S: Into<String>>(self, grant_number: S) -> Self
pub fn grant_number<S: Into<String>>(self, grant_number: S) -> Self
Sourcepub fn free_full_text_only(self) -> Self
pub fn free_full_text_only(self) -> Self
Filter to articles with free full text only
Includes PMC, Bookshelf, and publishers’ websites.
§Example
use pubmed_client::pubmed::SearchQuery;
let query = SearchQuery::new()
.query("cancer")
.free_full_text_only();Sourcepub fn full_text_only(self) -> Self
pub fn full_text_only(self) -> Self
Filter to articles with full text links (including subscription-based)
§Example
use pubmed_client::pubmed::SearchQuery;
let query = SearchQuery::new()
.query("machine learning")
.full_text_only();Sourcepub fn pmc_only(self) -> Self
pub fn pmc_only(self) -> Self
Filter to articles with PMC full text only
§Example
use pubmed_client::pubmed::SearchQuery;
let query = SearchQuery::new()
.query("diabetes")
.pmc_only();Sourcepub fn has_abstract(self) -> Self
pub fn has_abstract(self) -> Self
Filter to articles with abstracts
§Example
use pubmed_client::pubmed::SearchQuery;
let query = SearchQuery::new()
.query("genetics")
.has_abstract();Sourcepub fn article_types(self, types: &[ArticleType]) -> Self
pub fn article_types(self, types: &[ArticleType]) -> Self
Sourcepub fn article_type(self, article_type: ArticleType) -> Self
pub fn article_type(self, article_type: ArticleType) -> Self
Source§impl SearchQuery
impl SearchQuery
Sourcepub fn get_stats(&self) -> (usize, usize, usize)
pub fn get_stats(&self) -> (usize, usize, usize)
Get query statistics and information
§Returns
Returns a tuple of (term_count, filter_count, estimated_complexity)
§Example
use pubmed_client::pubmed::SearchQuery;
let query = SearchQuery::new()
.query("machine learning")
.published_after(2020)
.free_full_text_only();
let (terms, filters, complexity) = query.get_stats();Trait Implementations§
Source§impl Clone for SearchQuery
impl Clone for SearchQuery
Source§fn clone(&self) -> SearchQuery
fn clone(&self) -> SearchQuery
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more