Commit adcaf838 authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

Sphinx documentation for the InvenioStore class.

parent da1311a4
invenio_tools.inveniostore.InvenioStore
=======================================
.. currentmodule:: invenio_tools.inveniostore
.. autoclass:: InvenioStore
:show-inheritance:
.. rubric:: Methods
.. autosummary::
:toctree: inveniostore/
~InvenioStore.get_ids
~InvenioStore.get_record
~InvenioStore.interogate
~InvenioStore.last_search_url
~InvenioStore.search
~InvenioStore.search_year
invenio_tools.inveniostore.InvenioStore.get_ids
===============================================
.. currentmodule:: invenio_tools.inveniostore
.. automethod:: InvenioStore.get_ids
\ No newline at end of file
invenio_tools.inveniostore.InvenioStore.get_record
==================================================
.. currentmodule:: invenio_tools.inveniostore
.. automethod:: InvenioStore.get_record
\ No newline at end of file
invenio_tools.inveniostore.InvenioStore.interogate
==================================================
.. currentmodule:: invenio_tools.inveniostore
.. automethod:: InvenioStore.interogate
\ No newline at end of file
invenio_tools.inveniostore.InvenioStore.last_search_url
=======================================================
.. currentmodule:: invenio_tools.inveniostore
.. automethod:: InvenioStore.last_search_url
\ No newline at end of file
invenio_tools.inveniostore.InvenioStore.search
==============================================
.. currentmodule:: invenio_tools.inveniostore
.. automethod:: InvenioStore.search
\ No newline at end of file
invenio_tools.inveniostore.InvenioStore.search_year
===================================================
.. currentmodule:: invenio_tools.inveniostore
.. automethod:: InvenioStore.search_year
\ No newline at end of file
......@@ -45,4 +45,11 @@ Classes
.. autosummary::
:toctree: generated/
CheckAndFix
\ No newline at end of file
CheckAndFix
.. currentmodule:: invenio_tools.inveniostore
.. autosummary::
:toctree: generated/
InvenioStore
......@@ -30,19 +30,20 @@ REG_IDS_OK = re.compile("^\[[\d, ]*\]$")
class InvenioStore(object):
"""Class to dialogue with U{invenio<http://invenio-software.org/>} store.
"""Class to dialogue with `invenio <http://invenio-software.org/>`_ store.
In the dialogue:
The basic ingredients of the dialogue are:
- the request is an URL
- the response is an XML string which is compliant with the
U{MARC<http://www.loc.gov/marc/>} standard.
* the *request* which is an URL.
* the *response* which is an XML string compliant with the
`MARC <http://www.loc.gov/marc/>`_ standard.
"""
def __init__(self, host='cds.cern.ch'):
"""
@type host: str
@param host: domain name for the store
Args:
host (str): possible values are ``cds.cern.ch``
or ``inspirehep.net``.
"""
self._host = host
......@@ -50,16 +51,17 @@ class InvenioStore(object):
self._try = 0
def interogate(self, url):
"""Interrogate the store using the C{url}.
"""Interrogate the store using the *URL*.
@type url: unicode
@param url: URL string
Args:
url (unicode): URL string
@rtype: unicode
@return: the HTTP response
Returns:
unicode: the HTTP response
@raise CdsException: when the server return an HTTP error
five consecutive time.
Raises:
CdsException: when the server return an HTTP error
five consecutive time.
"""
self._url = url
......@@ -82,76 +84,64 @@ class InvenioStore(object):
return data
def get_ids(self, **kwargs):
"""Return a list of record C{id} for records matching search criteria.
"""Return a list of *record id* matching search criteria.
Search criteria are defined by the keywords arguments:
@type cc: str
@keyword cc: current collection (e.g. "ATLAS Papers").
The collection the user started to search/browse from.
Keyword Args:
cc (str): current collection (e.g. "ATLAS Papers").
The collection the user started to search/browse from.
@type p: str
@keyword p: pattern to search for (e.g. "ellis and muon or kaon").
p (str): pattern to search for (e.g. "ellis and muon or kaon").
@type f: str
@keyword f: field to search within (e.g. "author").
f (str): field to search within (e.g. "author").
@type p1: str
@keyword p1: first pattern to search for in the advanced search
interface. Much like C{p}.
p1 (str): first pattern to search for in the advanced search
interface. Much like **p**.
@type f1: str
@keyword f1: first field to search within in the advanced search
interface. Much like C{f}.
f1 (str): first field to search within in the advanced search
interface. Much like **f**.
@type m1: str
@keyword m1: first matching type in the advanced search interface.
("a" all of the words, "o" any of the words, "e" exact
phrase, "p" partial phrase, "r" regular expression).
m1 (str): first matching type in the advanced search interface.
("a" all of the words, "o" any of the words, "e" exact
phrase, "p" partial phrase, "r" regular expression).
@type op1: str
@keyword op1: first operator, to join the first and the second unit
in the advanced search interface. ("a" add, "o" or, "n" not).
op1 (str): first operator, to join the first and the second unit
in the advanced search interface. ("a" add, "o" or, "n" not).
@type p2: str
@keyword p2: second pattern to search for in the advanced search
interface. Much like C{p}.
p2 (str): second pattern to search for in the advanced search
interface. Much like **p**.
@type f2: str
@keyword f2: second field to search within in the advanced search
interface. Much like C{f}.
f2 (str): second field to search within in the advanced search
interface. Much like **f**.
@type m2: str
@keyword m2: second matching type in the advanced search interface.
("a" all of the words, "o" any of the words, "e" exact
phrase, "p" partial phrase, "r" regular expression).
m2 (str): second matching type in the advanced search interface.
("a" all of the words, "o" any of the words, "e" exact
phrase, "p" partial phrase, "r" regular expression).
@type op2: str
@keyword op2: second operator, to join the second and the third unit
in the advanced search interface. ("a" add, "o" or,"n" not).
op2 (str): second operator, to join the second and the third unit
in the advanced search interface. ("a" add, "o" or,"n" not).
@type p3: str
@keyword p3: third pattern to search for in the advanced search
interface. Much like C{p}.
p3 (str): third pattern to search for in the advanced search
interface. Much like **p**.
@type f3: str
@keyword f3: third field to search within in the advanced search
interface. Much like C{f}.
f3 (str): third field to search within in the advanced search
interface. Much like **f**.
@type m3: str
@keyword m3: third matching type in the advanced search interface.
("a" all of the words, "o" any of the words, "e" exact
phrase, "p" partial phrase, "r" regular expression).
m3 (str): third matching type in the advanced search interface.
("a" all of the words, "o" any of the words, "e" exact
phrase, "p" partial phrase, "r" regular expression).
The complete list of keyword arguments can be found at
U{http://invenio-demo.cern.ch/help/hacking/search-engine-api}.
http://invenio-demo.cern.ch/help/hacking/search-engine-api.
@rtype: list
@returns: a list of numbers.
The list is empty when the request failed on the server.
Returns:
list: a list of numbers.
The list is empty when the request failed on the server.
@raise CdsException: when a keyword argument is invalid or
when the server return an invalid list of ids.
Raises:
CdsException: when a keyword argument is invalid or
when the server return an invalid list of ids.
"""
for k in kwargs:
......@@ -196,17 +186,18 @@ class InvenioStore(object):
return ids
def get_record(self, rec_id):
"""Retrieve a record defined by its C{rec_id} in the invenio store.
"""Retrieve a record defined by its *record id*.
@type rec_id: int
@param rec_id:
Args:
rec_id (int): record identifier in the store.
@rtype: unicode
@return: the XML string is compliant with
the U{MARC<http://www.loc.gov/marc/>} standard.
Use L{Marc12.__call__} to decode it.
Returns:
unicode: the XML string is compliant with
the `MARC <http://www.loc.gov/marc/>`_ standard.
Use Marc12.__call__ to decode it.
@raise CdsException: when the server return an HTTP error.
Raises:
CdsException: when the server return an HTTP error.
"""
self._try = 0
......@@ -214,9 +205,9 @@ class InvenioStore(object):
return self.interogate(url)
def last_search_url(self):
"""Get the URL used in the last search.
@rtype: unicode
"""
Returns:
unicode: the URL used in the last search.
"""
return self._url
......@@ -224,222 +215,180 @@ class InvenioStore(object):
def search(self, **kwargs):
"""Return records matching the keyword arguments.
@type req: str
@keyword req: mod_python Request class instance.
@type cc: str
@keyword cc: current collection (e.g. "ATLAS").
The collection the user started to search/browse from.
@type c: str
@keyword c: collection list (e.g. ["Theses", "Books"]).
The collections user may have selected/deselected when
starting to search from C{cc}.
@type ec: str
@keyword ec: external collection list (e.g. ['CiteSeer', 'Google']).
The external collections may have been selected/deselected by the
user.
@type p: str
@keyword p: pattern to search for (e.g. "ellis and muon or kaon").
@type f: str
@keyword f: field to search within (e.g. "author").
@type rg: int
@keyword rg: records in groups of (e.g. "10").
Defines how many hits per collection in the search results page are
displayed.
@type sf: str
@keyword sf: sort field (e.g. "title").
@type so: str
@keyword so: sort order ("a"=ascending, "d"=descending).
@type sp: str
@keyword sp: sort pattern (e.g. "CERN-") -- in case there are more
values in a sort field, this argument tells which one to prefer
@type rm: str
@keyword rm: ranking method (e.g. "jif").
Defines whether results should be ranked by some known ranking method.
@type of: str
@keyword of: output format (e.g. "hb").
Usually starting "h" means HTML output (and "hb" for HTML brief,
"hd" for HTML detailed), "x" means XML output, "t" means plain text
output, "id" means no output at all but to return list of recIDs found.
(Suitable for high-level API.)
@type ot: str
@keyword ot: output only these MARC tags (e.g. "100,700,909C0b").
Useful if only some fields are to be shown in the
output, e.g. for library to control some fields.
@type as: int
@keyword as: advanced search ("0" means no, "1" means yes).
Whether search was called from within the advanced search
interface.
@type p1: str
@keyword p1: first pattern to search for in the advanced search
interface. Much like C{p}.
@type f1: str
@keyword f1: first field to search within in the advanced search
interface. Much like C{f}.
@type m1: str
@keyword m1: first matching type in the advanced search interface.
("a" all of the words, "o" any of the words, "e" exact phrase,
"p" partial phrase, "r" regular expression).
@type op1: str
@keyword op1: first operator, to join the first and the second unit
in the advanced search interface. ("a" add, "o" or, "n" not).
@type p2: str
@keyword p2: second pattern to search for in the advanced search
interface. Much like C{p}.
@type f2: str
@keyword f2: second field to search within in the advanced search
interface. Much like C{f}.
@type m2: str
@keyword m2: second matching type in the advanced search interface.
("a" all of the words, "o" any of the words, "e" exact phrase,
"p" partial phrase, "r" regular expression).
@type op2: str
@keyword op2: second operator, to join the second and the third unit
in the advanced search interface. ("a" add, "o" or, "n" not).
@type p3: str
@keyword p3: third pattern to search for in the advanced search
interface. Much like C{p}.
@type f3: str
@keyword f3: third field to search within in the advanced search
interface. Much like C{f}.
@type m3: str
@keyword m3: third matching type in the advanced search interface.
("a" all of the words, "o" any of the words, "e" exact phrase,
"p" partial phrase, "r" regular expression).
@type sc: int
@keyword sc: split by collection ("0" no, "1" yes).
Governs whether we want to present the results in a single huge list,
or splitted by collection.
@type jrec: int
@keyword jrec: jump to record (e.g. "234").
Used for navigation inside the search results.
@type recid: int
@keyword recid: display record ID (e.g. "20000").
Do not search/browse but go straight away to the Detailed
record page for the given recID.
@type recidb: int
@keyword recidb: display record ID bis (e.g. "20010").
If greater than 'recid', then display records from recid to recidb.
Useful for example for dumping records from the
database for reformatting.
@type sysno: str
@keyword sysno: display old system SYS number (e.g. "").
If you migrate to Invenio from another system, and store your
old SYS call numbers, you can use them instead of recid if you wish so.
@type id: int
@keyword id: the same as recid, in case recid is not set.
For backwards compatibility.
@type idb: int
@keyword idb: the same as recid, in case recidb is not set.
For backwards compatibility.
@type sysnb: str
@keyword sysnb: the same as sysno, in case sysno is not set.
For backwards compatibility.
@type action: str
@keyword action: action to do. "SEARCH" for searching,
"Browse" for browsing. Default is to search.
@type d1: str
@keyword d1: first datetime in full YYYY-mm-dd HH:MM:DD format
(e.g. "1998-08-23 12:34:56"). Useful for search limits
on creation/modification date (see 'dt' argument below).
Note that 'd1' takes precedence over d1y, d1m, d1d if these
are defined.
@type d1y: int
@keyword d1y: first date's year (e.g. "1998").
Useful for search limits on creation/modification date.
@type d1m: int
@keyword d1m: first date's month (e.g. "08").
Useful for search limits on creation/modification date.
@type d1d: int
@keyword d1d: first date's day (e.g. "23").
Useful for search limits on creation/modification date.
@type d2: str
@keyword d2: second datetime in full YYYY-mm-dd HH:MM:DD format
(e.g. "1998-09-02 12:34:56"). Useful for search limits
on creation/modification date (see 'dt' argument below).
Note that 'd2' takes precedence over d2y, d2m, d2d
if these are defined.
@type d2y: int
@keyword d2y: second date's year (e.g. "1998").
Useful for search limits on creation/modification date.
@type d2m: int
@keyword d2m: second date's month (e.g. "09").
Useful for search limits on creation/modification date.
@type d2d: int
@keyword d2d: second date's day (e.g. "02").
Useful for search limits on creation/modification date.
@type dt: str
@keyword dt: first and second date's type (e.g. "c").
Specifies whether to search in creation dates ("c") or in
modification dates ("m"). When dt is not set and d1*
and d2* are set, the default is "c".
@type verbose: int
@keyword verbose: verbose level (0=min, 9=max).
Useful to print some internal information on the searching process
in case something goes wrong.
@type ap: int
@keyword ap: alternative patterns (0=no, 1=yes).
In case no exact match is found, the search engine can try
alternative patterns e.g. to replace non-alphanumeric characters by
a boolean query. ap defines if this is wanted.
@type ln: str
@keyword ln: language of the search interface (e.g. "en").
Useful for internationalization.
Keyword Args:
req (str): mod_python Request class instance.
cc (str): current collection (*e.g.* "ATLAS").
The collection the user started to search/browse from.
c (str): collection list (*e.g.* ["Theses", "Books"]).
The collections user may have selected/deselected when
starting to search from **cc**.
ec (str): external collection list (*e.g.* ['CiteSeer', 'Google']).
The external collections may have been selected/deselected
by the user.
p (str): pattern to search for (*e.g.* "ellis and muon or kaon").
f (str): field to search within (*e.g.* "author").
rg (int): records in groups of (*e.g.* "10").
Defines how many hits per collection in the search results
page are displayed.
sf (str): sort field (*e.g*. "title").
so (str): sort order ("a"=ascending, "d"=descending).
sp (str): sort pattern (*e.g.* "CERN-") -- in case there are more
values in a sort field, this argument tells which one
to prefer.
rm (str): ranking method (*e.g.* "jif").
Defines whether results should be ranked by some known
ranking method.
of (str): output format (*e.g.* "hb").
Usually starting "h" means HTML output (and "hb" for HTML
brief, "hd" for HTML detailed), "x" means XML output,
"t" means plain text output, "id" means no output at all but to
return list of recIDs found. (Suitable for high-level API.).
ot (str): output only these MARC tags (*e.g.* "100,700,909C0b").
Useful if only some fields are to be shown in the
output, e.g. for library to control some fields.
as (int): advanced search ("0" means no, "1" means yes).
Whether search was called from within the advanced search
interface.
p1 (str): first pattern to search for in the advanced search
interface. Much like **p**.
f1 (str): first field to search within in the advanced search
interface. Much like **f**.
m1 (str): first matching type in the advanced search interface.
("a" all of the words, "o" any of the words, "e" exact phrase,
"p" partial phrase, "r" regular expression).
op1 (str): first operator, to join the first and the second unit
in the advanced search interface. ("a" add, "o" or, "n" not).
p2 (str): second pattern to search for in the advanced search
interface. Much like **p**.
f2 (str): second field to search within in the advanced search
interface. Much like **f**.
m2 (str): second matching type in the advanced search interface.
("a" all of the words, "o" any of the words, "e" exact phrase,
"p" partial phrase, "r" regular expression).
op2 (str): second operator, to join the second and the third unit
in the advanced search interface. ("a" add, "o" or, "n" not).
p3 (str): third pattern to search for in the advanced search
interface. Much like **p**.
f3 (str): third field to search within in the advanced search
interface. Much like **f**.
m3 (str): third matching type in the advanced search interface.
("a" all of the words, "o" any of the words, "e" exact phrase,
"p" partial phrase, "r" regular expression).
sc (int): split by collection ("0" no, "1" yes).
Governs whether we want to present the results in a single
huge list, or splitted by collection.
jrec (int): jump to record (*e.g.* "234").
Used for navigation inside the search results.
recid (int): display record ID (*e.g.* "20000").
Do not search/browse but go straight away to the Detailed
record page for the given recID.
recidb (int): display record ID bis (*e.g.* "20010").
If greater than 'recid', then display records from recid to
recidb. Useful for example for dumping records from the
database for reformatting.
sysno (str): display old system SYS number (*e.g.* "").
If you migrate to Invenio from another system, and store your
old SYS call numbers, you can use them instead of recid if you
wish so.
id (int): the same as recid, in case recid is not set.
For backwards compatibility.
idb (int): the same as recid, in case recidb is not set.
For backwards compatibility.
sysnb (str): the same as sysno, in case sysno is not set.
For backwards compatibility.
action (str): action to do. "SEARCH" for searching,
"Browse" for browsing. Default is to search.
d1 (str): first datetime in full YYYY-mm-dd HH:MM:DD format
(*e.g.* "1998-08-23 12:34:56"). Useful for search limits
on creation/modification date (see 'dt' argument below).
Note that 'd1' takes precedence over d1y, d1m, d1d if these
are defined.
d1y (int): first date's year (*e.g.* "1998").
Useful for search limits on creation/modification date.
d1m (int): first date's month (*e.g.* "08").
Useful for search limits on creation/modification date.