Commit 1743ca72 authored by Bartek Górny's avatar Bartek Górny

2006-08-03 BG

Nice display of search results (with highlights from SearchableText); searchable text for Spreadsheet.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@9040 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 347b4ccf
class Done(Exception):
pass
class Word(str):pass
class FoundWord(str):
def __str__(self):
return self.tags[0]+self+self.tags[1]
class Part:
def __init__(self,tags,trail):
self.chain=[]
self.limit=trail
self.trail=trail
self.has=False
self.tags=tags
def push(self,w):
self.chain.insert(0,Word(w))
if len(self.chain)>self.limit:
if self.has:
self.chain.reverse()
raise Done()
self.chain.pop()
def add(self,w):
#import pdb
#pdb.set_trace()
self.chain.insert(0,FoundWord(w))
self.limit+=self.trail+1
self.has=True
def __str__(self):
return '...%s...' % ' '.join(map(str,self.chain))
def generateParts(context,text,sw,tags,trail,maxlines):
par=Part(tags,trail)
test=lambda w:w.strip().replace('"','').replace("'","") in sw
i=0
for aw in text:
if i==maxlines:
raise StopIteration
if test(aw):
par.add(aw)
else:
try:
par.push(aw)
except Done:
i+=1
yield par
par=Part(tags,trail)
def cutFound(context,txt,sw,tags,trail,maxlines):
FoundWord.tags=tags
text = txt.split(' ') # very rough tokenization
return [p for p in generateParts(context,text,sw,tags,trail,maxlines)]
if __name__=='__main__':
sw='pricing priority right acting proportion'
txt=' '.join([l.strip() for l in open('offer.txt').readlines()])
# configuration
tags=('<b>','</b>')
trail=5
maxlines=5
sw=sw.split()
for p in cutFound(txt,sw,tags,trail,maxlines):
print p
# vim: filetype=python syntax=python shiftwidth=2
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<tuple>
<tuple>
<string>Products.PythonScripts.PythonScript</string>
<string>PythonScript</string>
</tuple>
<none/>
</tuple>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Python_magic</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>__ac_local_roles__</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_body</string> </key>
<value> <string>tags=(\'[[\',\']]\')\n
trail=5\n
maxlines=5\n
txt=brain.SearchableText()\n
sw=context.REQUEST.get(\'SearchableText\',None)\n
context.log(script.getId(),sw)\n
if sw is None:\n
return \'\'\n
sw=sw.split()\n
res=context.cutFound(context,txt,sw,tags,trail,maxlines)\n
return \' \'.join(map(str,res))\n
</string> </value>
</item>
<item>
<key> <string>_code</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>_filepath</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>brain,selection</string> </value>
</item>
<item>
<key> <string>errors</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>func_code</string> </key>
<value>
<object>
<klass>
<global name="FuncCode" module="Shared.DC.Scripts.Signature"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>co_argcount</string> </key>
<value> <int>2</int> </value>
</item>
<item>
<key> <string>co_varnames</string> </key>
<value>
<tuple>
<string>brain</string>
<string>selection</string>
<string>tags</string>
<string>trail</string>
<string>maxlines</string>
<string>_getattr_</string>
<string>txt</string>
<string>context</string>
<string>None</string>
<string>sw</string>
<string>script</string>
<string>res</string>
<string>map</string>
<string>str</string>
</tuple>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>func_defaults</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Base_showFoundText</string> </value>
</item>
<item>
<key> <string>warnings</string> </key>
<value>
<tuple/>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<tuple>
<tuple>
<string>Products.ERP5Form.Form</string>
<string>ERP5Form</string>
</tuple>
<none/>
</tuple>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>__ac_local_roles__</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary/>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_objects</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>action</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>encoding</string> </key>
<value> <string>UTF-8</string> </value>
</item>
<item>
<key> <string>enctype</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>group_list</string> </key>
<value>
<list>
<string>bottom</string>
</list>
</value>
</item>
<item>
<key> <string>groups</string> </key>
<value>
<dictionary>
<item>
<key> <string>bottom</string> </key>
<value>
<list>
<string>listbox</string>
</list>
</value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Base_viewSearchResultList</string> </value>
</item>
<item>
<key> <string>method</string> </key>
<value> <string>POST</string> </value>
</item>
<item>
<key> <string>name</string> </key>
<value> <string>Folder_viewContentList</string> </value>
</item>
<item>
<key> <string>pt</string> </key>
<value> <string>form_list</string> </value>
</item>
<item>
<key> <string>rid</string> </key>
<value> <int>-1722436574</int> </value>
</item>
<item>
<key> <string>row_length</string> </key>
<value> <int>4</int> </value>
</item>
<item>
<key> <string>stored_encoding</string> </key>
<value> <string>UTF-8</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Folder Contents</string> </value>
</item>
<item>
<key> <string>uid</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>unicode_mode</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>update_action</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<tuple>
<tuple>
<string>Products.ExternalMethod.ExternalMethod</string>
<string>ExternalMethod</string>
</tuple>
<none/>
</tuple>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>__ac_local_roles__</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>_function</string> </key>
<value> <string>cutFound</string> </value>
</item>
<item>
<key> <string>_module</string> </key>
<value> <string>cutFound</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>cutFound</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
2006-08-03 BG
Nice display of search results (with highlights from SearchableText); searchable text for Spreadsheet.
2006-08-02 BG 2006-08-02 BG
* Support for Pdf File * Support for Pdf File
* fixes in actions, type registry and forms * fixes in actions, type registry and forms
......
7 11
\ No newline at end of file \ No newline at end of file
asSecurityGroupIdList asSecurityGroupIdList
cutFound
asSecurityGroupId asSecurityGroupId
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment