From 74e89693ffa88ce054d598cc3fbcf7fbb088fdc8 Mon Sep 17 00:00:00 2001 From: j Date: Tue, 29 Jan 2019 19:11:51 +0530 Subject: [PATCH] bad win32 fulltext search --- oml/fulltext.py | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/oml/fulltext.py b/oml/fulltext.py index d7d6d3e..d1cd5ee 100644 --- a/oml/fulltext.py +++ b/oml/fulltext.py @@ -7,15 +7,30 @@ from sqlalchemy.sql import operators logger = logging.getLogger(__name__) -def find_fulltext_macos(query): + +def get_prefix(): import settings + return os.path.join(os.path.expanduser(settings.preferences['libraryPath']), 'Books/') + +def get_ids(books): 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] books = subprocess.check_output(cmd).decode().strip().split('\n') 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 ids + return get_ids(books) + +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): ids = []