コード例 #1
0
    def searchResults(self, REQUEST=None, check_perms=False, **kw):
        mode = self.mode
        if mode == DISABLE_MODE:
            return self.patched.searchResults(REQUEST, **kw)
        if isinstance(REQUEST, dict):
            query = REQUEST.copy()
        else:
            query = {}
        query.update(kw)

        if check_perms:
            show_inactive = query.get('show_inactive', False)
            if isinstance(REQUEST, dict) and not show_inactive:
                show_inactive = 'show_inactive' in REQUEST

            user = _getAuthenticatedUser(self.catalogtool)
            query[
                'allowedRolesAndUsers'] = self.catalogtool._listAllowedRolesAndUsers(
                    user)

            if not show_inactive and not _checkPermission(
                    AccessInactivePortalContent, self.catalogtool):
                query['effectiveRange'] = DateTime()
        orig_query = query.copy()
        # info('Running query: %s' % repr(orig_query))
        try:
            return self.query(query)
        except:
            info("Error running Query: %s\n%s" %
                 (repr(orig_query), traceback.format_exc()))
            if mode == DUAL_MODE:
                # fall back now...
                return self.patched.searchResults(REQUEST, **kw)
            else:
                return LazyMap(BrainFactory(self.catalog), [], 0)
コード例 #2
0
 def query(self, query):
     qassembler = QueryAssembler(self.catalogtool)
     dquery, sort = qassembler.normalize(query)
     equery = qassembler(dquery)
     result = self.conn.search(equery,
                               self.catalogsid,
                               self.catalogtype,
                               sort=sort,
                               fields="_metadata")
     count = result.count()
     result = ResultWrapper(result, count=count)
     factory = BrainFactory(self.catalog)
     return LazyMap(factory, result, count)
コード例 #3
0
 def search(self, query, factory=None, **query_params):
     """
     @param query: dict
         The plone query
     @param factory: function(result: dict): any
         The factory that maps each elastic search result.
         By default, get the plone catalog brain.
     @param query_params:
         Parameters to pass to the search method
         'stored_fields': the list of fields to get from stored source
     @return: LazyMap
     """
     result = ElasticResult(self, query, **query_params)
     if not factory:
         factory = BrainFactory(self.catalog)
     return LazyMap(factory, result, result.count)
コード例 #4
0
def zcatalog_fhir_search(context,
                         query_string=None,
                         params=None,
                         bundle_response=False,
                         bundle_as_dict=False):
    """ """
    query_result = Search(context=context,
                          query_string=query_string,
                          params=params).build()

    query_copy = query_result._query.clone()
    if context.unrestricted is False:
        context.engine.build_security_query(query_copy)

    params = {
        "query": query_copy,
        "calculate_field_index_name":
        context.engine.calculate_field_index_name,
        "get_mapping": context.engine.get_mapping,
    }

    compiled = context.engine.dialect.compile(**params)
    if "from" in compiled:
        del compiled["from"]
    if "scroll" in compiled:
        del compiled["scroll"]
    if "_source" in compiled:
        del compiled["_source"]
    if "size" in compiled:
        del compiled["size"]

    query_params = {"stored_fields": "path.path"}
    result = ElasticResult(context.engine.es_catalog, compiled, **query_params)
    factory = BrainFactory(context.engine.es_catalog.catalog)
    lazy_maps = LazyMap(factory, result, result.count)

    if bundle_response is False:
        return lazy_maps

    engine_result = build_engine_result(lazy_maps)

    return context.engine.wrapped_with_bundle(engine_result,
                                              as_json=bundle_as_dict)
コード例 #5
0
 def search(self, query):
     result = ElasticResult(self, query)
     factory = BrainFactory(self.catalog)
     return LazyMap(factory, result, result.count)