def get_search_results(portal_type=None, uid=None, **kw): """Search the catalog and return the results :returns: Catalog search results :rtype: list or Products.ZCatalog.Lazy.LazyMap """ # If we have an UID, return the object immediately if uid is not None: logger.info("UID '%s' found, returning the object immediately" % uid) return u.to_list(get_object_by_uid(uid)) # allow to search search for the Plone Site with portal_type include_portal = False if u.to_string(portal_type) == "Plone Site": include_portal = True # The request may contain a list of portal_types, e.g. # `?portal_type=Document&portal_type=Plone Site` if "Plone Site" in u.to_list(req.get("portal_type")): include_portal = True # Build and execute a catalog query results = search(portal_type=portal_type, uid=uid, **kw) if include_portal: results = list(results) + u.to_list(get_portal()) return results
def get_keyword_query(self, **kw): """Generates a query from the given keywords. Only known indexes make it into the generated query. :returns: Catalog query :rtype: dict """ query = dict() # Only known indexes get observed indexes = self.catalog.get_indexes() # Handle additional keyword parameters for k, v in kw.iteritems(): # handle uid in keywords if k.lower() == "uid": k = "UID" # handle portal_type in keywords if k.lower() == "portal_type": if v: v = _.to_list(v) if k not in indexes: logger.warn("Skipping unknown keyword parameter '%s=%s'" % (k, v)) continue if v is None: logger.warn("Skip None value in kw parameter '%s=%s'" % (k, v)) continue logger.debug("Adding '%s=%s' to query" % (k, v)) query[k] = v return query
def get_keyword_query(self, **kw): """Generates a query from the given keywords. Only known indexes make it into the generated query. :returns: Catalog query :rtype: dict """ query = dict() # Only known indexes get observed indexes = self.catalog.get_indexes() # Handle additional keyword parameters for k, v in kw.iteritems(): # handle uid in keywords if k.lower() == "uid": k = "UID" # handle portal_type in keywords if k.lower() == "portal_type": if v: v = u.to_list(v) if k not in indexes: logger.warn("Skipping unknown keyword parameter '%s=%s'" % (k, v)) continue if v is None: logger.warn("Skip None value in kw parameter '%s=%s'" % (k, v)) continue logger.debug("Adding '%s=%s' to query" % (k, v)) query[k] = v return query
def get_keyword_query(**kw): """ generates a query from the given keywords """ query = dict() # only known indexes get observed indexes = get_catalog_indexes() for k, v in kw.iteritems(): # handle uid if v and k.lower() == "uid": if v: query["UID"] = v continue # handle portal_type if k.lower() == "portal_type": if v: query["portal_type"] = _.to_list(v) continue # and the rest if k not in indexes: logger.warn("Skipping unknown keyword parameter '%s=%s'" % (k, v)) continue if v is None: logger.warn("Skip value 'None' in kw parameter '%s=%s'" % (k, v)) continue logger.info("Adding '%s=%s' to query" % (k, v)) query[k] = v return query
def to_index_value(self, value, index): """Convert the value for a given index """ # ZPublisher records can be passed to the catalog as is. if isinstance(value, HTTPRequest.record): return value if isinstance(index, basestring): index = self.get_index(index) if index.id == "portal_type": return filter(lambda x: x, _.to_list(value)) if index.meta_type == "DateIndex": return DateTime(value) if index.meta_type == "BooleanIndex": return bool(value) if index.meta_type == "KeywordIndex": return value.split(",") return value
def to_index_value(self, value, index): """Convert the value for a given index """ # ZPublisher records can be passed to the catalog as is. if isinstance(value, HTTPRequest.record): return value if isinstance(index, basestring): index = self.get_index(index) if index.id == "portal_type": return filter(lambda x: x, u.to_list(value)) if index.meta_type == "DateIndex": return DateTime(value) if index.meta_type == "BooleanIndex": return bool(value) if index.meta_type == "KeywordIndex": return value.split(",") return value