Skip to content

Commit

Permalink
Make site-search results score-debugging optional (mdn#2868)
Browse files Browse the repository at this point in the history
* Make site-search results score-debugging optional

Fixes mdn#2866

* Update docs/debugging-sitesearch.md

Co-authored-by: Ryan Johnson <[email protected]>

Co-authored-by: Ryan Johnson <[email protected]>
  • Loading branch information
peterbe and escattone authored Feb 10, 2021
1 parent 7cad1f7 commit 6bef620
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
5 changes: 5 additions & 0 deletions client/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 14,8 @@ export const AUTOCOMPLETE_SEARCH_WIDGET = JSON.parse(
export const DEBUG_GOOGLE_ANALYTICS = JSON.parse(
process.env.REACT_APP_DEBUG_GOOGLE_ANALYTICS || "false"
);

// You can read more about this in `docs/debugging-sitesearch.md`.
export const DEBUG_SEARCH_RESULTS = JSON.parse(
process.env.REACT_APP_DEBUG_SEARCH_RESULTS || "false"
);
4 changes: 2 additions & 2 deletions client/src/site-search/search-results.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 2,7 @@ import React from "react";
import { Link, createSearchParams, useSearchParams } from "react-router-dom";
import useSWR from "swr";

import { CRUD_MODE } from "../constants";
import { CRUD_MODE, DEBUG_SEARCH_RESULTS } from "../constants";
import { useLocale } from "../hooks";
import { appendURL } from "./utils";

Expand Down Expand Up @@ -362,7 362,7 @@ function Results({
<a className="url" href={document.mdn_url}>
{document.mdn_url}
</a>
{process.env.NODE_ENV === "development" && (
{DEBUG_SEARCH_RESULTS && (
<span className="nerd-data">
<b>score:</b> <code>{document.score}</code>,{" "}
<b>popularity:</b> <code>{document.popularity}</code>,{" "}
Expand Down
32 changes: 32 additions & 0 deletions docs/debugging-sitesearch.md
Original file line number Diff line number Diff line change
@@ -0,0 1,32 @@
# Debugging site-search

## How it works

Site-search is done via Kuma and Elasticsearch. The default way, when you sort
by "Best" is that it combines the match with each documents' popularity number.
This hopefully gives the best possible results as it elevates popular documents,
on the assumption that it's more likely to be what you're looking for, with how
much the title and body matches the search string.

This metadata is always included in the search results JSON from Kuma. But
displaying it in Yari is optional.

## How to enable it

To display each search results `score` and `popularity`, set this in your `.env`:

REACT_APP_DEBUG_SEARCH_RESULTS=true

Now, when you open <http://localhost:3000/en-US/search?q=test> the `score`
and `popularity` is shown.

## How to use it

You can't affect the sorting algorithm in Yari. To try out different techniques
for the `function_score` in the Python Elasticsearch code, you have to
make changes within Kuma to try different combinations such as `popularity_factor`
and `boost_mode` and `score_mode`. Most of these values are currently hardcoded in
the Kuma Python code.

It's hard to predict exactly what users really prefer and a lot of it depends
on learning from how people react to the sorting.

0 comments on commit 6bef620

Please sign in to comment.