<commit_before># Search v2

## Development tips

### Adding fields to a live index

Elastic supports adding new fields to an existing mapping,
along with some other operations:
https://www.elastic.co/guide/en/elasticsearch/reference/7.9/mapping.html#add-field-mapping

To know whether a change you make to a Document will work in prod,
try it locally having already set up the mapping:<commit_msg>add docs explaining how to enable search v2 in instant search on staging (#4623)<commit_after># Search v2

## Testing on Staging

### Enabling in Instant Search

Open [support.allizom.org](https://support.allizom.org) and then open Firefox's [Web Console](https://developer.mozilla.org/en-US/docs/Tools/Web_Console).

Paste the following JS in, and hit return on your keyboard:

```
window.localStorage.setItem("enable_search_v2", "true")
```

Pasting JS into your Web Console without understanding what it does is a *very bad idea*,
so to explain this:

* `window.localStorage` uses the [Local Storage API](https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage) to get access to a small store which sites can use to store small pieces of information in your browser.
* `setItem()` is the function which allows us to write a piece of information to the store.
* `"enable_search_v2"` is the name of the piece of information we're storing.
* `"true"` is its value.

Now refresh the page and instant search should be using search v2.
You can check this by using some of the syntax which search v2 supports,
like wildcards.
A search for `fir*` in search v1 should return next to no results,
whereas in search v2 it should return at least as many as a search for `firefox`.

### Disabling in Instant Search

You can disable search v2 in instant search by opening Firefox's Web Console on support.allizom.org again,
but running this snippet instead:

```
window.localStorage.removeItem("enable_search_v2")
```

* `window.localStorage` is the same Local Storage API from before.
* `removeItem()` is the function to remove a piece of information.
* `"enable_search_v2"` is the name of the piece of information to remove.

Refresh the page,
and instant search will be using search v1 again.

## Development tips

### Adding fields to a live index

Elastic supports adding new fields to an existing mapping,
along with some other operations:
https://www.elastic.co/guide/en/elasticsearch/reference/7.9/mapping.html#add-field-mapping

To know whether a change you make to a Document will work in prod,
try it locally having already set up the mapping:
{'fraction_non_alphanumeric': 0.07954545454545454, 'fraction_numerical': 0.008228840125391849, 'mean_word_length': 4.635761589403973, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 5, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4393787', 'n_tokens_mistral': 724, 'n_tokens_neox': 691, 'n_words': 340}