eldoc/mods/catalogs.py

25 lines
621 B
Python
Raw Normal View History

from mods.db import db, Catalog, CatalogIndex
2019-11-12 21:39:26 +03:00
def add_catalog(name):
with db.atomic():
catalog = Catalog.create(name=name)
CatalogIndex.insert(
{
CatalogIndex.rowid: catalog.id,
CatalogIndex.text: name
}
).execute()
2019-11-12 21:39:26 +03:00
return catalog
def search_catalogs(q):
with db.atomic():
return (Catalog.select()
.join(
CatalogIndex,
on=(Catalog.id == CatalogIndex.rowid))
.where(CatalogIndex.match(q))
.order_by(CatalogIndex.bm25()))
2019-11-12 21:39:26 +03:00