|
@ -3,6 +3,7 @@ from whoosh.fields import * |
|
|
from whoosh.index import create_in |
|
|
from whoosh.index import create_in |
|
|
from whoosh.qparser import QueryParser |
|
|
from whoosh.qparser import QueryParser |
|
|
from models.distribusi_model import Distribusis |
|
|
from models.distribusi_model import Distribusis |
|
|
|
|
|
from models.distribusi_file_model import DistribusiFiles |
|
|
import flask_apscheduler |
|
|
import flask_apscheduler |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -15,21 +16,26 @@ def init_search_index(APP): |
|
|
scheduler.api_enabled = False |
|
|
scheduler.api_enabled = False |
|
|
scheduler.init_app(APP) |
|
|
scheduler.init_app(APP) |
|
|
scheduler.start() |
|
|
scheduler.start() |
|
|
index_distribusis(APP) |
|
|
|
|
|
index_distribusi_files(APP) |
|
|
|
|
|
|
|
|
|
|
|
@scheduler.task("interval", id="update", minutes=60) |
|
|
|
|
|
def update_search_index(): |
|
|
|
|
|
index_distribusis(APP) |
|
|
|
|
|
index_distribusi_files(APP) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def index_distribusis(APP): |
|
|
|
|
|
schema = Schema( |
|
|
schema = Schema( |
|
|
title=TEXT(stored=True), path=ID(stored=True), content=TEXT |
|
|
title=TEXT(stored=True), path=ID(stored=True), content=TEXT |
|
|
) |
|
|
) |
|
|
ix = create_in(SEARCH_DATA_DIR, schema) |
|
|
ix = create_in(SEARCH_DATA_DIR, schema) |
|
|
writer = ix.writer() |
|
|
writer = ix.writer() |
|
|
|
|
|
index_distribusis(APP, writer) |
|
|
|
|
|
index_distribusi_files(APP, writer) |
|
|
|
|
|
writer.commit(optimize=True) |
|
|
|
|
|
|
|
|
|
|
|
@scheduler.task("interval", id="update", minutes=60) |
|
|
|
|
|
def update_search_index(): |
|
|
|
|
|
ix = index.open_dir(SEARCH_DATA_DIR) |
|
|
|
|
|
update_writer = ix.writer() |
|
|
|
|
|
index_distribusis(APP, update_writer) |
|
|
|
|
|
index_distribusi_files(APP, update_writer) |
|
|
|
|
|
update_writer.commit(optimize=True) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def index_distribusis(APP, writer): |
|
|
distribusis = _visible_distribusis(APP) |
|
|
distribusis = _visible_distribusis(APP) |
|
|
for distribusi in distribusis: |
|
|
for distribusi in distribusis: |
|
|
writer.add_document( |
|
|
writer.add_document( |
|
@ -37,11 +43,19 @@ def index_distribusis(APP): |
|
|
path="/a", |
|
|
path="/a", |
|
|
content=distribusi.description, |
|
|
content=distribusi.description, |
|
|
) |
|
|
) |
|
|
writer.commit(optimize=True) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def index_distribusi_files(APP): |
|
|
def index_distribusi_files(APP, writer): |
|
|
APP.logger.info("searching distribusi files not implemented yet.") |
|
|
with APP.app_context(): |
|
|
|
|
|
for distribusi_file in DistribusiFiles.query.all(): |
|
|
|
|
|
APP.logger.info( |
|
|
|
|
|
f"adding distribusi file {distribusi_file.path} to search index" |
|
|
|
|
|
) |
|
|
|
|
|
writer.add_document( |
|
|
|
|
|
title=distribusi_file.path, |
|
|
|
|
|
path="/b", |
|
|
|
|
|
content=distribusi_file.description, |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _visible_distribusis(APP): |
|
|
def _visible_distribusis(APP): |
|
|