web search done right
Feedback when optic parsing fails
Mikkel Denker7567acdc937a
diff --git a/core/benches/search-preindexed-optic.rs b/core/benches/search-preindexed-optic.rsindex 36447e83..2659d427 100644--- a/core/benches/search-preindexed-optic.rs+++ b/core/benches/search-preindexed-optic.rs@@ -1,4 +1,5 @@use criterion::{criterion_group, criterion_main, Criterion};+use optics::Optic;use stract::{index::Index,searcher::{LocalSearcher, SearchQuery},@@ -17,7 +18,7 @@ macro_rules! bench {$searcher.search(&SearchQuery {query: $query.to_string(),- optic: Some($optic.to_string()),+ optic: Some(Optic::parse($optic).unwrap()),..Default::default()}).unwrap()diff --git a/core/src/api/search.rs b/core/src/api/search.rsindex e9322171..7ea76e1c 100644--- a/core/src/api/search.rs+++ b/core/src/api/search.rs@@ -15,7 +15,7 @@// along with this program. If not, see <https://www.gnu.org/licenses/>.use http::{StatusCode, Uri};-use optics::SiteRankings;+use optics::{Optic, SiteRankings};use std::{collections::HashMap, sync::Arc};use axum::Json;@@ -61,6 +61,7 @@ struct SearchTemplate {default_optics: Vec<OpticLink>,has_more_results: bool,has_code: bool,+ alerts: Vec<String>,}enum RegionSelection {@@ -105,13 +106,23 @@ pub async fn route(.unwrap_or_default();let mut optic = None;+ let mut alerts = Vec::new();if let Some(url) = params.get("optic") {if !url.is_empty() {if let Ok(res) = reqwest::get(url).await {if let Ok(text) = res.text().await {- optic = Some(text);+ match Optic::parse(&text) {+ Ok(parsed_optic) => optic = Some(parsed_optic),+ Err(err) => {+ alerts.push(format!("Could not parse optic: {}", err));+ }+ }+ } else {+ alerts.push("Could not retrieve optic as text".to_string());}+ } else {+ alerts.push("Could not retrieve optic".to_string());}}}@@ -170,6 +181,7 @@ pub async fn route(default_optics: DEFAULT_OPTICS.to_vec(),has_more_results: result.has_more_results,has_code,+ alerts,};Ok(HtmlTemplate(template).into_response())@@ -183,7 +195,6 @@ pub async fn route(}Err(err) => {tracing::error!("{:?}", err);-Err(StatusCode::INTERNAL_SERVER_ERROR)}}@@ -245,23 +256,66 @@ fn next_page_url(uri: &Uri, params: HashMap<String, String>, skip_pages: usize)next_page_url}+#[derive(Debug, serde::Serialize, serde::Deserialize)]+pub struct ApiSearchQuery {+ pub query: String,+ pub page: usize,+ pub num_results: usize,+ pub selected_region: Option<Region>,+ pub optic: Option<String>,+ pub site_rankings: Option<SiteRankings>,+ pub return_ranking_signals: bool,+}++impl TryFrom<ApiSearchQuery> for SearchQuery {+ type Error = crate::Error;++ fn try_from(api: ApiSearchQuery) -> Result<Self, Self::Error> {+ let optic = if let Some(optic) = &api.optic {+ Some(Optic::parse(optic)?)+ } else {+ None+ };++ Ok(SearchQuery {+ query: api.query,+ page: api.page,+ num_results: api.num_results,+ selected_region: api.selected_region,+ optic,+ site_rankings: api.site_rankings,+ return_ranking_signals: api.return_ranking_signals,+ })+ }+}+#[allow(clippy::unused_async)]#[allow(clippy::match_wild_err_arm)]#[debug_handler]pub async fn api(extract::State(state): extract::State<Arc<State>>,- extract::Json(mut query): extract::Json<SearchQuery>,-) -> impl IntoResponse {+ extract::Json(mut query): extract::Json<ApiSearchQuery>,+) -> Result<impl IntoResponse, StatusCode> {query.num_results = query.num_results.min(50 * NUM_RESULTS_PER_PAGE);+ let query = SearchQuery::try_from(query);++ if let Err(err) = query {+ tracing::error!("{:?}", err);+ return Ok(err.to_string().into_response());+ }++ let query = query.unwrap();match state.searcher.search(&query).await {- Ok(result) => match result {- SearchResult::Websites(result) => Json(result).into_response(),- SearchResult::Bang(result) => Redirect::to(&result.redirect_to.full()).into_response(),- },+ Ok(result) => Ok(Json(result).into_response()),Err(Error::DistributedSearcher(searcher::distributed::Error::EmptyQuery)) => {- Redirect::to("/").into_response()+ Ok(searcher::distributed::Error::EmptyQuery+ .to_string()+ .into_response())+ }+ Err(err) => {+ tracing::error!("{:?}", err);+ Err(StatusCode::INTERNAL_SERVER_ERROR)}- Err(_) => panic!("Search failed"), // TODO: show 500 status to user here}}diff --git a/core/src/query/mod.rs b/core/src/query/mod.rsindex 80595c86..bff62667 100644--- a/core/src/query/mod.rs+++ b/core/src/query/mod.rs@@ -94,9 +94,8 @@ impl Query {optics.push(site_rankigns_optic);}- if let Some(optic_program) = &query.optic {- let optic = Optic::parse(optic_program)?;- optics.push(optic);+ if let Some(optic) = &query.optic {+ optics.push(optic.clone());}for optic in &optics {diff --git a/core/src/query/optic.rs b/core/src/query/optic.rsindex db365023..cb6d25c4 100644--- a/core/src/query/optic.rs+++ b/core/src/query/optic.rs@@ -206,7 +206,7 @@ impl AsTantivyQuery for Matching {#[cfg(test)]mod tests {- use optics::SiteRankings;+ use optics::{Optic, SiteRankings};use crate::{gen_temp_path,@@ -304,15 +304,17 @@ mod tests {.search(&SearchQuery {query: "website".to_string(),optic: Some(- r#"+ Optic::parse(+ r#"Rule {Matches {Domain("b.com")},Action(Discard)}- "#- .to_string(),+ "#,+ )+ .unwrap(),),..Default::default()})@@ -326,15 +328,17 @@ mod tests {.search(&SearchQuery {query: "website".to_string(),optic: Some(- r#"+ Optic::parse(+ r#"Rule {Matches {Domain("a.com")},Action(Boost(10))}- "#- .to_string(),+ "#,+ )+ .unwrap(),),..Default::default()})@@ -416,7 +420,10 @@ mod tests {let _ = searcher.search(&SearchQuery {query: "website".to_string(),- optic: Some(include_str!("../../../optics/testcases/quickstart.optic").to_string()),+ optic: Some(+ Optic::parse(include_str!("../../../optics/testcases/quickstart.optic"))+ .unwrap(),+ ),..Default::default()}).unwrap()@@ -426,7 +433,8 @@ mod tests {.search(&SearchQuery {query: "website".to_string(),optic: Some(- include_str!("../../../optics/testcases/hacker_news.optic").to_string(),+ Optic::parse(include_str!("../../../optics/testcases/hacker_news.optic"))+ .unwrap(),),..Default::default()})@@ -437,7 +445,10 @@ mod tests {.search(&SearchQuery {query: "website".to_string(),optic: Some(- include_str!("../../../optics/testcases/copycats_removal.optic").to_string(),+ Optic::parse(include_str!(+ "../../../optics/testcases/copycats_removal.optic"+ ))+ .unwrap(),),..Default::default()})@@ -548,7 +559,8 @@ mod tests {.search(&SearchQuery {query: "website".to_string(),optic: Some(- r#"+ Optic::parse(+ r#"DiscardNonMatching;Rule {Matches {@@ -562,8 +574,9 @@ mod tests {},Action(Boost(1))};- "#- .to_string(),+ "#,+ )+ .unwrap(),),..Default::default()})@@ -697,12 +710,14 @@ mod tests {.search(&SearchQuery {query: "website".to_string(),optic: Some(- r#"+ Optic::parse(+ r#"Like(Site("www.a.com"));Like(Site("www.b.com"));Dislike(Site("www.c.com"));- "#- .to_string(),+ "#,+ )+ .unwrap(),),..Default::default()})@@ -815,15 +830,17 @@ mod tests {.search(&SearchQuery {query: "website".to_string(),optic: Some(- r#"+ Optic::parse(+ r#"DiscardNonMatching;Rule {Matches {Schema("BlogPosting")}}- "#- .to_string(),+ "#,+ )+ .unwrap(),),..Default::default()})@@ -837,15 +854,17 @@ mod tests {.search(&SearchQuery {query: "website".to_string(),optic: Some(- r#"+ Optic::parse(+ r#"DiscardNonMatching;Rule {Matches {Schema("BlogPosting.comment")}}- "#- .to_string(),+ "#,+ )+ .unwrap(),),..Default::default()})@@ -859,15 +878,17 @@ mod tests {.search(&SearchQuery {query: "website".to_string(),optic: Some(- r#"+ Optic::parse(+ r#"DiscardNonMatching;Rule {Matches {Schema("ImageObject")}}- "#- .to_string(),+ "#,+ )+ .unwrap(),),..Default::default()})@@ -881,15 +902,17 @@ mod tests {.search(&SearchQuery {query: "website".to_string(),optic: Some(- r#"+ Optic::parse(+ r#"DiscardNonMatching;Rule {Matches {Schema("Person")}}- "#- .to_string(),+ "#,+ )+ .unwrap(),),..Default::default()})@@ -943,7 +966,8 @@ mod tests {.search(&SearchQuery {query: "site:stackoverflow.com".to_string(),optic: Some(- r#"+ Optic::parse(+ r#"DiscardNonMatching;Rule {Matches {@@ -963,8 +987,9 @@ mod tests {},Action(Boost(1))};- "#- .to_string(),+ "#,+ )+ .unwrap(),),..Default::default()})@@ -1048,15 +1073,17 @@ mod tests {.search(&SearchQuery {query: "example".to_string(),optic: Some(- r#"+ Optic::parse(+ r#"DiscardNonMatching;Rule {Matches {Site("b.com")}};- "#- .to_string(),+ "#,+ )+ .unwrap(),),site_rankings: Some(SiteRankings {liked: vec!["a.com".to_string()],@@ -1111,7 +1138,7 @@ mod tests {let res = searcher.search(&SearchQuery {query: "avengers endgame".to_string(),- optic: Some(include_str!("../searcher/discussions.optic").to_string()),+ optic: Some(Optic::parse(include_str!("../searcher/discussions.optic")).unwrap()),..Default::default()}).unwrap()@@ -1170,7 +1197,9 @@ mod tests {let res = searcher.search(&SearchQuery {query: "example".to_string(),- optic: Some("Rule { Matches { Title(\"is\") }, Action(Discard) }".to_string()),+ optic: Some(+ Optic::parse("Rule { Matches { Title(\"is\") }, Action(Discard) }").unwrap(),+ ),..Default::default()}).unwrap()@@ -1180,7 +1209,9 @@ mod tests {let res = searcher.search(&SearchQuery {query: "example".to_string(),- optic: Some("Rule { Matches { Title(\"|is\") }, Action(Discard) }".to_string()),+ optic: Some(+ Optic::parse("Rule { Matches { Title(\"|is\") }, Action(Discard) }").unwrap(),+ ),..Default::default()}).unwrap()@@ -1190,7 +1221,9 @@ mod tests {let res = searcher.search(&SearchQuery {query: "example".to_string(),- optic: Some("Rule { Matches { Title(\"|This\") }, Action(Discard) }".to_string()),+ optic: Some(+ Optic::parse("Rule { Matches { Title(\"|This\") }, Action(Discard) }").unwrap(),+ ),..Default::default()}).unwrap()@@ -1201,7 +1234,8 @@ mod tests {.search(&SearchQuery {query: "example".to_string(),optic: Some(- "Rule { Matches { Title(\"|This an\") }, Action(Discard) }".to_string(),+ Optic::parse("Rule { Matches { Title(\"|This an\") }, Action(Discard) }")+ .unwrap(),),..Default::default()})@@ -1213,7 +1247,8 @@ mod tests {.search(&SearchQuery {query: "example".to_string(),optic: Some(- "Rule { Matches { Title(\"|This * an\") }, Action(Discard) }".to_string(),+ Optic::parse("Rule { Matches { Title(\"|This * an\") }, Action(Discard) }")+ .unwrap(),),..Default::default()})@@ -1225,7 +1260,8 @@ mod tests {.search(&SearchQuery {query: "example".to_string(),optic: Some(- "Rule { Matches { Site(\"example.com\") }, Action(Discard) }".to_string(),+ Optic::parse("Rule { Matches { Site(\"example.com\") }, Action(Discard) }")+ .unwrap(),),..Default::default()})@@ -1237,7 +1273,8 @@ mod tests {.search(&SearchQuery {query: "example".to_string(),optic: Some(- "Rule { Matches { Site(\"|example.com\") }, Action(Discard) }".to_string(),+ Optic::parse("Rule { Matches { Site(\"|example.com\") }, Action(Discard) }")+ .unwrap(),),..Default::default()})@@ -1249,7 +1286,8 @@ mod tests {.search(&SearchQuery {query: "example".to_string(),optic: Some(- "Rule { Matches { Site(\"|example.com|\") }, Action(Discard) }".to_string(),+ Optic::parse("Rule { Matches { Site(\"|example.com|\") }, Action(Discard) }")+ .unwrap(),),..Default::default()})@@ -1261,7 +1299,8 @@ mod tests {.search(&SearchQuery {query: "example".to_string(),optic: Some(- "Rule { Matches { Title(\"website.com|\") }, Action(Discard) }".to_string(),+ Optic::parse("Rule { Matches { Title(\"website.com|\") }, Action(Discard) }")+ .unwrap(),),..Default::default()})@@ -1313,8 +1352,10 @@ mod tests {.search(&SearchQuery {query: "example".to_string(),optic: Some(- "DiscardNonMatching; Rule { Matches { Title(\"is\") }, Action(Boost(0)) }"- .to_string(),+ Optic::parse(+ "DiscardNonMatching; Rule { Matches { Title(\"is\") }, Action(Boost(0)) }",+ )+ .unwrap(),),..Default::default()})@@ -1326,8 +1367,10 @@ mod tests {.search(&SearchQuery {query: "example".to_string(),optic: Some(- "DiscardNonMatching; Rule { Matches { Title(\"is\") }, Action(Boost(0)) }"- .to_string(),+ Optic::parse(+ "DiscardNonMatching; Rule { Matches { Title(\"is\") }, Action(Boost(0)) }",+ )+ .unwrap(),),site_rankings: Some(SiteRankings {liked: vec![],@@ -1383,7 +1426,7 @@ mod tests {let res = searcher.search(&SearchQuery {query: "example".to_string(),- optic: Some("".to_string()),+ optic: Some(Optic::parse("").unwrap()),..Default::default()}).unwrap()@@ -1393,7 +1436,9 @@ mod tests {let res = searcher.search(&SearchQuery {query: "example".to_string(),- optic: Some("Rule { Matches { Title(\"\") }, Action(Discard) }".to_string()),+ optic: Some(+ Optic::parse("Rule { Matches { Title(\"\") }, Action(Discard) }").unwrap(),+ ),..Default::default()}).unwrap()@@ -1474,7 +1519,9 @@ mod tests {let res = searcher.search(&SearchQuery {query: "example".to_string(),- optic: Some("Rule { Matches { Title(\"*\") }, Action(Discard) }".to_string()),+ optic: Some(+ Optic::parse("Rule { Matches { Title(\"*\") }, Action(Discard) }").unwrap(),+ ),..Default::default()}).unwrap()@@ -1484,7 +1531,9 @@ mod tests {let res = searcher.search(&SearchQuery {query: "example".to_string(),- optic: Some("Rule { Matches { Title(\"* is\") }, Action(Discard) }".to_string()),+ optic: Some(+ Optic::parse("Rule { Matches { Title(\"* is\") }, Action(Discard) }").unwrap(),+ ),..Default::default()}).unwrap()@@ -1495,7 +1544,8 @@ mod tests {.search(&SearchQuery {query: "example".to_string(),optic: Some(- "Rule { Matches { Title(\"* This is\") }, Action(Discard) }".to_string(),+ Optic::parse("Rule { Matches { Title(\"* This is\") }, Action(Discard) }")+ .unwrap(),),..Default::default()})@@ -1507,7 +1557,8 @@ mod tests {.search(&SearchQuery {query: "example".to_string(),optic: Some(- "Rule { Matches { Title(\"example *\") }, Action(Discard) }".to_string(),+ Optic::parse("Rule { Matches { Title(\"example *\") }, Action(Discard) }")+ .unwrap(),),..Default::default()})@@ -1519,8 +1570,10 @@ mod tests {.search(&SearchQuery {query: "example".to_string(),optic: Some(- "Rule { Matches { Title(\"example website *\") }, Action(Discard) }"- .to_string(),+ Optic::parse(+ "Rule { Matches { Title(\"example website *\") }, Action(Discard) }",+ )+ .unwrap(),),..Default::default()})@@ -1579,8 +1632,8 @@ mod tests {.search(&SearchQuery {query: "example".to_string(),optic: Some(- "DiscardNonMatching; Rule { Matches { Content(\"||\") }, Action(Boost(0)) }"- .to_string(),+ Optic::parse("DiscardNonMatching; Rule { Matches { Content(\"||\") }, Action(Boost(0)) }")+ .unwrap(),),..Default::default()})@@ -1592,8 +1645,10 @@ mod tests {.search(&SearchQuery {query: "example".to_string(),optic: Some(- "DiscardNonMatching; Rule { Matches { Content(\"|\") }, Action(Boost(0)) }"- .to_string(),+ Optic::parse(+ "DiscardNonMatching; Rule { Matches { Content(\"|\") }, Action(Boost(0)) }",+ )+ .unwrap(),),..Default::default()})diff --git a/core/src/ranking/mod.rs b/core/src/ranking/mod.rsindex bace881a..3f749a40 100644--- a/core/src/ranking/mod.rs+++ b/core/src/ranking/mod.rs@@ -165,6 +165,8 @@ pub fn online_centrality_scorer(#[cfg(test)]mod tests {+ use optics::Optic;+use crate::{index::Index,searcher::{LocalSearcher, SearchQuery},@@ -772,11 +774,13 @@ mod tests {.search(&SearchQuery {query: "example".to_string(),optic: Some(- r#"+ Optic::parse(+ r#"Ranking(Signal("bm25_title"), 20000000);Ranking(Signal("host_centrality"), 0);- "#- .to_string(),+ "#,+ )+ .unwrap(),),..Default::default()})@@ -789,10 +793,12 @@ mod tests {.search(&SearchQuery {query: "example".to_string(),optic: Some(- r#"+ Optic::parse(+ r#"Ranking(Signal("host_centrality"), 2000000)- "#- .to_string(),+ "#,+ )+ .unwrap(),),..Default::default()})diff --git a/core/src/ranking/pipeline.rs b/core/src/ranking/pipeline.rsindex bce162b0..cbb217ca 100644--- a/core/src/ranking/pipeline.rs+++ b/core/src/ranking/pipeline.rs@@ -172,11 +172,7 @@ impl<T: AsRankingWebsite, M: CrossEncoder> Scorer<T> for ReRanker<M> {fn set_query_info(&mut self, query: &SearchQuery) {self.query = Some(query.clone());- self.signal_coefficients = query- .optic- .as_ref()- .and_then(|p| optics::parse(p.as_str()).ok())- .map(|optic| SignalCoefficient::from_optic(&optic));+ self.signal_coefficients = query.optic.as_ref().map(SignalCoefficient::from_optic);}}@@ -227,11 +223,7 @@ impl<T: AsRankingWebsite> Scorer<T> for Initial {}fn set_query_info(&mut self, query: &SearchQuery) {- self.signal_coefficients = query- .optic- .as_ref()- .and_then(|p| optics::parse(p.as_str()).ok())- .map(|optic| SignalCoefficient::from_optic(&optic));+ self.signal_coefficients = query.optic.as_ref().map(SignalCoefficient::from_optic);}}diff --git a/core/src/searcher/distributed.rs b/core/src/searcher/distributed.rsindex 21cf1703..764ab4cc 100644--- a/core/src/searcher/distributed.rs+++ b/core/src/searcher/distributed.rs@@ -50,6 +50,7 @@ use std::{use futures::stream::FuturesUnordered;use futures::StreamExt;use itertools::intersperse;+use optics::Optic;use serde::{Deserialize, Serialize};use thiserror::Error;@@ -373,7 +374,7 @@ impl DistributedSearcher {let query = SearchQuery {query: query.query.clone(),num_results: 1,- optic: Some(include_str!("stackoverflow.optic").to_string()),+ optic: Some(Optic::parse(include_str!("stackoverflow.optic")).unwrap()),..Default::default()};@@ -473,7 +474,7 @@ impl DistributedSearcher {let mut query = SearchQuery {query: query.query.clone(),num_results: NUM_RESULTS,- optic: Some(include_str!("discussions.optic").to_string()),+ optic: Some(Optic::parse(include_str!("discussions.optic")).unwrap()),site_rankings: query.site_rankings.clone(),return_ranking_signals: query.return_ranking_signals,..Default::default()diff --git a/core/src/searcher/mod.rs b/core/src/searcher/mod.rsindex 1438533d..a6c5cb73 100644--- a/core/src/searcher/mod.rs+++ b/core/src/searcher/mod.rs@@ -19,7 +19,7 @@ pub mod local;pub use distributed::*;pub use local::*;-use optics::SiteRankings;+use optics::{Optic, SiteRankings};use serde::{Deserialize, Serialize};use crate::{@@ -60,7 +60,7 @@ pub struct SearchQuery {pub page: usize,pub num_results: usize,pub selected_region: Option<Region>,- pub optic: Option<String>,+ pub optic: Option<Optic>,pub site_rankings: Option<SiteRankings>,pub return_ranking_signals: bool,}diff --git a/frontend/src/pages/index.astro b/frontend/src/pages/index.astroindex 21881510..654e48f4 100644--- a/frontend/src/pages/index.astro+++ b/frontend/src/pages/index.astro@@ -17,7 +17,7 @@ import OpticSelector from "../components/OpticSelector.astro";<img src="/images/biglogo.svg" class="h-full w-full" /></div><Searchbar autofocus />- <div class="mt-2 text-gray-600 flex space-x-2">+ <div class="mt-3 text-gray-600 flex space-x-2"><div>Customise your search with an <a class="underline font-medium" href="/settings">optic</a>:</div><OpticSelector default_optics="default_optics" search_on_change={false}/></div></div>diff --git a/frontend/src/pages/search.astro b/frontend/src/pages/search.astroindex 1104f2c4..b0c56397 100644--- a/frontend/src/pages/search.astro+++ b/frontend/src/pages/search.astro@@ -11,6 +11,7 @@ import Discussions from "../components/Discussions.astro";import Widget from "../components/Widget.astro";import DirectAnswer from "../components/DirectAnswer.astro";import { askama } from "../askama";+import type { AstroCookies } from "astro/dist/core/cookies";---<Layout title="{{ query }} - Stract">@@ -167,6 +168,18 @@ import { askama } from "../askama";<!-- Modal --><Modal />++ <!-- Error alerts (failed optic parsing etc.) -->+ <div class="sticky w-fit left-full right-0 bottom-0">+ {+ askama.for_("alert in alerts", () => (+ <div class="bg-red-700 text-white py-2 pl-2 pr-4 mr-2 mb-2 rounded-xl">+ <span class="cursor-pointer mr-2" onclick="this.parentElement.style.display='none';">×</span>+ {askama`alert $ {{lorem.sentence}}`}+ </div>+ ))+ }+ </div></main><Footer />diff --git a/optics/src/ast.rs b/optics/src/ast.rsindex c1d7c514..4e36ed72 100644--- a/optics/src/ast.rs+++ b/optics/src/ast.rs@@ -17,6 +17,8 @@use super::Error;use super::Result as ModResult;use lalrpop_util::lalrpop_mod;+use serde::Deserialize;+use serde::Serialize;use super::lexer;@@ -25,12 +27,12 @@ lalrpop_mod!(pub parser, "/parser.rs");pub static PARSER: once_cell::sync::Lazy<parser::BlocksParser> =once_cell::sync::Lazy::new(parser::BlocksParser::new);-#[derive(Debug, PartialEq, Clone)]+#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]pub enum RankingTarget {Signal(String),}-#[derive(Debug, PartialEq, Clone)]+#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]pub struct RankingCoeff {pub target: RankingTarget,pub value: f64,diff --git a/optics/src/lib.rs b/optics/src/lib.rsindex 36274162..7fdb954e 100644--- a/optics/src/lib.rs+++ b/optics/src/lib.rs@@ -130,7 +130,7 @@ impl From<RawAction> for Action {}}-#[derive(Debug, PartialEq, Eq, Clone)]+#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)]pub struct Matching {pub pattern: Vec<PatternPart>,pub location: MatchLocation,@@ -177,7 +177,7 @@ impl TryFrom<RawMatchPart> for Matching {}}-#[derive(Debug, PartialEq, Eq)]+#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)]enum PatternToken {Raw(String),@@ -230,14 +230,14 @@ impl PatternToken {}}-#[derive(Debug, PartialEq, Eq, Clone)]+#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)]pub enum PatternPart {Raw(String),Wildcard,Anchor,}-#[derive(Debug, PartialEq, Eq, Clone)]+#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)]pub enum MatchLocation {Site,Url,@@ -248,14 +248,14 @@ pub enum MatchLocation {Schema,}-#[derive(Debug, PartialEq, Eq, Clone, Copy)]+#[derive(Debug, PartialEq, Eq, Clone, Copy, Serialize, Deserialize)]pub enum Action {Boost(u64),Downrank(u64),Discard,}-#[derive(Debug, Default, Clone)]+#[derive(Debug, Default, Clone, Serialize, Deserialize)]pub struct Optic {pub rankings: Vec<RankingCoeff>,pub site_rankings: SiteRankings,@@ -269,7 +269,7 @@ impl Optic {}}-#[derive(Debug, PartialEq, Eq, Clone)]+#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)]pub struct Rule {pub matches: Vec<Matching>,pub action: Action,