From ba7c130b34425a8c00f5632b7ff21c412340ba49 Mon Sep 17 00:00:00 2001 From: Casey Duncan Date: Wed, 5 Jun 2002 20:02:02 +0000 Subject: [PATCH] Added management interface to query words in the lexicon and in the process uncovered a BTreeItems bug, whee! --- ZCTextIndex.py | 50 ++++++++++++++++++++++++-- dtml/manageLexicon.dtml | 4 +-- dtml/manageZCTextIndex.dtml | 10 ++++-- dtml/queryLexicon.dtml | 71 +++++++++++++++++++++++++++++++++++++ help/Lexicon_Add.stx | 19 +++++----- 5 files changed, 136 insertions(+), 18 deletions(-) create mode 100644 dtml/queryLexicon.dtml diff --git a/ZCTextIndex.py b/ZCTextIndex.py index 82f2302..8a1ef83 100644 --- a/ZCTextIndex.py +++ b/ZCTextIndex.py @@ -200,8 +200,9 @@ class PLexicon(Lexicon, Acquisition.Implicit, SimpleItem): meta_type = 'ZCTextIndex Lexicon' - manage_options = ({'label':'Overview', 'action':'manage_main'},) + \ - SimpleItem.manage_options + manage_options = ({'label':'Overview', 'action':'manage_main'}, + {'label':'Query', 'action':'queryLexicon'}, + ) + SimpleItem.manage_options def __init__(self, id, title='', *pipeline): self.id = str(id) @@ -213,7 +214,50 @@ def __init__(self, id, title='', *pipeline): def getPipelineNames(self): """Return list of names of pipeline element classes""" return [element.__class__.__name__ for element in self._pipeline] - + + _queryLexicon = DTMLFile('dtml/queryLexicon', globals()) + + def queryLexicon(self, REQUEST, words=None, page=0, rows=20, cols=4): + """Lexicon browser/query user interface + """ + if words: + wids = [] + for word in words: + wids.extend(self.globToWordIds(word)) + words = [self.get_word(wid) for wid in wids] + else: + words = self.words() + + word_count = len(words) + rows = max(min(rows, 500),1) + cols = max(min(cols, 12), 1) + page_count = word_count / (rows * cols) + \ + (word_count % (rows * cols) > 0) + page = max(min(page, page_count - 1), 0) + start = rows * cols * page + end = min(rows * cols * (page + 1), word_count) + + if word_count: + words = list(words[start:end]) + else: + words = [] + + columns = [] + i = 0 + while i < len(words): + columns.append(words[i:i + rows]) + i += rows + + return self._queryLexicon(self, REQUEST, + page=page, + rows=rows, + cols=cols, + start_word=start+1, + end_word=end, + word_count=word_count, + page_count=page_count, + page_columns=columns) + manage_main = DTMLFile('dtml/manageLexicon', globals()) InitializeClass(PLexicon) diff --git a/dtml/manageLexicon.dtml b/dtml/manageLexicon.dtml index 1c6090f..511d04a 100644 --- a/dtml/manageLexicon.dtml +++ b/dtml/manageLexicon.dtml @@ -10,12 +10,12 @@ Input Pipeline Stages

-

+

Text indexed through this lexicon is processed by the following pipeline stages

-
    +
    1. &dtml-sequence-item;
    2. diff --git a/dtml/manageZCTextIndex.dtml b/dtml/manageZCTextIndex.dtml index b83a3b4..b100de0 100644 --- a/dtml/manageZCTextIndex.dtml +++ b/dtml/manageZCTextIndex.dtml @@ -2,8 +2,12 @@

      - - There is nothing to manage here. Move along. - + The ZCTextIndex Lexicon in use by this index is: + +

      +

      + Note: You cannot change the lexicon assigned to a ZCTextIndex. + To use another lexicon, delete this index and create a new one that + uses the desired lexicon.

      diff --git a/dtml/queryLexicon.dtml b/dtml/queryLexicon.dtml new file mode 100644 index 0000000..8f45cae --- /dev/null +++ b/dtml/queryLexicon.dtml @@ -0,0 +1,71 @@ + + + +

      + Browse the words in the lexicon or enter the word(s) you are interested in + below. Globbing characters (*, ?) are supported +

      + + +
      +

      + Word(s) + + + +  Output Columns: + +  Rows: + +

      +
      +
      +
      + + + + + + +
      + &dtml-word_count; Words Found, + Displaying &dtml-start_word;-&dtml-end_word; + + + + + Page: + + of &dtml-page_count; + + + + + +
      +
      +
      + + + + + + + + +
      + +
      +
      + +