--- a/src/pyams_thesaurus/rpc/json/__init__.py Tue Jun 30 14:21:29 2015 +0200
+++ b/src/pyams_thesaurus/rpc/json/__init__.py Wed Jul 22 17:22:01 2015 +0200
@@ -17,7 +17,7 @@
# import interfaces
from pyams_thesaurus.interfaces.term import STATUS_ARCHIVED
-from pyams_thesaurus.interfaces.thesaurus import IThesaurus
+from pyams_thesaurus.interfaces.thesaurus import IThesaurus, IThesaurusExtracts
# import packages
from pyams_utils.list import unique
@@ -26,7 +26,29 @@
@jsonrpc_method(endpoint='thesaurus')
+def getExtracts(request, thesaurus_name):
+ """Get extracts of given thesaurus"""
+ thesaurus = query_utility(IThesaurus, name=thesaurus_name)
+ if thesaurus is None:
+ return []
+ extracts = IThesaurusExtracts(thesaurus)
+ return [{'id': extract.__name__,
+ 'text': extract.name} for extract in extracts.values()]
+
+
+@jsonrpc_method(endpoint='thesaurus')
+def getTopTerms(request, thesaurus_name, extract_name=None):
+ """Get top terms of given thesaurus"""
+ thesaurus = query_utility(IThesaurus, name=thesaurus_name)
+ if thesaurus is None:
+ return []
+ return ({'id': term.label,
+ 'text': term.label} for term in thesaurus.getTopTerms(extract_name))
+
+
+@jsonrpc_method(endpoint='thesaurus')
def findTerms(request, query, thesaurus_name, extract_name=None):
+ """Find terms matching given query, returning their title"""
thesaurus = query_utility(IThesaurus, name=thesaurus_name)
if thesaurus is None:
return []
@@ -39,6 +61,7 @@
@jsonrpc_method(endpoint='thesaurus')
def findTermsWithLabel(request, query, thesaurus_name, extract_name=None):
+ """Find terms matching given query, returning their full label"""
thesaurus = query_utility(IThesaurus, name=thesaurus_name)
if thesaurus is None:
return []