[open-ils-commits] r553 - constrictor/trunk/contrib/evergreen (erickson)
svn at svn.open-ils.org
svn at svn.open-ils.org
Tue Jun 30 22:46:27 EDT 2009
Author: erickson
Date: 2009-06-30 22:46:25 -0400 (Tue, 30 Jun 2009)
New Revision: 553
Added:
constrictor/trunk/contrib/evergreen/eg_bib_search.py
Modified:
constrictor/trunk/contrib/evergreen/eg_data.py
constrictor/trunk/contrib/evergreen/eg_tasks.py
Log:
added basic bib search script, which pulls random words from the dictionary and builds 1-3 word search phrases
Added: constrictor/trunk/contrib/evergreen/eg_bib_search.py
===================================================================
--- constrictor/trunk/contrib/evergreen/eg_bib_search.py (rev 0)
+++ constrictor/trunk/contrib/evergreen/eg_bib_search.py 2009-07-01 02:46:25 UTC (rev 553)
@@ -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())
+
+
+
Modified: constrictor/trunk/contrib/evergreen/eg_data.py
===================================================================
--- constrictor/trunk/contrib/evergreen/eg_data.py 2009-06-30 20:14:19 UTC (rev 552)
+++ constrictor/trunk/contrib/evergreen/eg_data.py 2009-07-01 02:46:25 UTC (rev 553)
@@ -68,7 +68,7 @@
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
Modified: constrictor/trunk/contrib/evergreen/eg_tasks.py
===================================================================
--- constrictor/trunk/contrib/evergreen/eg_tasks.py 2009-06-30 20:14:19 UTC (rev 552)
+++ constrictor/trunk/contrib/evergreen/eg_tasks.py 2009-07-01 02:46:25 UTC (rev 553)
@@ -151,3 +151,16 @@
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())
+
More information about the open-ils-commits
mailing list