Commit 169047b5 authored by Casey Duncan's avatar Casey Duncan

Finished lexicon query screen.

Completed Zope integration.
parent 7473eda8
...@@ -37,6 +37,9 @@ from Products.ZCTextIndex.CosineIndex import CosineIndex ...@@ -37,6 +37,9 @@ from Products.ZCTextIndex.CosineIndex import CosineIndex
from Products.ZCTextIndex.OkapiIndex import OkapiIndex from Products.ZCTextIndex.OkapiIndex import OkapiIndex
index_types = {'Okapi BM25 Rank':OkapiIndex, index_types = {'Okapi BM25 Rank':OkapiIndex,
'Cosine Measure':CosineIndex} 'Cosine Measure':CosineIndex}
IndexMgmtPerm = 'Manage ZCatalogIndex Entries'
IndexSearchPerm = 'Search ZCatalogIndex'
class ZCTextIndex(Persistent, Acquisition.Implicit, SimpleItem): class ZCTextIndex(Persistent, Acquisition.Implicit, SimpleItem):
"""Persistent TextIndex""" """Persistent TextIndex"""
...@@ -52,6 +55,9 @@ class ZCTextIndex(Persistent, Acquisition.Implicit, SimpleItem): ...@@ -52,6 +55,9 @@ class ZCTextIndex(Persistent, Acquisition.Implicit, SimpleItem):
) )
query_options = ['query'] query_options = ['query']
security = ClassSecurityInfo()
security.declareObjectProtected(IndexMgmtPerm)
## Constructor ## ## Constructor ##
...@@ -82,6 +88,8 @@ class ZCTextIndex(Persistent, Acquisition.Implicit, SimpleItem): ...@@ -82,6 +88,8 @@ class ZCTextIndex(Persistent, Acquisition.Implicit, SimpleItem):
## External methods not in the Pluggable Index API ## ## External methods not in the Pluggable Index API ##
security.declareProtected('query', IndexSearchPerm)
def query(self, query, nbest=10): def query(self, query, nbest=10):
"""Return pair (mapping from docids to scores, num results). """Return pair (mapping from docids to scores, num results).
...@@ -195,6 +203,11 @@ def manage_addLexicon(self, id, title='', elements=[], REQUEST=None): ...@@ -195,6 +203,11 @@ def manage_addLexicon(self, id, title='', elements=[], REQUEST=None):
if REQUEST is not None: if REQUEST is not None:
return self.manage_main(self, REQUEST, update_menu=1) return self.manage_main(self, REQUEST, update_menu=1)
# I am borrowing the existing vocabulary permissions for now to avoid
# adding new permissions. This may change when old style Vocabs go away
LexiconQueryPerm = 'Query Vocabulary'
LexiconMgmtPerm = 'Manage Vocabulary'
class PLexicon(Lexicon, Acquisition.Implicit, SimpleItem): class PLexicon(Lexicon, Acquisition.Implicit, SimpleItem):
"""Lexicon for ZCTextIndex""" """Lexicon for ZCTextIndex"""
...@@ -203,6 +216,9 @@ class PLexicon(Lexicon, Acquisition.Implicit, SimpleItem): ...@@ -203,6 +216,9 @@ class PLexicon(Lexicon, Acquisition.Implicit, SimpleItem):
manage_options = ({'label':'Overview', 'action':'manage_main'}, manage_options = ({'label':'Overview', 'action':'manage_main'},
{'label':'Query', 'action':'queryLexicon'}, {'label':'Query', 'action':'queryLexicon'},
) + SimpleItem.manage_options ) + SimpleItem.manage_options
security = ClassSecurityInfo()
security.declareObjectProtected(LexiconQueryPerm)
def __init__(self, id, title='', *pipeline): def __init__(self, id, title='', *pipeline):
self.id = str(id) self.id = str(id)
...@@ -217,6 +233,8 @@ class PLexicon(Lexicon, Acquisition.Implicit, SimpleItem): ...@@ -217,6 +233,8 @@ class PLexicon(Lexicon, Acquisition.Implicit, SimpleItem):
_queryLexicon = DTMLFile('dtml/queryLexicon', globals()) _queryLexicon = DTMLFile('dtml/queryLexicon', globals())
security.declareProtected(LexiconQueryPerm, 'queryLexicon')
def queryLexicon(self, REQUEST, words=None, page=0, rows=20, cols=4): def queryLexicon(self, REQUEST, words=None, page=0, rows=20, cols=4):
"""Lexicon browser/query user interface """Lexicon browser/query user interface
""" """
...@@ -229,7 +247,7 @@ class PLexicon(Lexicon, Acquisition.Implicit, SimpleItem): ...@@ -229,7 +247,7 @@ class PLexicon(Lexicon, Acquisition.Implicit, SimpleItem):
words = self.words() words = self.words()
word_count = len(words) word_count = len(words)
rows = max(min(rows, 500),1) rows = max(min(rows, 500), 1)
cols = max(min(cols, 12), 1) cols = max(min(cols, 12), 1)
page_count = word_count / (rows * cols) + \ page_count = word_count / (rows * cols) + \
(word_count % (rows * cols) > 0) (word_count % (rows * cols) > 0)
...@@ -256,8 +274,10 @@ class PLexicon(Lexicon, Acquisition.Implicit, SimpleItem): ...@@ -256,8 +274,10 @@ class PLexicon(Lexicon, Acquisition.Implicit, SimpleItem):
end_word=end, end_word=end,
word_count=word_count, word_count=word_count,
page_count=page_count, page_count=page_count,
page_range=xrange(page_count),
page_columns=columns) page_columns=columns)
security.declareProtected(LexiconMgmtPerm, 'manage_main')
manage_main = DTMLFile('dtml/manageLexicon', globals()) manage_main = DTMLFile('dtml/manageLexicon', globals())
InitializeClass(PLexicon) InitializeClass(PLexicon)
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
<td align="right"><span class="form-label"> <td align="right"><span class="form-label">
Page: Page:
<select name="page:int" onchange="this.form.submit()"> <select name="page:int" onchange="this.form.submit()">
<dtml-in expr="_.range(page_count)" prefix="page"> <dtml-in name="page_range" prefix="page">
<option value="&dtml-page_item;" <option value="&dtml-page_item;"
<dtml-if expr="page == page_item"> <dtml-if expr="page == page_item">
selected selected
......
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