def scansearch(auth, label, filt, project=None, aid=None):
if not aid:<EOL><INDENT>aid = accession(auth, label, project)<EOL><DEDENT>url = "<STR_LIT>" % (auth.url.rstrip('<STR_LIT:/>'), aid)<EOL>logger.debug("<STR_LIT>", url)<EOL>r = requests.get(url, auth=(auth.username, auth.password), verify=CHECK_CERTIFICATE)<EOL>if r.status_code != requests.codes.ok:<EOL><INDENT>raise ScanSearchError("<STR_LIT>" % (r.status_code, r.url))<EOL><DEDENT>if not r.content:<EOL><INDENT>raise ScanSearchError("<STR_LIT>" % r.url)<EOL><DEDENT>reader = csv.reader(io.StringIO(r.content.decode()))<EOL>columns = next(reader)<EOL>conn = sqlite3.connect("<STR_LIT>")<EOL>c = conn.cursor()<EOL>c.execute("<STR_LIT>" % '<STR_LIT:U+002C>'.join(columns))<EOL>query = "<STR_LIT>" % '<STR_LIT:U+002C>'.join('<STR_LIT:?>' * len(columns))<EOL>for row in reader:<EOL><INDENT>c.execute(query, [x for x in row])<EOL><DEDENT>conn.commit()<EOL>result = col.defaultdict(list)<EOL>for token,filt in iter(filt.items()):<EOL><INDENT>try:<EOL><INDENT>result[token] = [x[<NUM_LIT:0>] for x in c.execute("<STR_LIT>" % filt)]<EOL><DEDENT>except sqlite3.OperationalError:<EOL><INDENT>logger.critical("<STR_LIT>", filt)<EOL>raise<EOL><DEDENT><DEDENT>return result<EOL>
Search for scans by supplying a set of SQL-based conditionals.

Example:
    >>> import yaxil
    >>> auth = yaxil.XnatAuth(url='...', username='...', password='...')
    >>> query = {
    ...   'eor1': "note LIKE %EOR1%",
    ...   'eor2': "note LIKE %EOR2%",
    ...   'mpr':  "series_description='T1_MEMPRAGE RMS' OR note LIKE %ANAT%"
    ... }
    >>> yaxil.scansearch(auth, 'AB1234C', query)
    {"mpr": [4], "eor1": [13], "eor2": [14]}

:param auth: XNAT authentication object
:type auth: :mod:`yaxil.XnatAuth`
:param label: XNAT MR Session label
:type label: str
:param filt: Scan search filter/query
:type filt: dict
:param project: XNAT MR Session project
:type project: str
:param aid: XNAT Accession ID
:type aid: str
:returns: Same dictionary that was passed in, but values are now matching scans
:rtype: dict