From: erickson Date: Wed, 1 Jul 2009 02:46:25 +0000 (+0000) Subject: added basic bib search script, which pulls random words from the dictionary and build... X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=5bf3b76ba828831d00be10579c4f2e3c58a80763;p=working%2Frandom.git added basic bib search script, which pulls random words from the dictionary and builds 1-3 word search phrases git-svn-id: svn://svn.open-ils.org/ILS-Contrib/constrictor/trunk@553 6d9bc8c9-1ec2-4278-b937-99fde70a366f --- diff --git a/contrib/evergreen/eg_bib_search.py b/contrib/evergreen/eg_bib_search.py new file mode 100644 index 000000000..6db0490a9 --- /dev/null +++ b/contrib/evergreen/eg_bib_search.py @@ -0,0 +1,45 @@ +from constrictor.task import Task +from constrictor.script import Script, ScriptManager, ScriptThread +from constrictor.log import * +import eg_utils, eg_data, eg_tasks +import random + +eg_utils.init() +words_file = open('/usr/share/dict/words') # add config property +words = words_file.readlines() +words_file.close() + +class BibSearchScript(Script): + + def run(self): + + dm = eg_data.DataManager() + org_id = dm.getThreadData(eg_data.PROP_ORG_IDS) or 1 + + search_args = { + 'org_unit' : org_id, + 'depth' : 0, + # randomly add many more optional flags + } + + word_count = int( (random.random() * 3) % 3) + 1 # search phrase has 1-4 words + search_term = '' + + for i in range(0, word_count): + word = words[ int(random.random() * len(words)) ] + search_term += '%s ' % word[0:len(word)-1] + + logInfo('Search term="%s" args="%s"' % (search_term, str(search_args))) + + res = eg_tasks.TASKS['BibSearchTask'].run( + search_args = search_args, + search_term = search_term + ) + + logInfo('Search returned %d hits' % int(res['count'])) + return True + +ScriptManager.go(BibSearchScript()) + + + diff --git a/contrib/evergreen/eg_data.py b/contrib/evergreen/eg_data.py index d1d0de9ad..bb7770f25 100644 --- a/contrib/evergreen/eg_data.py +++ b/contrib/evergreen/eg_data.py @@ -68,7 +68,7 @@ class DataManager(object): case an exception is raised. For atomic data, the value is returned and no thread data is checked ''' - data = self.data[prop] + data = self.data.get(prop) if not isinstance(data, list): return data diff --git a/contrib/evergreen/eg_tasks.py b/contrib/evergreen/eg_tasks.py index 3bc6a94e9..7579df158 100644 --- a/contrib/evergreen/eg_tasks.py +++ b/contrib/evergreen/eg_tasks.py @@ -151,3 +151,16 @@ class TitleHoldFetchAllTask(AbstractMethodTask): return self.runMethod(eg_utils.authtoken(), kw['patron_id']) registerTask(TitleHoldFetchAllTask()) + +class BibSearchTask(AbstractMethodTask): + + def __init__(self): + AbstractMethodTask.__init__(self) + self.service = OILS_APP_SEARCH + self.method = 'open-ils.search.biblio.multiclass.query' + + def run(self, **kw): + return self.runMethod(kw['search_args'], kw['search_term'], True) + +registerTask(BibSearchTask()) +