openmedialibrary/oml/fulltext.py

30 lines
872 B
Python
Raw Normal View History

2019-01-15 08:38:42 +00:00
import logging
import os
import subprocess
import sys
2019-01-15 08:43:52 +00:00
from sqlalchemy.sql import operators
2019-01-15 08:38:42 +00:00
logger = logging.getLogger(__name__)
def find_fulltext_macos(query):
import settings
from item.models import File
prefix = os.path.join(os.path.expanduser(settings.preferences['libraryPath']), 'Books/')
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
def find_fulltext(query):
ids = []
if sys.platform == 'darwin':
ids = find_fulltext_macos(query)
else:
logger.debug('missing fulltext search implementation for %s', sys.platform)
return ids
def platform_supported():
return sys.platform == 'darwin'