Back to index

plone3  3.1.7
Public Member Functions | Public Attributes
plone.app.vocabularies.catalog.SearchableTextSource Class Reference

List of all members.

Public Member Functions

def __init__
def __contains__
def search

Public Attributes

 context
 base_query
 default_query
 catalog
 portal_tool
 portal_path

Detailed Description

  >>> from plone.app.vocabularies.tests.base import Brain
  >>> from plone.app.vocabularies.tests.base import DummyContext
  >>> from plone.app.vocabularies.tests.base import DummyTool

  >>> context = DummyContext()

  >>> tool = DummyTool('portal_catalog')
  >>> rids = ('/1234', '/2345')
  >>> def getrid(value):
  ...     return value in rids and value or None
  >>> tool.getrid = getrid
  >>> def call(**values):
  ...     if values['SearchableText'].startswith('error'):
  ...         raise ParseError
  ...     return [Brain(r) for r in rids]
  >>> tool.__call__ = call
  >>> context.portal_catalog = tool

  >>> tool = DummyTool('portal_url')
  >>> def getPortalPath():
  ...     return '/'
  >>> tool.getPortalPath = getPortalPath
  >>> context.portal_url = tool

  >>> source = SearchableTextSource(context)
  >>> source
  <plone.app.vocabularies.catalog.SearchableTextSource object at ...>

  >>> '1234' in source, '1' in source
  (True, False)

  >>> source.search('')
  []

  >>> source.search('error')
  []

  >>> source.search('foo')
  <generator object at ...>

  >>> list(source.search('foo'))
  ['1234', '2345']

  >>> list(source.search('bar path:/dummy'))
  ['/dummy', '1234', '2345']

  >>> source = SearchableTextSource(context, default_query='default')
  >>> list(source.search(''))
  ['1234', '2345']

Definition at line 84 of file catalog.py.


Constructor & Destructor Documentation

def plone.app.vocabularies.catalog.SearchableTextSource.__init__ (   self,
  context,
  base_query = {},
  default_query = None 
)

Definition at line 139 of file catalog.py.

00139 
00140     def __init__(self, context, base_query={}, default_query=None):
00141         self.context = context
00142         self.base_query = base_query
00143         self.default_query = default_query
00144         self.catalog = getToolByName(context, "portal_catalog")
00145         self.portal_tool = getToolByName(context, "portal_url")
00146         self.portal_path = self.portal_tool.getPortalPath()

Here is the caller graph for this function:


Member Function Documentation

Return whether the value is available in this source

Definition at line 147 of file catalog.py.

00147 
00148     def __contains__(self, value):
00149         """Return whether the value is available in this source
00150         """
00151         if self.catalog.getrid(self.portal_path + value) is None:
00152             return False
00153         return True

Definition at line 154 of file catalog.py.

00154 
00155     def search(self, query_string):
00156         query = self.base_query.copy()
00157         if query_string == '':
00158             if self.default_query is not None:
00159                 query.update(parse_query(self.default_query, self.portal_path))
00160             else:
00161                 return []
00162         else:
00163             query.update(parse_query(query_string, self.portal_path))
00164         
00165         try:
00166             results = (x.getPath()[len(self.portal_path):] for x in self.catalog(**query))
00167         except ParseError:
00168             return []
00169         
00170         if query.has_key('path'):
00171             path = query['path']['query'][len(self.portal_path):]
00172             if path != '':
00173                 return itertools.chain((path,), results)
00174         return results

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 141 of file catalog.py.

Definition at line 143 of file catalog.py.

Definition at line 140 of file catalog.py.

Definition at line 142 of file catalog.py.

Definition at line 145 of file catalog.py.

Definition at line 144 of file catalog.py.


The documentation for this class was generated from the following file: