distribusi-verse: medium-tech web app content management system for the web
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

52 lines
1.4 KiB

import os
from whoosh.fields import *
from whoosh.index import create_in
from whoosh.qparser import QueryParser
from models.distribusi_model import Distribusis
import flask_apscheduler
SCRIPT_DIR = os.path.dirname(__file__)
SEARCH_DATA_DIR = os.path.abspath(os.path.join(SCRIPT_DIR, "searchdata"))
def init_search_index(APP):
scheduler = flask_apscheduler.APScheduler()
scheduler.api_enabled = False
scheduler.init_app(APP)
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(
title=TEXT(stored=True), path=ID(stored=True), content=TEXT
)
ix = create_in(SEARCH_DATA_DIR, schema)
writer = ix.writer()
distribusis = _visible_distribusis(APP)
for distribusi in distribusis:
writer.add_document(
title=distribusi.distribusiname,
path="/a",
content=distribusi.description,
)
writer.commit()
def index_distribusi_files(APP):
APP.logger.info("searching distribusi files not implemented yet.")
def _visible_distribusis(APP):
with APP.app_context():
distribusis = Distribusis.query.filter(
Distribusis.visible.isnot(False)
).all()
return distribusis