Skip to content

arXiv search query doesn't quote multi-word terms — spaces break field-qualified queries #94

Description

@FirmwareVersion

Bug

skills/sn-search-academic/scripts/arxiv_search.py build_search_query() builds arXiv queries like all:{query} without quoting multi-word strings, so spaces get treated as separate terms.

parts = [f"{field}:{query}"]  # query not quoted

Why this breaks

For a phrase like:

python arxiv_search.py "attention is all you need"

it currently generates:

all:attention is all you need

arXiv parses that as multiple terms, not a single phrase. The expected query is:

all:"attention is all you need"

Author field has the same problem: au:ho jonathan should be au:"ho jonathan".

Repro

>>> build_search_query("attention is all you need")
'all:attention is all you need'
# should be:
'all:"attention is all you need"'

Maybe Fix?

def _quote_if_multiword(term: str) -> str:
    return f'"{term}"' if " " in term else term

parts = [f"{field}:{_quote_if_multiword(query)}"]

author_terms = [
    f"au:{_quote_if_multiword(a.strip())}"
    for a in author.split(",") if a.strip()
]

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions