bad win32 fulltext search

This commit is contained in:
j 2019-01-29 19:11:51 +05:30
parent 5bf87bc64d
commit 74e89693ff

View file

@ -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 = []