bad win32 fulltext search
This commit is contained in:
parent
5bf87bc64d
commit
74e89693ff
1 changed files with 19 additions and 4 deletions
|
@ -7,15 +7,30 @@ from sqlalchemy.sql import operators
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
def find_fulltext_macos(query):
|
|
||||||
|
def get_prefix():
|
||||||
import settings
|
import settings
|
||||||
|
return os.path.join(os.path.expanduser(settings.preferences['libraryPath']), 'Books/')
|
||||||
|
|
||||||
|
def get_ids(books):
|
||||||
from item.models import File
|
from item.models import File
|
||||||
prefix = os.path.join(os.path.expanduser(settings.preferences['libraryPath']), 'Books/')
|
ids = [b[0] for b in File.query.filter(operators.in_op(File.path, books)).values('sha1')]
|
||||||
|
return ids
|
||||||
|
|
||||||
|
def find_fulltext_macos(query):
|
||||||
|
prefix = get_prefix()
|
||||||
cmd = ["mdfind", "-onlyin", prefix, query]
|
cmd = ["mdfind", "-onlyin", prefix, query]
|
||||||
books = subprocess.check_output(cmd).decode().strip().split('\n')
|
books = subprocess.check_output(cmd).decode().strip().split('\n')
|
||||||
books = [path[len(prefix):] for path in books]
|
books = [path[len(prefix):] for path in books]
|
||||||
ids = [b[0] for b in File.query.filter(operators.in_op(File.path, books)).values('sha1')]
|
return get_ids(books)
|
||||||
return ids
|
|
||||||
|
def find_fulltext_windows(query):
|
||||||
|
prefix = get_prefix()
|
||||||
|
prefix = os.path.normpath(prefix)
|
||||||
|
cmd = ['findstr', '/i', '/c:' + query, '/d:' + prefix]
|
||||||
|
books = subprocess.check_output(cmd).decode().strip().split('\n')
|
||||||
|
books = [b.split(':')[0] for b in books]
|
||||||
|
return get_ids(books, prefix)
|
||||||
|
|
||||||
def find_fulltext(query):
|
def find_fulltext(query):
|
||||||
ids = []
|
ids = []
|
||||||
|
|
Loading…
Reference in a new issue