Search-Query Documentation

Search Query Logo

Build Status GitHub Release PyPI Version License

Search Query is a Python package designed to load, lint, translate, save, improve, and automate academic literature search queries. It is extensible and currently supports PubMed, EBSCOHost, and Web of Science. The package can be used programmatically, through the command line, or as a pre-commit hook. It has zero dependencies and integrates in a variety of environments. The parsers and linters are battle-tested on peer-reviewed searchRxiv queries.

Installation

To install search-query, run:

pip install search-query

Quickstart

Creating a query programmatically is simple:

from search_query import OrQuery, AndQuery

# Typical building-blocks approach
digital_synonyms = OrQuery(["digital", "virtual", "online"], search_field="abstract")
work_synonyms = OrQuery(["work", "labor", "service"], search_field="abstract")
query = AndQuery([digital_synonyms, work_synonyms])

We can also parse a query from a string or a JSON search file (see the overview of platform identifiers):

from search_query.parser import parse

query_string = '("digital health"[Title/Abstract]) AND ("privacy"[Title/Abstract])'
query = parse(query_string, platform="pubmed")

A useful feature of parsers is the built-in linter functionality, which helps us to validate the query by identifying syntactical errors:

 from search_query.parser import parse

 query_string = '("digital health"[Title/Abstract]) AND ("privacy"[Title/Abstract]'
 query = parse(query_string, platform="pubmed")
# Output:
# ❌ Fatal: unbalanced-parentheses (F1001)
#    Unbalanced opening parenthesis
#    ("digital health"[Title/Abstract]) AND ("privacy"[Title/Abstract]
#                                          ^^^

Once we have created a query object, we can translate it for different databases. Note how the syntax is translated and how the search for Title/Abstract is spit into two elements:

1from search_query.parser import parse
2
3query_string = '("digital health"[Title/Abstract]) AND ("privacy"[Title/Abstract])'
4query = parse(query_string, platform="pubmed")
5wos_query = query.translate(target_syntax="wos")
6print(wos_query.to_string())
7# Output:
8# ((AB="digital health" OR TI="digital health") AND (AB="privacy" OR TI="privacy"))

Demo

A Jupyter Notebook demo (hosted on Binder) is available here:

https://mybinder.org/badge_logo.svg

Functional Overview

The search-query package is built to support researchers throughout the entire lifecycle of academic search query management. Below is a high-level overview of the core functionalities:

_images/presentation.png