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

Finished lexicon query screen.

Completed Zope integration.
parent 7473eda8
......@@ -38,6 +38,9 @@ from Products.ZCTextIndex.OkapiIndex import OkapiIndex
index_types = {'Okapi BM25 Rank':OkapiIndex,
'Cosine Measure':CosineIndex}
IndexMgmtPerm = 'Manage ZCatalogIndex Entries'
IndexSearchPerm = 'Search ZCatalogIndex'
class ZCTextIndex(Persistent, Acquisition.Implicit, SimpleItem):
"""Persistent TextIndex"""
......@@ -53,6 +56,9 @@ class ZCTextIndex(Persistent, Acquisition.Implicit, SimpleItem):
query_options = ['query']
security = ClassSecurityInfo()
security.declareObjectProtected(IndexMgmtPerm)
## Constructor ##
def __init__(self, id, extra, caller, index_factory=None):
......@@ -82,6 +88,8 @@ class ZCTextIndex(Persistent, Acquisition.Implicit, SimpleItem):
## External methods not in the Pluggable Index API ##
security.declareProtected('query', IndexSearchPerm)
def query(self, query, nbest=10):
"""Return pair (mapping from docids to scores, num results).
......@@ -195,6 +203,11 @@ def manage_addLexicon(self, id, title='', elements=[], REQUEST=None):
if REQUEST is not None:
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):
"""Lexicon for ZCTextIndex"""
......@@ -204,6 +217,9 @@ class PLexicon(Lexicon, Acquisition.Implicit, SimpleItem):
{'label':'Query', 'action':'queryLexicon'},
) + SimpleItem.manage_options
security = ClassSecurityInfo()
security.declareObjectProtected(LexiconQueryPerm)
def __init__(self, id, title='', *pipeline):
self.id = str(id)
self.title = str(title)
......@@ -217,6 +233,8 @@ class PLexicon(Lexicon, Acquisition.Implicit, SimpleItem):
_queryLexicon = DTMLFile('dtml/queryLexicon', globals())
security.declareProtected(LexiconQueryPerm, 'queryLexicon')
def queryLexicon(self, REQUEST, words=None, page=0, rows=20, cols=4):
"""Lexicon browser/query user interface
"""
......@@ -229,7 +247,7 @@ class PLexicon(Lexicon, Acquisition.Implicit, SimpleItem):
words = self.words()
word_count = len(words)
rows = max(min(rows, 500),1)
rows = max(min(rows, 500), 1)
cols = max(min(cols, 12), 1)
page_count = word_count / (rows * cols) + \
(word_count % (rows * cols) > 0)
......@@ -256,8 +274,10 @@ class PLexicon(Lexicon, Acquisition.Implicit, SimpleItem):
end_word=end,
word_count=word_count,
page_count=page_count,
page_range=xrange(page_count),
page_columns=columns)
security.declareProtected(LexiconMgmtPerm, 'manage_main')
manage_main = DTMLFile('dtml/manageLexicon', globals())
InitializeClass(PLexicon)
......@@ -34,7 +34,7 @@
<td align="right"><span class="form-label">
Page:
<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;"
<dtml-if expr="page == page_item">
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