'Search the database using unix glob-style matching (wildcards
* and ?).
Parameters
pattern : str
The wildcarded pattern to match when searching
search_raw : bool
If True, search the raw input, otherwise, the parsed input
raw, output : bool
See :meth:`get_range`
n : None or int
If an integer is given, it defines the limit of
returned entries.
unique : bool
When it is true, return only unique entries.
Returns
Tuples as :meth:`get_range`'

@catch_corrupt_db
def search(self, pattern='*', raw=True, search_raw=True, output=False, n=None, unique=False):

    tosearch = ('source_raw' if search_raw else 'source')
    if output:
        tosearch = ('history.' + tosearch)
    self.writeout_cache()
    sqlform = ('WHERE    %s    GLOB    ?' % tosearch)
    params = (pattern,)
    if unique:
        sqlform += '    GROUP    BY    {0}'.format(tosearch)
    if (n is not None):
        sqlform += '    ORDER    BY    session    DESC,    line    DESC    LIMIT    ?'
        params += (n,)
    elif unique:
        sqlform += '    ORDER    BY    session,    line'
    cur = self._run_sql(sqlform, params, raw=raw, output=output)
    if (n is not None):
        return reversed(list(cur))
    return cur
