Skip to content

Commit 00e7ff1

Browse files
committed
Bug 1938944 - Implement search form in the search engine selector.
1 parent 63cdbf9 commit 00e7ff1

File tree

4 files changed

+171
-10
lines changed

4 files changed

+171
-10
lines changed

components/search/src/configuration_types.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ pub(crate) struct JSONEngineUrls {
6666

6767
/// The URL to use for trending suggestions.
6868
pub trending: Option<JSONEngineUrl>,
69+
70+
/// The URL of the search engine homepage.
71+
pub search_form: Option<JSONEngineUrl>,
6972
}
7073

7174
/// Represents the engine base section of the configuration.

components/search/src/filter.rs

Lines changed: 91 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ impl From<JSONEngineUrls> for SearchEngineUrls {
4545
search: urls.search.unwrap_or_default().into(),
4646
suggestions: urls.suggestions.map(|suggestions| suggestions.into()),
4747
trending: urls.trending.map(|trending| trending.into()),
48+
search_form: urls.search_form.map(|search_form| search_form.into()),
4849
}
4950
}
5051
}
@@ -63,7 +64,13 @@ impl SearchEngineUrls {
6364
if let Some(trending_url) = &preferred.trending {
6465
match &mut self.trending {
6566
Some(trend) => trend.merge(trending_url),
66-
None => self.suggestions = Some(trending_url.clone().into()),
67+
None => self.trending = Some(trending_url.clone().into()),
68+
};
69+
}
70+
if let Some(search_form_url) = &preferred.search_form {
71+
match &mut self.search_form {
72+
Some(search_form) => search_form.merge(search_form_url),
73+
None => self.search_form = Some(search_form_url.clone().into()),
6774
};
6875
}
6976
}
@@ -296,6 +303,7 @@ mod tests {
296303
}),
297304
suggestions: None,
298305
trending: None,
306+
search_form: None,
299307
},
300308
},
301309
&JSONEngineVariant {
@@ -332,7 +340,8 @@ mod tests {
332340
search_term_param_name: None,
333341
},
334342
suggestions: None,
335-
trending: None
343+
trending: None,
344+
search_form: None
336345
}
337346
}
338347
)
@@ -386,6 +395,17 @@ mod tests {
386395
}]),
387396
search_term_param_name: None,
388397
}),
398+
search_form: Some(JSONEngineUrl {
399+
base: Some("https://example.com/search_form".to_string()),
400+
method: Some(crate::JSONEngineMethod::Get),
401+
params: Some(vec![SearchUrlParam {
402+
name: "search-form-name".to_string(),
403+
value: Some("search-form-value".to_string()),
404+
enterprise_value: None,
405+
experiment_config: None,
406+
}]),
407+
search_term_param_name: None,
408+
}),
389409
},
390410
});
391411

@@ -461,7 +481,18 @@ mod tests {
461481
experiment_config: None,
462482
}],
463483
search_term_param_name: None,
464-
})
484+
}),
485+
search_form: Some(SearchEngineUrl {
486+
base: "https://example.com/search_form".to_string(),
487+
method: "GET".to_string(),
488+
params: vec![SearchUrlParam {
489+
name: "search-form-name".to_string(),
490+
value: Some("search-form-value".to_string()),
491+
enterprise_value: None,
492+
experiment_config: None,
493+
}],
494+
search_term_param_name: None,
495+
}),
465496
}
466497
}
467498
)
@@ -514,6 +545,17 @@ mod tests {
514545
}]),
515546
search_term_param_name: Some("trend".to_string()),
516547
}),
548+
search_form: Some(JSONEngineUrl {
549+
base: Some("https://example.com/search_form".to_string()),
550+
method: Some(crate::JSONEngineMethod::Get),
551+
params: Some(vec![SearchUrlParam {
552+
name: "search-form-name".to_string(),
553+
value: Some("search-form-value".to_string()),
554+
enterprise_value: None,
555+
experiment_config: None,
556+
}]),
557+
search_term_param_name: None,
558+
}),
517559
}),
518560
sub_variants: vec![],
519561
},
@@ -565,7 +607,18 @@ mod tests {
565607
experiment_config: None,
566608
}],
567609
search_term_param_name: Some("trend".to_string()),
568-
})
610+
}),
611+
search_form: Some(SearchEngineUrl {
612+
base: "https://example.com/search_form".to_string(),
613+
method: "GET".to_string(),
614+
params: vec![SearchUrlParam {
615+
name: "search-form-name".to_string(),
616+
value: Some("search-form-value".to_string()),
617+
enterprise_value: None,
618+
experiment_config: None,
619+
}],
620+
search_term_param_name: None,
621+
}),
569622
}
570623
}
571624
)
@@ -618,6 +671,17 @@ mod tests {
618671
}]),
619672
search_term_param_name: Some("trend".to_string()),
620673
}),
674+
search_form: Some(JSONEngineUrl {
675+
base: Some("https://example.com/search-form-variant".to_string()),
676+
method: Some(crate::JSONEngineMethod::Get),
677+
params: Some(vec![SearchUrlParam {
678+
name: "search-form-variant".to_string(),
679+
value: Some("search form variant".to_string()),
680+
enterprise_value: None,
681+
experiment_config: None,
682+
}]),
683+
search_term_param_name: None,
684+
}),
621685
}),
622686
// This would be the list of sub-variants for this part of the
623687
// configuration, however it is not used as the actual sub-variant
@@ -667,6 +731,17 @@ mod tests {
667731
}]),
668732
search_term_param_name: Some("subtrend".to_string()),
669733
}),
734+
search_form: Some(JSONEngineUrl {
735+
base: Some("https://example.com/search-form-subvariant".to_string()),
736+
method: Some(crate::JSONEngineMethod::Get),
737+
params: Some(vec![SearchUrlParam {
738+
name: "search-form-subvariant".to_string(),
739+
value: Some("search form subvariant".to_string()),
740+
enterprise_value: None,
741+
experiment_config: None,
742+
}]),
743+
search_term_param_name: None,
744+
}),
670745
}),
671746
sub_variants: vec![],
672747
}),
@@ -717,7 +792,18 @@ mod tests {
717792
experiment_config: None,
718793
}],
719794
search_term_param_name: Some("subtrend".to_string()),
720-
})
795+
}),
796+
search_form: Some(SearchEngineUrl {
797+
base: "https://example.com/search-form-subvariant".to_string(),
798+
method: "GET".to_string(),
799+
params: vec![SearchUrlParam {
800+
name: "search-form-subvariant".to_string(),
801+
value: Some("search form subvariant".to_string()),
802+
enterprise_value: None,
803+
experiment_config: None,
804+
}],
805+
search_term_param_name: None,
806+
}),
721807
}
722808
}
723809
)

components/search/src/selector.rs

Lines changed: 74 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,14 @@ mod tests {
263263
"name": "trending-name",
264264
"experimentConfig": "trending-experiment-value",
265265
}]
266+
},
267+
"searchForm": {
268+
"base": "https://example.com/search-form",
269+
"method": "GET",
270+
"params": [{
271+
"name": "search-form-name",
272+
"value": "search-form-value",
273+
}]
266274
}
267275
}
268276
},
@@ -360,7 +368,18 @@ mod tests {
360368
)
361369
}],
362370
search_term_param_name: None
363-
})
371+
}),
372+
search_form: Some(SearchEngineUrl {
373+
base: "https://example.com/search-form".to_string(),
374+
method: "GET".to_string(),
375+
params: vec![SearchUrlParam {
376+
name: "search-form-name".to_string(),
377+
value: Some("search-form-value".to_string()),
378+
experiment_config: None,
379+
enterprise_value: None,
380+
}],
381+
search_term_param_name: None,
382+
}),
364383
},
365384
..Default::default()
366385
},
@@ -382,7 +401,8 @@ mod tests {
382401
search_term_param_name: Some("search".to_string())
383402
},
384403
suggestions: None,
385-
trending: None
404+
trending: None,
405+
search_form: None
386406
}
387407
}
388408
),
@@ -428,6 +448,14 @@ mod tests {
428448
"name": "area",
429449
"experimentConfig": "area-param",
430450
}]
451+
},
452+
"searchForm": {
453+
"base": "https://example.com/search-form",
454+
"method": "GET",
455+
"params": [{
456+
"name": "search-form-name",
457+
"value": "search-form-value",
458+
}]
431459
}
432460
}
433461
},
@@ -542,7 +570,18 @@ mod tests {
542570
experiment_config: Some("area-param".to_string())
543571
}],
544572
search_term_param_name: None
545-
})
573+
}),
574+
search_form: Some(SearchEngineUrl {
575+
base: "https://example.com/search-form".to_string(),
576+
method: "GET".to_string(),
577+
params: vec![SearchUrlParam {
578+
name: "search-form-name".to_string(),
579+
value: Some("search-form-value".to_string()),
580+
enterprise_value: None,
581+
experiment_config: None,
582+
}],
583+
search_term_param_name: None,
584+
}),
546585
},
547586
..Default::default()
548587
},
@@ -607,6 +646,14 @@ mod tests {
607646
"name": "area",
608647
"experimentConfig": "area-param",
609648
}]
649+
},
650+
"searchForm": {
651+
"base": "https://example.com/search-form",
652+
"method": "GET",
653+
"params": [{
654+
"name": "search-form-name",
655+
"value": "search-form-value",
656+
}]
610657
}
611658
}
612659
},
@@ -720,7 +767,18 @@ mod tests {
720767
experiment_config: Some("area-param".to_string())
721768
}],
722769
search_term_param_name: None
723-
})
770+
}),
771+
search_form: Some(SearchEngineUrl {
772+
base: "https://example.com/search-form".to_string(),
773+
method: "GET".to_string(),
774+
params: vec![SearchUrlParam {
775+
name: "search-form-name".to_string(),
776+
value: Some("search-form-value".to_string()),
777+
enterprise_value: None,
778+
experiment_config: None,
779+
}],
780+
search_term_param_name: None,
781+
}),
724782
},
725783
..Default::default()
726784
}),
@@ -782,7 +840,18 @@ mod tests {
782840
experiment_config: Some("area-param".to_string())
783841
}],
784842
search_term_param_name: None
785-
})
843+
}),
844+
search_form: Some(SearchEngineUrl {
845+
base: "https://example.com/search-form".to_string(),
846+
method: "GET".to_string(),
847+
params: vec![SearchUrlParam {
848+
name: "search-form-name".to_string(),
849+
value: Some("search-form-value".to_string()),
850+
enterprise_value: None,
851+
experiment_config: None,
852+
}],
853+
search_term_param_name: None,
854+
}),
786855
},
787856
..Default::default()
788857
}),

components/search/src/types.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ pub struct SearchEngineUrls {
139139

140140
/// The URL to use for trending suggestions.
141141
pub trending: Option<SearchEngineUrl>,
142+
143+
/// The URL of the search engine homepage.
144+
pub search_form: Option<SearchEngineUrl>,
142145
}
143146

144147
/// The list of acceptable classifications for a search engine.

0 commit comments

Comments
 (0)