geminispace.info

gemini search engine
git clone https://git.clttr.info/geminispace.info.git
Log (Feed) | Files | Refs (Tags) | README | LICENSE

commit dc4a32429ccd4d547319e6aacb54e500dd04ff37
parent dd46f0e29bf49df3637eccb28477d409c6e698d7
Author: Natalie Pendragon <natpen@natpen.net>
Date:   Wed,  3 Jun 2020 10:47:33 -0400

[serve] Use "OR" as the default connector for queries

Diffstat:
Mgus/serve.py | 16+++++++++++++---
1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/gus/serve.py b/gus/serve.py @@ -13,9 +13,8 @@ from urllib.parse import quote import jetforce from jetforce import Response, Status -from whoosh import highlight +from whoosh import highlight, qparser from whoosh.index import open_dir -from whoosh.qparser import MultifieldParser from gus.crawl import run_crawl from gus.lib.index_statistics import compute_index_statistics, load_last_statistics_from_file @@ -245,7 +244,7 @@ def index(request): def _search_index(query, requested_page): - query = MultifieldParser(["content", "url", "prompt"], ix.schema).parse(query) + query = query_parser.parse(query) results = searcher.search_page(query, requested_page, pagelen=10) return ( len(results), @@ -425,10 +424,21 @@ def main(): hostname=args.hostname, app=app, ) + global ix ix = open_dir(INDEX_DIR) + + global query_parser + or_group = qparser.OrGroup.factory(0.9) + query_parser = qparser.MultifieldParser(["content", "url", "prompt"], ix.schema, group=or_group) + query_parser.add_plugin(qparser.RegexPlugin()) + query_parser.remove_plugin_class(qparser.WildcardPlugin) + query_parser.remove_plugin_class(qparser.BoostPlugin) + query_parser.remove_plugin_class(qparser.RangePlugin) + global index_modification_time index_modification_time = _get_index_modification_time() + global searcher with ix.searcher() as searcher: asyncio.run(server.run())