def get_search_results(portal_type=None, uid=None, **kw): """Search the catalog and return the results :returns: Catalog search results :rtype: iterable """ # 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 search(self, query): """search the catalog """ logger.info("Catalog query={}".format(query)) # Support to set the catalog as a request parameter catalogs = _.to_list(req.get("catalog", None)) if catalogs: return senaiteapi.search(query, catalog=catalogs) # Delegate to the search API of Bika LIMS return senaiteapi.search(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