diff --git a/search_app.py b/search_app.py index 730847d..da2d97e 100644 --- a/search_app.py +++ b/search_app.py @@ -384,6 +384,7 @@ def build_query_payload( use_fuzzy: bool = True, use_phrase: bool = True, use_query_string: bool = False, + include_external: bool = True, ) -> Dict: filters: List[Dict] = [] should: List[Dict] = [] @@ -396,6 +397,9 @@ def build_query_payload( if year_filter: filters.append(year_filter) + if not include_external: + filters.append({"bool": {"must_not": [{"term": {"external_reference": True}}]}}) + if use_query_string: base_fields = ["title^3", "description^2", "transcript_full", "transcript_secondary_full"] qs_query = (query or "").strip() or "*" @@ -916,6 +920,7 @@ def create_app(config: AppConfig = CONFIG) -> Flask: use_fuzzy = parse_flag("fuzzy", True) use_phrase = parse_flag("phrase", True) use_query_string = parse_flag("query_string", False) + include_external = parse_flag("external", True) if use_query_string: use_exact = use_fuzzy = use_phrase = False @@ -928,6 +933,7 @@ def create_app(config: AppConfig = CONFIG) -> Flask: use_fuzzy=use_fuzzy, use_phrase=use_phrase, use_query_string=use_query_string, + include_external=include_external, ) start = page * size if config.elastic.debug: @@ -1005,6 +1011,7 @@ def create_app(config: AppConfig = CONFIG) -> Flask: "referenced_by_count": source.get("referenced_by_count", 0), "referenced_by": source.get("referenced_by", []), "video_status": source.get("video_status"), + "external_reference": source.get("external_reference"), } ) @@ -1068,6 +1075,7 @@ def create_app(config: AppConfig = CONFIG) -> Flask: use_exact = parse_flag("exact", True) use_fuzzy = parse_flag("fuzzy", True) use_phrase = parse_flag("phrase", True) + include_external = parse_flag("external", True) if use_query_string: use_exact = use_fuzzy = use_phrase = False @@ -1080,6 +1088,7 @@ def create_app(config: AppConfig = CONFIG) -> Flask: use_fuzzy=use_fuzzy, use_phrase=use_phrase, use_query_string=use_query_string, + include_external=include_external, ) query = search_payload.get("query", {"match_all": {}}) diff --git a/static/app.js b/static/app.js index 4da22d3..328b2a1 100644 --- a/static/app.js +++ b/static/app.js @@ -39,6 +39,7 @@ const exactToggle = document.getElementById("exactToggle"); const fuzzyToggle = document.getElementById("fuzzyToggle"); const phraseToggle = document.getElementById("phraseToggle"); + const externalToggle = document.getElementById("externalToggle"); const queryToggle = document.getElementById("queryStringToggle"); const searchBtn = document.getElementById("searchBtn"); const aboutBtn = document.getElementById("aboutBtn"); @@ -139,6 +140,9 @@ exactToggle.checked = parseBoolParam("exact", true); fuzzyToggle.checked = parseBoolParam("fuzzy", true); phraseToggle.checked = parseBoolParam("phrase", true); + if (externalToggle) { + externalToggle.checked = parseBoolParam("external", true); + } queryToggle.checked = parseBoolParam("query_string", false); applyQueryMode(); rememberToggleState(); @@ -313,7 +317,7 @@ } } - function updateUrl(q, sort, channels, year, page, size, exact, fuzzy, phrase, queryMode) { + function updateUrl(q, sort, channels, year, page, size, exact, fuzzy, phrase, queryMode, includeExternal) { const next = new URL(window.location.href); next.searchParams.set("q", q); next.searchParams.set("sort", sort); @@ -331,6 +335,7 @@ next.searchParams.set("fuzzy", fuzzy ? "1" : "0"); next.searchParams.set("phrase", phrase ? "1" : "0"); next.searchParams.set("query_string", queryMode ? "1" : "0"); + next.searchParams.set("external", includeExternal ? "1" : "0"); history.pushState({}, "", next.toString()); } @@ -1193,10 +1198,11 @@ async function updateFrequencyChart(term, channels, year, queryMode, toggles = { if (queryMode) { params.set("query_string", "1"); } - const { exact = true, fuzzy = true, phrase = true } = toggles || {}; + const { exact = true, fuzzy = true, phrase = true, external = true } = toggles || {}; params.set("exact", exact ? "1" : "0"); params.set("fuzzy", fuzzy ? "1" : "0"); params.set("phrase", phrase ? "1" : "0"); + params.set("external", external ? "1" : "0"); clearFrequency("Loading timeline…"); try { @@ -1250,6 +1256,13 @@ async function updateFrequencyChart(term, channels, year, queryMode, toggles = { const headerMain = document.createElement("div"); headerMain.className = "result-header-main"; const badgeDefs = []; + if (item.external_reference) { + badgeDefs.push({ + label: "External", + badgeType: "external", + title: "Indexed from an external reference source", + }); + } if (item.highlightSource && item.highlightSource.primary) { badgeDefs.push({ label: "primary transcript", badgeType: "transcript-primary" }); } @@ -1516,6 +1529,7 @@ async function updateFrequencyChart(term, channels, year, queryMode, toggles = { let exact = !!exactToggle.checked; let fuzzy = !!fuzzyToggle.checked; let phrase = !!phraseToggle.checked; + const includeExternal = externalToggle ? externalToggle.checked : true; if (queryMode) { exact = false; fuzzy = false; @@ -1531,7 +1545,19 @@ async function updateFrequencyChart(term, channels, year, queryMode, toggles = { currentPage = page; if (pushState) { - updateUrl(q, sort, channels, year, page, size, exact, fuzzy, phrase, queryMode); + updateUrl( + q, + sort, + channels, + year, + page, + size, + exact, + fuzzy, + phrase, + queryMode, + includeExternal + ); } const params = new URLSearchParams(); @@ -1543,13 +1569,14 @@ async function updateFrequencyChart(term, channels, year, queryMode, toggles = { params.set("fuzzy", fuzzy ? "1" : "0"); params.set("phrase", phrase ? "1" : "0"); params.set("query_string", queryMode ? "1" : "0"); + params.set("external", includeExternal ? "1" : "0"); channels.forEach((id) => params.append("channel_id", id)); if (year) params.set("year", year); const res = await fetch(`/api/search?${params.toString()}`); const payload = await res.json(); renderResults(payload, page); - updateFrequencyChart(q, channels, year, queryMode, { exact, fuzzy, phrase }); + updateFrequencyChart(q, channels, year, queryMode, { exact, fuzzy, phrase, external: includeExternal }); } searchBtn.addEventListener("click", () => runSearch(0)); @@ -1580,6 +1607,9 @@ async function updateFrequencyChart(term, channels, year, queryMode, toggles = { exactToggle.addEventListener("change", () => { rememberToggleState(); runSearch(0); }); fuzzyToggle.addEventListener("change", () => { rememberToggleState(); runSearch(0); }); phraseToggle.addEventListener("change", () => { rememberToggleState(); runSearch(0); }); + if (externalToggle) { + externalToggle.addEventListener("change", () => runSearch(0)); + } if (queryToggle) { queryToggle.addEventListener("change", () => { applyQueryMode(); runSearch(0); }); } diff --git a/static/index.html b/static/index.html index 217b382..f237563 100644 --- a/static/index.html +++ b/static/index.html @@ -81,6 +81,12 @@ Boost exact phrases inside transcripts. +