def get_compiled_query(query_string, needles):
 compiled_query = None
 for word in get_query_words(query_string):
  inner_query = None
  for needle in needles:
   q = Q(**{(u'%s__icontains' % needle): word})
   inner_query = (q if (inner_query is None) else (inner_query | q))
  compiled_query = (inner_query if (compiled_query is None) else (compiled_query & inner_query))
 return compiled_query

def get_compiled_query ( query_string , needles ) : compiled_query = None for word in get_query_words ( query_string ) : inner_query = None for needle in needles : q = Q ( ** { ( u'%s__icontains' % needle ) : word } ) inner_query = ( q if ( inner_query is None ) else ( inner_query | q ) ) compiled_query = ( inner_query if ( compiled_query is None ) else ( compiled_query & inner_query ) ) return compiled_query
get compiled query compile query string into q objects and return it .