-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpackage.json
24 lines (24 loc) · 11.1 KB
/
package.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
{
"name": "nyt-article-search",
"version": "1.0.0",
"description": "Use the Article Search API to look up articles by keyword. You can refine your search using filters and facets. ``` /articlesearch.json?q={query}&fq={filter} ``` ## Example Call ``` https://api.nytimes.com/svc/search/v2/articlesearch.json?q=election&api-key=yourkey ``` ## FILTERING YOUR SEARCH Use filters to narrow the scope of your search. You can specify the fields and the values that your query will be filtered on. The Article Search API uses [Elasticsearch](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-simple-query-string-query.html#simple-query-string-syntax), so the filter query (fq) uses standard [Lucene syntax](http://www.lucenetutorial.com/lucene-query-syntax.html). Separate the filter field name and value with a colon, and surround multiple values with parentheses. ``` field-name:( value1 , value2 , ... value n ) ``` The default connector for values in parentheses is OR. If you declare an explicit boolean value, it must be capitalized. You can filter on multiple values and fields. ``` field-name-1:( value1 ) AND field-name-2:( value2 , value3 ) ``` For a list of all fields you can filter on, see the Filter Query Fields table below. You can also filter by search text. ### Pagination The Article Search API returns a max of 10 results at a time. The meta node in the response contains the total number of matches ( hits ) and the current offset. Use the page query parameter to paginate thru results (page=0 for results 1-10, page=1 for 11-20, ...). You can paginate thru up to 100 pages (1,000 results). If you get too many results try filtering by date range. ### Filter Query Examples Restrict your search to articles with The New York Times as the source: ``` fq=source:( The New York Times ) ``` Restrict your search to articles from either the Sports or Foreign desk: ``` fq=news_desk:( Sports , Foreign ) ``` Restrict your search to articles that are about New York City and from the Sports desk: ``` fq=news_desk:( Sports ) AND glocations:( NEW YORK CITY ) ``` If you do not specify a field, the scope of the filter query will look for matches in the body, headline and byline. The example below will restrict your search to articles with The New York Times in the body, headline or byline: ``` fq=The New York Times ``` Find articles with the word Pokemon that were on the print paper's front page. ``` fq=Pokemon AND print_page:1 AND (print_section:( A , 1 ) OR (!_exists_:print_section)) ``` ### Filter Query Fields Field | Behavior ------------------------- | --------------- body | Multiple tokens body.search | Left-edge n-grams creative_works | Single token creative_works.contains | Multiple tokens day_of_week | Single token document_type | Case-sensitive exact match glocations | Single token glocations.contains | Multiple tokens headline | Multiple tokens headline.search | Left-edge n-grams kicker | Single token kicker.contains | Multiple tokens news_desk | Single token news_desk.contains | Multiple tokens organizations | Single token organizations.contains | Multiple tokens persons | Single token persons.contains | Multiple tokens pub_date | Timestamp (YYYY-MM-DD) pub_year | Integer secpg | Multiple tokens source | Single token source.contains | Multiple tokens subject | Single token subject.contains | Multiple tokens section_name | Single token section_name.contains | Multiple tokens type_of_material | Single token type_of_material.contains | Multiple tokens web_url | Single token (case-sensitive) word_count | Integer #### News Desk Values * Adventure Sports * Arts & Leisure * Arts * Automobiles * Blogs * Books * Booming * Business Day * Business * Cars * Circuits * Classifieds * Connecticut * Crosswords & Games * Culture * DealBook * Dining * Editorial * Education * Energy * Entrepreneurs * Environment * Escapes * Fashion & Style * Fashion * Favorites * Financial * Flight * Food * Foreign * Generations * Giving * Global Home * Health & Fitness * Health * Home & Garden * Home * Jobs * Key * Letters * Long Island * Magazine * Market Place * Media * Men's Health * Metro * Metropolitan * Movies * Museums * National * Nesting * Obits * Obituaries * Obituary * OpEd * Opinion * Outlook * Personal Investing * Personal Tech * Play * Politics * Regionals * Retail * Retirement * Science * Small Business * Society * Sports * Style * Sunday Business * Sunday Review * Sunday Styles * T Magazine * T Style * Technology * Teens * Television * The Arts * The Business of Green * The City Desk * The City * The Marathon * The Millennium * The Natural World * The Upshot * The Weekend * The Year in Pictures * Theater * Then & Now * Thursday Styles * Times Topics * Travel * U.S. * Universal * Upshot * UrbanEye * Vacation * Washington * Wealth * Weather * Week in Review * Week * Weekend * Westchester * Wireless Living * Women's Health * Working * Workplace * World * Your Money #### Section Name Values * Arts * Automobiles * Autos * Blogs * Books * Booming * Business * Business Day * Corrections * Crosswords & Games * Crosswords/Games * Dining & Wine * Dining and Wine * Editors' Notes * Education * Fashion & Style * Food * Front Page * Giving * Global Home * Great Homes & Destinations * Great Homes and Destinations * Health * Home & Garden * Home and Garden * International Home * Job Market * Learning * Magazine * Movies * Multimedia * Multimedia/Photos * N.Y. / Region * N.Y./Region * NYRegion * NYT Now * National * New York * New York and Region * Obituaries * Olympics * Open * Opinion * Paid Death Notices * Public Editor * Real Estate * Science * Sports * Style * Sunday Magazine * Sunday Review * T Magazine * T:Style * Technology * The Public Editor * The Upshot * Theater * Times Topics * TimesMachine * Today's Headlines * Topics * Travel * U.S. * Universal * UrbanEye * Washington * Week in Review * World * Your Money #### Type of Material Values * Addendum * An Analysis * An Appraisal * Archives * Article * Banner * Biography * Birth Notice * Blog * Brief * Caption * Chronology * Column * Correction * Economic Analysis * Editorial * Editorial Cartoon * Editors' Note * First Chapter * Front Page * Glossary * Interactive Feature * Interactive Graphic * Interview * Letter * List * Marriage Announcement * Military Analysis * News * News Analysis * Newsletter * Obituary * Obituary (Obit) * Op-Ed * Paid Death Notice * Postscript * Premium * Question * Quote * Recipe * Review * Schedule * SectionFront * Series * Slideshow * Special Report * Statistics * Summary * Text * Video * Web Log ## USING FACETS Use facets to view the relative importance of certain fields to a search term, and gain insight about how to best refine your queries and filter your search results. The following fields can be used as facet fields: day_of_week, document_type, ingredients, news_desk, pub_month, pub_year, section_name, source, subsection_name, and type_of_material. Specify facets using the facet_fields parameter. Set facet=true and the response will contain an array with a count for the five terms that have the highest count for each facet. For example, including the following in your request will add a facet array with a count for the top five days of the week to the response. ``` facet_fields=day_of_week&facet=true ``` By default, facet counts ignore all filters and return the count for all results of a query. For the following queries, the facet count in each response will be identical, even though the results returned in one set is restricted to articles published in 2012. ``` q=obama&facet_fields=source&facet=true&begin_date=20120101&end_date=20121231 ``` You can force facet counts to respect filters by setting facet_filter=true. Facet counts will be restricted based on any filters you have specified (this includes both explicit filter queries set using the fq parameter and implicit filters like begin_date). Here is the facet array response to the query. ```javascript facets : { source : { _type : terms , missing : 524, total : 83121, other : 317, terms : [ { term : The New York Times , count : 68530 }, { term : AP , count : 7705 }, { term : Reuters , count : 4969 }, { term : International Herald Tribune , count : 1464 }, { term : , count : 136 } ] } } ``` If you set facet_filter to true the facet array will only count facet occurences in 2012. ```javascript facets : { source : { _type : terms , missing : 192, total : 22596, other : 139, terms : [ { term : The New York Times , count : 14812 }, ... ``` ### Examples Requests Search for documents containing 'new york times' and return results 20-29 with results sorted oldest first. ``` https://api.nytimes.com/svc/search/v2/articlesearch.json?q=new+york+times&page=2&sort=oldest&api-key=your-api-key ``` Search for all documents published on January 1, 2012 containing 'romney'. Facet count will be returned for 'day_of_week' and will be reflective of all documents (i.e., the date range filter and filter query do not affect facet counts). ``` https://api.nytimes.com/svc/search/v2/articlesearch.json?fq=romney&facet_field=day_of_week&facet=true&begin_date=20120101&end_date=20120101&api-key=your-api-key ``` ### Example Response Here is an partial example response. ```javascript { response : { meta : { hits : 25, time : 332, offset : 0 }, docs : [ { web_url : http://thecaucus.blogs.nytimes.com/2012/01/01/virginia-attorney-general-backs-off-ballot-proposal/ , snippet : Virginia's attorney general on Sunday backed off of a proposal to loosen the state's ballot access rules to allow more Republican presidential candidates to qualify. , lead_paragraph : DES MOINES -- Virginia's attorney general on Sunday backed off of a proposal to loosen the state's ballot access rules to allow more Republican presidential candidates to qualify. , ... } ], facets : { day_of_week : { _type : terms , missing : 1871790, total : 13098462, other : 3005891, terms : [ { term : Sunday , count : 3122347 }, ... ``` ### Limit Fields in Response You can limit the number fields returned in the response with the fl parameter. ``` fl=web_url ``` ",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"build": "tsc"
},
"keywords": [
"typescript",
"sdk",
"api",
"client"
],
"author": "LibLab",
"license": "",
"devDependencies": {
"typescript": "5.3.3"
},
"dependencies": {
"zod": "3.22.0"
}
}