An open source, non-profit web search engine
Add a component of the HN domain score when ranking
Daoud Clarkee6655101ef53
diff --git a/config/tinysearchengine.yaml b/config/tinysearchengine.yamlindex e4d29b3..3aa8320 100644--- a/config/tinysearchengine.yaml+++ b/config/tinysearchengine.yaml@@ -8,5 +8,5 @@ server_config:index_config:index_path: data/index.tinysearch- num_pages: 25600- page_size: 4096\ No newline at end of file+ num_pages: 256000+ page_size: 40960\ No newline at end of filediff --git a/mwmbl/indexer/domains.py b/mwmbl/indexer/domains.pyindex 5cd7294..20ae997 100644--- a/mwmbl/indexer/domains.py+++ b/mwmbl/indexer/domains.py@@ -11,7 +11,7 @@ import pandas as pdDATA_DIR = Path(os.environ['HOME']) / 'data' / 'tinysearch'ALL_DOMAINS_PATH = DATA_DIR / 'hn-top-domains.csv'-TOP_DOMAINS_PATH = 'hn-top-domains-filtered.py'+TOP_DOMAINS_PATH = '../tinysearchengine/hn_top_domains_filtered.py'MIN_COUNT = 10PROBABILITY_THRESHOLD = 0.8diff --git a/mwmbl/indexer/extract.py b/mwmbl/indexer/extract.pyindex 8c3a70d..a397e05 100644--- a/mwmbl/indexer/extract.py+++ b/mwmbl/indexer/extract.py@@ -11,10 +11,6 @@ from pyspark.sql.types import StructType, StructField, StringType, LongType, IntRECORDS_PATH = 's3://tinysearch/outputs/records'OUTPUT_PATH = 's3://tinysearch/outputs/index'-NUM_PAGES = 1024-MAX_RESULTS_PER_HASH = 200-PAGE_SIZE = 4096-index_schema = StructType([StructField("term_hash", LongType(), False),diff --git a/mwmbl/tinysearchengine/create_app.py b/mwmbl/tinysearchengine/create_app.pyindex 7af8e9f..e5daa16 100644--- a/mwmbl/tinysearchengine/create_app.py+++ b/mwmbl/tinysearchengine/create_app.py@@ -2,11 +2,13 @@ import refrom logging import getLoggerfrom operator import itemgetterfrom pathlib import Path+from urllib.parse import urlparsefrom fastapi import FastAPIfrom starlette.responses import FileResponsefrom starlette.staticfiles import StaticFiles+from mwmbl.tinysearchengine.hn_top_domains_filtered import DOMAINSfrom mwmbl.tinysearchengine.indexer import TinyIndex, Documentlogger = getLogger(__name__)@@ -49,6 +51,9 @@ def create(tiny_index: TinyIndex):return patterndef score_result(terms, result: Document):+ domain = urlparse(result.url).netloc+ domain_score = DOMAINS.get(domain, 0.0)+result_string = f"{result.title.strip()} {result.extract.strip()}"query_regex = get_query_regex(terms)matches = list(re.finditer(query_regex, result_string, flags=re.IGNORECASE))@@ -64,7 +69,7 @@ def create(tiny_index: TinyIndex):seen_matches.add(value)total_possible_match_length = sum(len(x) for x in terms)- score = (match_length + 1./last_match_char) / (total_possible_match_length + 1)+ score = 0.1*domain_score + 0.9*(match_length + 1./last_match_char) / (total_possible_match_length + 1)return scoredef order_results(terms: list[str], results: list[Document]):diff --git a/mwmbl/indexer/hn-top-domains-filtered.py b/mwmbl/tinysearchengine/hn_top_domains_filtered.pysimilarity index 100%rename from mwmbl/indexer/hn-top-domains-filtered.pyrename to mwmbl/tinysearchengine/hn_top_domains_filtered.py