summaryrefslogtreecommitdiffstats
path: root/toolkit/components/search/docs/SearchConfigurationSchema.rst
blob: b57f69fe1386b68701aac50d54000d39a2af1e1c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
===========================
Search Configuration Schema
===========================

This document outlines the details of the schema and how the various sub-parts
interact. For the full fields and descriptions, please see the `schema itself`_.

.. note::
    In the examples, only relevant properties are displayed.

Overview
========

The configuration is a JSON blob which is object with a `data` property which
is an array of engines:

.. code-block:: js

    {
      data: [
        {
          // engine 1 details
        },
        {
          // engine 2 details
        }
      ]
    }

Engine Objects
==============

An engine's details are located in the properties of the object associated with it.
An engine that is deployed globally could be listed simply as:

.. code-block:: js

    {
      "default": "no",
      "telemetryId": "engine1-telem",
      "webExtension": {
        "id": "web@ext"
      },
      "appliesTo": [{
        "included": {
          "everywhere": true
        }
      }]
    }

The ``appliesTo`` section is an array of objects. At least one object is required
to specify which regions/locales the engine is included within. If an
``appliesTo`` object lists additional attributes then these will override any
attributes at the top-level.

For example, a more complex engine definition may be available only to users
located specific regions or with certain locales. For example:

.. code-block:: js

    {
      "webExtension": {
        "id": "web@ext"
      },
      "appliesTo": [{
        "included": {
          "region": "us"
        },
        "webExtension": {
          "id": "web-us@ext"
        }
      }, {
        "included": {
          "region": "gb"
        },
        "webExtension": {
          "id": "web-gb@ext"
        }
      }]
    }

In this case users identified as being in the US region would use the WebExtension
with identifier ``web-us@ext``. GB region users would get
``web-gb@ext``, and all other users would get ``web@ext``.

To direct search engines to pull ``_locale`` data from a specific locale
directory, you can use ``webExtension.locales``.

For example, in this code block:

.. code-block:: js

    {
      "webExtension": {
        "id": "web@ext"
      },
      "appliesTo": [
        {
          "included": {
            "locales": "en-US"
          },
          "webExtension": {
            "locales": [
              "us"
            ]
          }
        }, {
          "included": {
            "locales": "en-GB"
          },
          "webExtension": {
            "locales": [
              "uk"
            ]
          }
        }
      ]
    }

There should exist a ``us`` and ``uk`` folder in the ``locales`` directory
of the extension, ``web``.

If a locale is not provided, ``webExtension.locales`` is set to
``SearchUtils.DEFAULT_TAG``.

`Search Extensions directory <https://searchfox.org/mozilla-central/source/browser/components/search/extensions>`__

`Example of a locales directory <https://searchfox.org/mozilla-central/source/browser/components/search/extensions/wikipedia/_locales>`__


Special Attributes
==================

$USER_LOCALE
------------

If a ``webExtension.locales`` property contains an element with the value
``"$USER_LOCALE"`` then the special value will be replaced in the
configuration object with the users locale. For example:

.. code-block:: js

    {
      "webExtension": {
        "id": "web@ext"
      },
      "appliesTo": [{
        "included": {
          "locales": {
            "matches": [
              "en-US",
              "en-GB"
            ]
          }
        },
        "webExtension": {
          "locales": ["$USER_LOCALE"]
        }
      }]
    }

Will report either ``[en-US]`` or ``[en-GB]`` as the ``webExtension.locales``
property depending on the user's locale.

Since the special string is replaced, custom folder names can be searched for
by adding the keyword in between a consistent prefix/suffix.

For example, if ``webExtension.locales`` was ``["example-$USER_LOCALE"]``,
the locale generator will generate locale names in the form of ``example-en-US``
and ``example-en-GB``.

Note: Prior to Firefox 100.0, $USER_LOCALE used an exact match.
In Firefox 100.0 the replacement was updated to use a standard string replacement.

From Firefox 98.0.1 and 97.7.1esr, ``"$USER_LOCALE"`` may also be used in the
``telemetryId`` field.

$USER_REGION
------------

This can be used in the same situations as ``"$USER_LOCALE"``, instead
replacing ``webExtension.locale`` with a string that uses the users region.

.. code-block:: js

    {
      "webExtension": {
        "id": "web@ext"
      },
      "appliesTo": [{
        "included": {
          "everywhere": true
        },
        "webExtension": {
          "locales": ["foo-$USER_REGION"]
        }
      }]
    }

In this example, if the user's region is ``fr``, the ``webExtension.locale``
will be ``foo-fr``, and the code will look for the ``messages.json`` in
the ``foo-fr`` folder of the ``_locales`` folder for this extension.

Note: ``"$USER_REGION"`` was added in Firefox 98.0.1 and 97.7.1esr and used an exact match.
In Firefox 100.0 the replacement was updated to use a standard string replacement.

"default"
---------

You can specify ``"default"`` as a region in the configuration if
the engine is to be included when we do not know the user's region.

"override"
----------

The ``"override"`` field can be set to true if you want a section to
only override otherwise included engines. ``"override"`` will only work for
sections which apply to distributions or experiments. The experiment case was
added in Firefox 81.

Starting with Firefox 96, ``"override"`` sections may include ``included`` and
``excluded`` information which will be applied accordingly. If they are not
supplied, then the override section will be applied to everywhere.

Example:

.. code-block:: js

    {
      "webExtension": {
        "id": "web@ext"
      },
      "appliesTo": [{
        // Complicated and lengthy inclusion rules
      }, {
        "override": true,
        "application": { "distributions": ["mydistrocode"]},
        "params": {
          "searchUrlGetParams": [
            { "name": "custom", "value": "foobar" }
          ]
        }
      }]
    }

Application Scoping
===================

An engine configuration may be scoped to a particular application.

Name
----

One or more application names may be specified. Currently the only application
type supported is ``firefox``. If an application name is specified, then it
must be matched for the section to apply. If there are no application names
specified, then the section will match any consumer of the configuration.

In the following example, ``web@ext`` would be included on any consumer
of the configuration, but ``web1@ext`` would only be included on Firefox desktop.

.. code-block:: js

    {
      "webExtension": {
        "id": "web@ext"
      },
      "appliesTo": [{
        "included": {
          "everywhere": true
          "application": {
            "name": []
          }
        }
      ]}
    },
    {
      "webExtension": {
        "id": "web1@ext"
      },
      "appliesTo": [{
        "included": {
          "everywhere": true
          "application": {
            "name": ["firefox"]
          }
        }
      ]}
    }

Channel
-------

One or more channels may be specified in an array to restrict a configuration
to just those channels. The current known channels are:

    - default: Self-builds of Firefox, or possibly some self-distributed versions.
    - nightly: Firefox Nightly builds.
    - aurora: Firefox Developer Edition
    - beta: Firefox Beta
    - release: The main Firefox release channel.
    - esr: The ESR Channel. This will also match versions of Firefox where the
      displayed version number includes ``esr``. We do this to include Linux
      distributions and other manual builds of ESR.

In the following example, ``web@ext`` would be set as default on the default
channel only, whereas ``web1@ext`` would be set as default on release and esr
channels.

.. code-block:: js

    {
      "webExtension": {
        "id": "web@ext"
      },
      "appliesTo": [{
        "included": {
          "everywhere": true
          "default": "yes",
          "application": {
            "channel": ["default"]
          }
        }
      ]}
    },
    {
      "webExtension": {
        "id": "web1@ext"
      },
      "appliesTo": [{
        "included": {
          "everywhere": true
          "default": "yes",
          "application": {
            "channel": ["release", "esr"]
          }
        }
      ]}
    }

Distributions
-------------

Distributions may be specified to be included or excluded in an ``appliesTo``
section. The ``distributions`` field in the ``application`` section is an array
of distribution identifiers. The identifiers match those supplied by the
``distribution.id`` preference.

In the following, ``web@ext`` would be included in only the ``cake``
distribution. ``web1@ext`` would be excluded from the ``apples`` distribution
but included in the main desktop application, and all other distributions.

.. code-block:: js

    {
      "webExtension": {
        "id": "web@ext"
      },
      "appliesTo": [{
        "included": {
          "everywhere": true
          "application": {
            "distributions": ["cake"]
          }
        }
      ]}
    },
    {
      "webExtension": {
        "id": "web1@ext"
      },
      "appliesTo": [{
        "included": {
          "everywhere": true
          "application": {
            "excludedDistributions": ["apples"]
          }
        }
      ]}
    }

Version
-------

Minimum and Maximum versions may be specified to restrict a configuration to
specific ranges. These may be open-ended. Version comparison is performed
using `the version comparator`_.

Note: comparison against ``maxVersion`` is a less-than comparison. The
``maxVersion`` won't be matched directly.

In the following example, ``web@ext`` would be included for any version after
72.0a1, whereas ``web1@ext`` would be included only between 68.0a1 and 71.x
version.

.. code-block:: js

    {
      "webExtension": {
        "id": "web@ext"
      },
      "appliesTo": [{
        "included": {
          "everywhere": true
          "application": {
            "minVersion": "72.0a1"
          }
        }
      ]}
    },
    {
      "webExtension": {
        "id": "web1@ext"
      },
      "appliesTo": [{
        "included": {
          "everywhere": true
          "default": "yes",
          "application": {
            "minVersion": "68.0a1"
            "maxVersion": "72.0a1"
          }
        }
      ]}
    }

Experiments
===========

We can run experiments by giving sections within ``appliesTo`` a
``experiment`` value, the Search Service can then optionally pass in a
matching ``experiment`` value to match those sections.

Sections which have a ``experiment`` will not be used unless a matching
``experiment`` has been passed in, for example:

.. code-block:: js

    {
      "webExtension": {
        "id": "web@ext"
      },
      "appliesTo": [{
        "included": {
          "everywhere": true
        },
        "experiment": "nov-16",
        "webExtension": {
          "id": "web-experimental@ext"
        }
      }, {
        "included": {
          "everywhere": true
        },
        "webExtension": {
          "id": "web-gb@ext"
        }
      }]
    }

Engine Defaults
===============

An engine may be specified as the default for one of two purposes:

#. normal browsing mode,
#. private browsing mode.

If there is no engine specified for private browsing mode for a particular region/locale
pair, then the normal mode engine is used.

If the instance of the application does not support a separate private browsing mode engine,
then it will only use the normal mode engine.

An engine may or may not be default for particular regions/locales. The ``default``
property is a tri-state value with states of ``yes``, ``yes-if-no-other`` and
``no``. Here's an example of how they apply:

.. code-block:: js

    {
      "webExtension": {
        "id": "engine1@ext"
      },
      "appliesTo": [{
        "included": {
          "region": "us"
        },
        "default": "yes"
      }, {
        "excluded": {
          "region": "us"
        },
        "default": "yes-if-no-other"
      }]
    },
    {
      "webExtension": {
        "id": "engine2@ext"
      },
      "appliesTo": [{
        "included": {
          "region": "gb"
        },
        "default": "yes"
      }]
    },
      "webExtension": {
        "id": "engine3@ext"
      },
      "default": "no"
      "appliesTo": [{
        "included": {
          "everywhere": true
        },
      }]
    },
    {
      "webExtension": {
        "id": "engine4@ext"
      },
      "defaultPrivate": "yes",
      "appliesTo": [{
        "included": {
          "region": "fr"
        }
      }]
    }

In this example, for normal mode:

    - engine1@ext is default in the US region, and all other regions except for GB
    - engine2@ext is default in only the GB region
    - engine3@ext and engine4 are never default anywhere

In private browsing mode:

    - engine1@ext is default in the US region, and all other regions except for GB and FR
    - engine2@ext is default in only the GB region
    - engine3@ext is never default anywhere
    - engine4@ext is default in the FR region.

Engine Ordering
===============

The ``orderHint`` field indicates the suggested ordering of an engine relative to
other engines when displayed to the user, unless the user has customized their
ordering.

The default ordering of engines is based on a combination of if the engine is
default, and the ``orderHint`` fields. The ordering is structured as follows:

#. Default engine in normal mode
#. Default engine in private browsing mode (if different from the normal mode engine)
#. Other engines in order from the highest ``orderHint`` to the lowest.

Example:

.. code-block:: js

    {
      "webExtension": {
        "id": "engine1@ext"
      },
      "orderHint": 2000,
      "default": "no",
    },
    {
      "webExtension": {
        "id": "engine2@ext"
      },
      "orderHint": 1000,
      "default": "yes"
    },
    {
      "webExtension": {
        "id": "engine3@ext"
      },
      "orderHint": 500,
      "default": "no"
    }

This would result in the order: ``engine2@ext, engine1@ext, engine3@ext``.

.. _schema itself: https://searchfox.org/mozilla-central/source/toolkit/components/search/schema/
.. _the version comparator: https://developer.mozilla.org/en-US/docs/Mozilla/Toolkit_version_format