def add_lexicon(catalog): # Lexicon catalog._setObject('plone_lexicon', PLexicon('plone_lexicon')) lexicon = catalog.plone_lexicon pipeline = [ element_factory.instantiate( "Word Splitter", "Unicode Whitespace splitter"), element_factory.instantiate( "Case Normalizer", "Unicode Case Normalizer"), ] lexicon._pipeline = tuple(pipeline)
def setup_lexicons(self): # setup the lexicons as some Plone-Catalog internal code depends on it # we wouldn't relly have to be so thorough as we don't actually want # to support full text searches on the people catalog, but setting # up the people catalog as close as possible to the portal catalog # ensures that there are no surprises lexicons = { 'plone_lexicon': [ ('Unicode Whitespace splitter', 'Word Splitter'), ('Unicode Ignoring Accents Case Normalizer', 'Case Normalizer'), ], 'plaintext_lexicon': [ ('HTML aware splitter', 'Word Splitter'), ('Case Normalizer', 'Case Normalizer'), ('Remove listed stop words only', 'Stop Words') ], 'htmltext_lexicon': [ ('HTML aware splitter', 'Word Splitter'), ('Case Normalizer', 'Case Normalizer'), ('Remove listed stop words only', 'Stop Words') ] } for lexicon, elements in lexicons.items(): pipeline = [] for element in elements: element = element_factory.instantiate(element[1], element[0]) pipeline.append(element) plexicon = PLexicon(lexicon) plexicon._pipeline = pipeline self._setObject(lexicon, plexicon)
def _importNode(self, node): """Import the object from the DOM node. """ pipeline = [] for child in node.childNodes: if child.nodeName == 'element': element = element_factory.instantiate( child.getAttribute('group').encode('utf-8'), child.getAttribute('name').encode('utf-8')) pipeline.append(element) self.context._pipeline = tuple(pipeline)
def importNode(self, node, mode=PURGE): """Import the object from the DOM node. """ pipeline = [] for child in node.childNodes: if child.nodeName == 'element': element = element_factory.instantiate( child.getAttribute('group'), child.getAttribute('name')) pipeline.append(element) self.context._pipeline = tuple(pipeline) #clear lexicon self.context._wids = OIBTree() self.context._words = IOBTree() self.context.length = Length()
def manage_addLexicon(self, id, title='', elements=[], REQUEST=None): """Add ZCTextIndex Lexicon""" pipeline = [] for el_record in elements: if not hasattr(el_record, 'name'): continue # Skip over records that only specify element group element = element_factory.instantiate(el_record.group, el_record.name) if element is not None: if el_record.group == 'Word Splitter': # I don't like hardcoding this, but its a simple solution # to get the splitter element first in the pipeline pipeline.insert(0, element) else: pipeline.append(element) lexicon = PLexicon(id, title, *pipeline) self._setObject(id, lexicon) if REQUEST is not None: return self.manage_main(self, REQUEST, update_menu=1)