mirror of
https://github.com/venthur/blag.git
synced 2025-11-26 13:13:06 +00:00
Compare commits
4 Commits
performanc
...
search
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8656780e5b | ||
|
|
ff1099de60 | ||
|
|
a0374a777e | ||
|
|
55eb9d7482 |
46
blag/blag.py
46
blag/blag.py
@@ -10,6 +10,7 @@ import configparser
|
|||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
|
import sqlite3
|
||||||
import sys
|
import sys
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
@@ -284,6 +285,8 @@ def build(args: argparse.Namespace) -> None:
|
|||||||
generate_index(articles, index_template, args.output_dir)
|
generate_index(articles, index_template, args.output_dir)
|
||||||
generate_archive(articles, archive_template, args.output_dir)
|
generate_archive(articles, archive_template, args.output_dir)
|
||||||
generate_tags(articles, tags_template, tag_template, args.output_dir)
|
generate_tags(articles, tags_template, tag_template, args.output_dir)
|
||||||
|
generate_search(articles, pages, 'corpus.db')
|
||||||
|
logger.info("Done.")
|
||||||
|
|
||||||
|
|
||||||
def process_markdown(
|
def process_markdown(
|
||||||
@@ -511,5 +514,48 @@ def generate_tags(
|
|||||||
fh.write(result)
|
fh.write(result)
|
||||||
|
|
||||||
|
|
||||||
|
def generate_search(
|
||||||
|
articles: list[tuple[str, dict[str, Any]]],
|
||||||
|
pages: list[tuple[str, dict[str, Any]]],
|
||||||
|
db: str,
|
||||||
|
) -> None:
|
||||||
|
"""Generate Search.
|
||||||
|
|
||||||
|
Parameters
|
||||||
|
----------
|
||||||
|
articles, pages
|
||||||
|
db
|
||||||
|
path to sqlite file
|
||||||
|
|
||||||
|
"""
|
||||||
|
logger.info("Generating full text search.")
|
||||||
|
conn = sqlite3.connect(db)
|
||||||
|
with conn:
|
||||||
|
conn.executescript("""
|
||||||
|
drop table if exists corpus;
|
||||||
|
|
||||||
|
create virtual table corpus using fts5(
|
||||||
|
link,
|
||||||
|
text,
|
||||||
|
tokenize = porter
|
||||||
|
);
|
||||||
|
""")
|
||||||
|
|
||||||
|
with conn:
|
||||||
|
for dst, context in articles:
|
||||||
|
text = context['content']
|
||||||
|
conn.execute("""
|
||||||
|
insert into corpus(link, text)
|
||||||
|
values(:link, :text)
|
||||||
|
""", dict(link=dst, text=text))
|
||||||
|
|
||||||
|
for dst, context in pages:
|
||||||
|
text = context['content']
|
||||||
|
conn.execute("""
|
||||||
|
insert into corpus(link, text)
|
||||||
|
values(:link, :text)
|
||||||
|
""", dict(link=dst, text=text))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|||||||
Reference in New Issue
Block a user