#NEWLINE# def find_res_by_keyword( self , keyword , restype = None , id_only = False , filter = None ) : #NEWLINE# #INDENT# log . debug ( 'find_res_by_keyword(keyword=%s, restype=%s)' , keyword , restype ) #NEWLINE# if ( ( not keyword ) or ( type ( keyword ) is not str ) ) : #NEWLINE# #INDENT# raise BadRequest ( 'Argument keyword illegal' ) #NEWLINE# #UNINDENT# if ( type ( id_only ) is not bool ) : #NEWLINE# #INDENT# raise BadRequest ( ( 'id_only must be type bool, not %s' % type ( id_only ) ) ) #NEWLINE# #UNINDENT# filter = ( filter if ( filter is not None ) else { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) #NEWLINE# qual_ds_name = self . _get_datastore_name ( ) #NEWLINE# if id_only : #NEWLINE# #INDENT# query = ( 'SELECT id, type_ FROM ' + qual_ds_name ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# query = ( 'SELECT id, type_, doc FROM ' + qual_ds_name ) #NEWLINE# #UNINDENT# query_clause = " WHERE lcstate<>'DELETED' " #NEWLINE# query_args = dict ( type_ = restype , kw = [ keyword ] ) #NEWLINE# query_clause += 'AND %(kw)s <@ json_keywords(doc)' #NEWLINE# if restype : #NEWLINE# #INDENT# query_clause += ' AND type_=%(type_)s' #NEWLINE# #UNINDENT# query_clause = self . _add_access_filter ( filter , qual_ds_name , query_clause , query_args ) #NEWLINE# extra_clause = filter . get ( 'extra_clause' , '' ) #NEWLINE# with self . pool . cursor ( ** restype . cursor_args ) as cur : #NEWLINE# #INDENT# cur . execute ( ( ( query + query_clause ) + extra_clause ) , query_args ) #NEWLINE# rows = cur . fetchall ( ) #NEWLINE# #UNINDENT# res_assocs = [ dict ( id = self . _prep_id ( row [ 0 ] ) , type = row [ 1 ] , keyword = keyword ) for row in rows ] #NEWLINE# log . debug ( 'find_res_by_keyword() found %s objects' , len ( res_assocs ) ) #NEWLINE# return self . _prepare_find_return ( rows , res_assocs , id_only = id_only )