|
|
@ -11,18 +11,27 @@ ext_database = sqlite3.connect(DB_PATH) |
|
|
def init_db(): |
|
|
def init_db(): |
|
|
cur = ext_database.cursor() |
|
|
cur = ext_database.cursor() |
|
|
cur.execute('CREATE TABLE IF NOT EXISTS updates ( `ext` TEXT, `update_time` INTEGER, `file_count` INTEGER);') |
|
|
cur.execute('CREATE TABLE IF NOT EXISTS updates ( `ext` TEXT, `update_time` INTEGER, `file_count` INTEGER);') |
|
|
def regexp(expr, item): |
|
|
|
|
|
return re.search(expr,item) is not None |
|
|
|
|
|
def _in(expr,item): |
|
|
|
|
|
return (1 if item in expr else 0) |
|
|
|
|
|
ext_database.create_function("REGEXP", 2, regexp) |
|
|
|
|
|
ext_database.create_function("INSIDE", 2, _in) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def regexp(expr, item,case): |
|
|
|
|
|
if case: |
|
|
|
|
|
return (1 if re.search(expr,item) is not None else 0) |
|
|
|
|
|
else: |
|
|
|
|
|
return (1 if re.search(expr,item,flags=re.I) is not None else 0) |
|
|
|
|
|
def _in(expr,item,case): |
|
|
|
|
|
if case: |
|
|
|
|
|
return (1 if expr in item else 0) |
|
|
|
|
|
else: |
|
|
|
|
|
return (1 if expr.lower() in item else 0) |
|
|
|
|
|
|
|
|
|
|
|
ext_database.create_function("REGEXP", 3, regexp) |
|
|
|
|
|
ext_database.create_function("INSIDE", 3, _in) |
|
|
|
|
|
|
|
|
class Searcher: |
|
|
class Searcher: |
|
|
|
|
|
|
|
|
def __init__(self,ext): |
|
|
|
|
|
|
|
|
def __init__(self,ext,case_sensitive=True): |
|
|
self.cur = ext_database.cursor() |
|
|
self.cur = ext_database.cursor() |
|
|
self.ext = ext |
|
|
self.ext = ext |
|
|
|
|
|
self.case = case_sensitive |
|
|
self.index = '{}_index'.format(ext) |
|
|
self.index = '{}_index'.format(ext) |
|
|
self.__init_table__() |
|
|
self.__init_table__() |
|
|
|
|
|
|
|
|
@ -34,7 +43,6 @@ class Searcher: |
|
|
{'ext':self.ext} |
|
|
{'ext':self.ext} |
|
|
) |
|
|
) |
|
|
self.commit() |
|
|
self.commit() |
|
|
|
|
|
|
|
|
def update(self,update_mtimes): |
|
|
def update(self,update_mtimes): |
|
|
self.cur.execute('SELECT MAX(update_time) FROM updates WHERE ext=?;',[self.ext]) |
|
|
self.cur.execute('SELECT MAX(update_time) FROM updates WHERE ext=?;',[self.ext]) |
|
|
last_update = self.cur.fetchone()[0] |
|
|
last_update = self.cur.fetchone()[0] |
|
|
@ -58,9 +66,9 @@ class Searcher: |
|
|
|
|
|
|
|
|
def search(self,query,regex=False): |
|
|
def search(self,query,regex=False): |
|
|
if regex: |
|
|
if regex: |
|
|
self.cur.execute('SELECT name,fullpath FROM {} WHERE name REGEXP ?;'.format(self.ext),[query]) |
|
|
|
|
|
|
|
|
self.cur.execute('SELECT name,fullpath FROM {} WHERE REGEXP(?,name,?)=1;'.format(self.ext),[query,self.case]) |
|
|
else: |
|
|
else: |
|
|
self.cur.execute('SELECT name,fullpath FROM {} WHERE INSIDE(name,?)=1;'.format(self.ext),[query]) |
|
|
|
|
|
|
|
|
self.cur.execute('SELECT name,fullpath FROM {} WHERE INSIDE(?,name,?)=1;'.format(self.ext),[query,self.case]) |
|
|
return self.cur.fetchall() |
|
|
return self.cur.fetchall() |
|
|
|
|
|
|
|
|
def clean(self,backhistory): |
|
|
def clean(self,backhistory): |
|
|
|