Skip to content

Session

bmckinney edited this page Mar 1, 2017 · 1 revision

Session Model

Search and Retrieve Methods


add_actions(actions)

Add actions to an existing search session.

results = session.add_actions('addfacetfilter(SubjectGeographic:massachusetts)')

add_query(query)

Add a query to the search request. When a query is added, it will be assigned an ordinal, which will be exposed in the search response message. It also removes any specified facet filters and sets the page number to 1.

results = session.add_query('AND,California')

clear_queries()

Clears all queries and facet filters, and set the page number back to 1; limiters and expanders are not modified.

clear_search()

Clear all specified query expressions, facet filters, limiters and expanders, and set the page number back to 1.

end()

Invalidates the session token. End Session should be called when you know a user has logged out.

remove_query(query_id)

Removes query from the currently specified search. It also removes any specified facet filters and sets the page number to 1.

results = session.remove_query(1)

retrieve(dbid:, an:, highlight: nil, ebook: 'ebook-pdf')

Returns a Record based a particular result based on a database ID and accession number.

Attributes:

  • :dbid - The database ID (required).
  • :an - The accession number (required).
  • :highlight - Comma separated list of terms to highlight in the data records (optional).
  • :ebook - Preferred format to return ebook content in. Either ebook-pdf (default) or ebook-pdf.
record = session.retrieve({dbid: 'asn', an: '108974507'})

search(options = {}, add_actions = false)

Performs a search.

Options:

  • :query - Required. The search terms. Format: {booleanOperator},{fieldCode}:{term}. Example: SU:Hiking
  • :mode - Search mode to be used. Either: all (default), any, bool, smart
  • :results_per_page - The number of records retrieved with the search results (between 1-100, default is 20).
  • :page - Starting page number for the result set returned from a search (if results per page = 10, and page number = 3 , this implies: I am expecting 10 records starting at page 3).
  • :sort - The sort order for the search results. Either: relevance (default), oldest, newest
  • :highlight - Specifies whether or not the search term is highlighted using tags. Either true or false.
  • :include_facets - Specifies whether or not the search term is highlighted using tags. Either true (default) or false.
  • :facet_filters - Facets to apply to the search. Facets are used to refine previous search results. Format: {filterID},{facetID}:{value}[,{facetID}:{value}]* Example: 1,SubjectEDS:food,SubjectEDS:fiction
  • :view - Specifies the amount of data to return with the response. Either 'title': title only; 'brief' (default): Title + Source, Subjects; 'detailed': Brief + full abstract
  • :actions - Actions to take on the existing query specification. Example: addfacetfilter(SubjectGeographic:massachusetts)
  • :limiters - Criteria to limit the search results by. Example: LA99:English,French,German
  • :expanders - Expanders that can be applied to the search. Either: thesaurus, fulltext, relatedsubjects
  • :publication_id - Publication to search within.
  • :related_content - Comma separated list of related content types to return with the search results. Either 'rs' (Research Starters) or 'emp' (Exact Publication Match)
  • :auto_suggest - Specifies whether or not to return search suggestions along with the search results. Either true or false (default).
results = session.search({query: 'abraham lincoln', results_per_page: 5, related_content: ['rs','emp']})
results = session.search({query: 'volcano', results_per_page: 1, publication_id: 'eric', include_facets: false})

simple_search(query)

Performs a simple search. All other search options assume default values.

Attributes:

  • query - the search query.
results = session.simple_search('volcanoes') 

Getting Auto-Suggest Terms

If you turn on auto_suggest, you can retrieve auto-suggest or "did you mean" terms in this way:

results = session.search({query: 'string thery', auto_suggest: true})
results.did_you_mean
 => "string theory"

Setter Methods


Use these methods to apply new configuration settings to an existing search.

include_related_content(val)

A related content type to additionally search for and include with the search results.

results = session.include_related_content('rs')

results_per_page(num)

Sets the page size on the search request.

results = session.results_per_page(50)

set_highlight(val)

Sets whether or not to turn highlighting on or off (y|n).

results = session.set_highlight('n')

set_include_facets(val)

Specify to include facets in the results or not. Either 'y' or 'n'.

results = session.set_include_facets('n')

set_search_mode(mode)

Sets the search mode. The available search modes are returned from the info method.

results = session.set_search_mode('bool')

set_sort(val)

Sets the sort for the search. The available sorts for the specified databases can be obtained from the session’s info attribute. Sets the page number back to 1.

results = session.set_sort('newest')

set_view(view)

Specifies the view parameter. The view representes the amount of data to return with the search.

results = session.set_view('detailed')

Publication Methods


add_publication(pub_id)

Specifies a publication to search within. Sets the pages number back to 1.

results = session.add_publication('eric')

remove_all_publications()

Removes all publications from the search. Sets the page number back to 1.

remove_publication(pub_id)

Removes a publication from the search. Sets the page number back to 1.

results = session.remove_publication('eric')

Profile Query Methods


dbid_in_profile(dbid)

Determine if a database ID is available in the profile. Returns Boolean.

get_available_database_ids()

Get a list of all available database IDs. Returns Array of IDs.

session.get_available_database_ids
 => ["nlebk", "e000xna", "edsart", "e700xna", "cat02060a", "ers", "asn"] 

publication_match_in_profile()

Determine if publication matching is available in the profile. Returns Boolean.

research_starters_match_in_profile()

Determine if research starters are available in the profile. Returns Boolean.

Pagination Methods


get_page(page = 1)

Get a specified page of results Returns search Results.

move_page(num)

Increments the current results page number by the value specified. If the current page was 5 and the specified value was 2, the page number would be set to 7.

next_page()

Get the next page of results.

prev_page()

Get the previous page of results.

reset_page()

Get the first page of results.

Limiter Methods


add_limiter(id, val)

Adds a limiter to the currently defined search and sets the page number back to 1.

results = session.add_limiter('FT','y')

clear_limiters()

Clears all currently specified limiters and sets the page number back to 1.

remove_limiter(id)

Removes the specified limiter and sets the page number back to 1.

results = session.remove_limiter('FT')

remove_limiter_value(id, val)

Removes a specified limiter value and sets the page number back to 1.

results = session.remove_limiter_value('LA99','French')

Facet Methods


add_facet(facet_id, facet_val)

Adds a facet filter to the search request. Sets the page number back to 1.

results = session.add_facet('Publisher', 'wiley-blackwell')
results = session.add_facet('SubjectEDS', 'water quality')

clear_facets()

Removes all specified facet filters. Sets the page number back to 1.

remove_facet(group_id)

Removes a specified facet filter id. Sets the page number back to 1.

results = session.remove_facet(45)

remove_facet_value(group_id, facet_id, facet_val)

Removes a specific facet filter value from a group. Sets the page number back to 1.

results = session.remove_facet_value(2, 'DE', 'Psychology')

Expander Methods


add_expander(val)

Adds expanders and sets the page number back to 1. Multiple expanders should be comma separated.

results = session.add_expander('thesaurus,fulltext')

clear_expanders()

Removes all specified expanders and sets the page number back to 1.

remove_expander(val)

Removes a specified expander. Sets the page number to 1.

results = session.remove_expander('fulltext')