This function creates a new Query that returns all rows from an query that match the given filter.

query.filter( filter=function, parallel=boolean, maxThreads=number )

Returns: Query

Argument Description
function, required

filter can be a function/closure that implements the following constructor

[function(struct row[, number rowNumber, query query]):boolean].

for best performance, it really helps to use scoped variables, like arguments.row, instead of just row

boolean, optional

execute closures parallel

number, optional

maximum number of threads executed, ignored when argument "parallel" is set to false


	q = QueryNew("name, description");
	loop times=3 {
			var fd = getFunctionData(arguments.f);
			var r =QueryAddRow(q);
			QuerySetCell(q,"name", fd.name, r);
			QuerySetCell(q,"description", fd.description, r);
	    label="demo data set size");
	s = "the";
<cftimer type="outline" label="Query of Query">
	<cfquery dbtype="query" name="q1">
		select 	name, description
		from 	q
		where 	description like <cfqueryparam value='%#s#%' cfsqltype="varchar">
<cfdump var=#q1.recordcount#>
<cftimer type="outline" label="query.filter() with scoped variables">
		q2 = q.filter(function(row){
			return (arguments.row.description contains s);
<cfdump var=#q2.recordcount#>
<cftimer type="outline" label="query.filter() without unscoped variables">
		q3 = q.filter(function(row){
			return (row.description contains s);
<cfdump var=#q3.recordcount#>

See also