HomeGuidesRecipesAPI EndpointsRelease NotesCommunity
Log In

Paragraph Search

The ParagraphApi allows you to search for and parse data at the paragraph level. In this guide, we will go over some of the properties you can use to filter your paragraph search. A full listing of the accepted properties can be found on the search for paragraphs reference page.

Setting Up

Make sure you have already followed the instructions for importing dependencies and authentication from the Getting Started Guide. Once you have completed that, instantiate the ParagraphApi as shown below.

paragraphs = layar_api.ParagraphApi(client)

👍

Check Your References

Make sure you have imported the layar_api and built out your client object before instantiating the ParagraphApi. If you need help setting these up check out Installing the Layar API and Configure Your Instance in our Getting Started Guide

Unlike the document search, the paragraph search accepts its parameters directly in the search method itself. Start by setting up your result definition.

result = paragraphs.paragraph_get()

Setting Your Filters

The filters you use in the paragraph_get method will be inserted directly into the method itself. However, for organization's sake, we recommend defining them in separate variables first.

Filter By Query

The ParagraphApi makes it easy to find relevant paragraphs across all your documents with a simple query search. The query is saved as a string which can then be added to the q parameter in your search method.

query = "my query string"
result = paragraphs.paragraph_get(q=query)

Filter By Document IDs

You may want to return all the paragraphs in a collection of documents or a specific document. This can be done with the document_ids parameter which accepts a list of document IDs as strings.

documents = ['document_1', 'document_2']
result = paragraphs.paragraph_get(document_ids=documents)

Filter By Dates

You can return all paragraphs that were created within a specific time range by using the from_date and to_date parameters. Dates should be formatted as YYYY-MM-DD.

from_date = '2021-06-15'
to_date = '2022-06-15'
result = paragraphs.paragraph_get(from_date=from_date, to_date=to_date)

Highlight Query Results

Not a filter, but very useful when searching for paragraphs is the ability to highlight the found query text within the returned paragraphs. This is a simple boolean flag called highlight which accepts a true or false value.

result = paragraphs.paragraph_get(highlight=true)

Using Multiple Filters

Using multiple filters is achieved by simply adding all the filters you need, separated by commas. For example, if you wanted to find all paragraphs that mention tachycardia and were published between May and September of 2021, you could get those results and highlight all the mentions of tachycardia by making the following request.

query = 'tachycardia'
from_date = '2021-05-01'
to_date = '2021-09-30'

result = paragraphs.paragraph_get(q=query, from_date=from_date, to_date=to_date, highlight=true)
# Check results (optional)
pprint(result)