Learn R Programming

diezeit (version 0.1-0)

zeit_search: Search the ZEIT archive

Description

zeit_search exposes a search for ZEIT archive items. You can set search queries, paginate, sort and partially select the fields, that should be returned. Articles, that match your query, are returned with a reduced set of meta data.

Usage

zeit_search(endpoint, query, fields, limit = 10, offset = 0, sort, print = TRUE)

Arguments

endpoint
one of author, content, department, keyword, product or series -- provides specific search functionalities.
query
the main search query; single string value or vector of strings.
fields
partially select output fields, as string value or vector of strings for multiple fields.
limit
limit the amount of matches to return; set to 10 by default.
offset
offset for the list of matches; set to 0 by default.
sort
sort search results by any of the returned fields. Vector of two (c([field], [direction])), giving field and direction keyword. Direction keywords are asc and desc for an ascending or descending sort order respectively. Multiple sort orders are accepted as list of such vectors.
print
if TRUE (default) the search results are printed.

Value

A list of matches to the query.

Details

Endpoints

The API is structured into several endpoints that provide specific functionalities:

author
search all authors
content search for content
department
search all departments
keyword search all keywords
product
search all products

Query syntax

You can search the entire article text and all meta data simply by setting the query parameter to your search phrase. The search uses entire strings "as is". To search for multiple tokens use a vector of strings.

All fields of an article can be queried individually by using [field]:[search string]. For example, to get articles that have the word "Kennedy" in their headline, you would search for "title:Kennedy".

Currently all endpoints other than content only support simple search phrases with asterisk (*) wildcards.

Examples

Run this code
## Not run: 
# # simple content search
# zeit_search(endpoint="content", query="bayreuth")
# zeit_search("content", "bayreuth") # same same
# 
# # multiple tokens
# zeit_search("content", c("bayreuth", "festspiele"))
# 
# # entire string
# zeit_search("content", "bayreuther festspiele")
# 
# # field query
# zeit_search("content", "title:bayreuth")
# 
# # partial selection
# zeit_search("content", "bayreuth", fields=c("title", "teaser_text"))
# 
# # pagination
# zeit_search("content", "bayreuth", limit=1) # just one match
# zeit_search("content", "bayreuth", limit=1, offset=1) # just the second match
# 
# # sorting
# zeit_search("content", "bayreuth",
#   sort=c("release_date", "asc")) # sort by date
# zeit_search("content", "bayreuth",
#   sort=list(c("release_date", "desc"), c("title", "asc"))) # sort by date and title
# 
# # hide matches
# bt.matches <- zeit_search("content", "bayreuth", print=FALSE)
# 
# # author search
# zeit_search(endpoint="author", query="Stefan Locke")
# ## End(Not run)

Run the code above in your browser using DataLab