Skip to content

Commit 2fb2e96

Browse files
heiskrJamesMGreene
andauthored
Move site search to use an endpoint (github#17359)
* Move site search to use an endpoint * Update browser.js * Update search.js * Update lib/search/versions.js Co-authored-by: James M. Greene <[email protected]> * Fix URLs Co-authored-by: James M. Greene <[email protected]>
1 parent c5c2347 commit 2fb2e96

30 files changed

+436
-416
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.algolia-cache
2+
.search-cache
23
.DS_Store
34
.env
45
/node_modules/

contributing/search.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,10 @@ Why do we need this? For our daily shipping needs, it's tolerable that search up
9090

9191
### Code files
9292

93-
- [javascripts/search.js](javascripts/search.js) - The browser-side code that enables search using Algolia's [InstantSearch.js](https://github.com/algolia/instantsearch.js/) library.
94-
- [lib/algolia/client.js](lib/algolia/client.js) - A thin wrapper around the [algoliasearch](https://ghub.io/algoliasearch) Node.js module for interacting with the Algolia API.
95-
- [lib/algolia/search-index.js](lib/algolia/search-index.js) - A class for generating structured search data from repository content and syncing it with the remote Algolia service. This class has built-in validation to ensure that all records are valid before they're uploaded. This class also takes care of removing deprecated records, and compares existing remote records with the latest local records to avoid uploading records that haven't changed.
96-
- [script/sync-algolia-search-indices.js](script/sync-algolia-search-indices.js) - The script used by the Actions workflow to update search indices on our Algolia account. This can also be [run in the development environment](#development).
93+
- [javascripts/search.js](javascripts/search.js) - The browser-side code that enables search.
94+
- [lib/search/algolia-client.js](lib/search/algolia-client.js) - A thin wrapper around the [algoliasearch](https://ghub.io/algoliasearch) Node.js module for interacting with the Algolia API.
95+
- [lib/search/algolia-search-index.js](lib/search/algolia-search-index.js) - A class for generating structured search data from repository content and syncing it with the remote Algolia service. This class has built-in validation to ensure that all records are valid before they're uploaded. This class also takes care of removing deprecated records, and compares existing remote records with the latest local records to avoid uploading records that haven't changed.
96+
- [script/sync-search-indices.js](script/sync-search-indices.js) - The script used by the Actions workflow to update search indices on our Algolia account. This can also be [run in the development environment](#development).
9797
- [tests/algolia-search.js](tests/algolia-search.js) - Tests!
9898

9999
## Indices
@@ -136,4 +136,4 @@ Each record represents a section of a page. Sections are derived by splitting up
136136
- It's not strictly necessary to set an `objectID` as Algolia will create one automatically, but by creating our own we have a guarantee that subsequent invocations of this upload script will overwrite existing records instead of creating numerous duplicate records with differing IDs.
137137
- Algolia has typo tolerance. Try spelling something wrong and see what you get!
138138
- Algolia has lots of controls for customizing each index, so we can add weights to certain attributes and create rules like "title is more important than body", etc. But it works pretty well as-is without any configuration.
139-
- Algolia has support for "advanced query syntax" for exact matching of quoted expressions and exclusion of words preceded by a `-` sign. This is off by default but we have it enabled in our browser client. This and many other settings can be configured in Algolia.com web interface. The settings in the web interface can be overridden by the InstantSearch.js client. See [javascripts/search.js]([javascripts/search.js).
139+
- Algolia has support for "advanced query syntax" for exact matching of quoted expressions and exclusion of words preceded by a `-` sign. This is off by default but we have it enabled in our browser client. This and many other settings can be configured in Algolia.com web interface. The settings in the web interface can be overridden by the search endpoint. See [middleware/search.js]([middleware/search.js).

includes/search-form.html

+3-5
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
- On all other pages, in the header
66
-->
77

8-
<form class="mb-0" aria-hidden="true">
9-
<div id="search-input-container">
10-
<!-- Algolia instantsearch.js will add a search input here -->
11-
</div>
12-
</form>
8+
<div id="search-input-container" aria-hidden="true">
9+
<!-- will add a search input here -->
10+
</div>

javascripts/experiment.js

+1-17
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import murmur from 'imurmurhash'
22
import { getUserEventsId, sendEvent } from './events'
3+
// import h from './hyperscript'
34

45
const TREATMENT = 'TREATMENT'
56
const CONTROL = 'CONTROL'
@@ -19,23 +20,6 @@ export async function sendSuccess (test) {
1920
})
2021
}
2122

22-
const xmlns = 'http://www.w3.org/2000/svg'
23-
24-
export function h (tagName, attributes = {}, children = []) {
25-
const el = ['svg', 'path'].includes(tagName)
26-
? document.createElementNS(xmlns, tagName)
27-
: document.createElement(tagName)
28-
Object.entries(attributes).forEach(
29-
([key, value]) => el.setAttribute(key, value)
30-
)
31-
children.forEach(child =>
32-
typeof child === 'string'
33-
? el.append(document.createTextNode(child))
34-
: el.append(child)
35-
)
36-
return el
37-
}
38-
3923
export default function () {
4024
// const testName = '$test-name$'
4125
// const xbucket = bucket(testName)

javascripts/fake-hogan.js

-15
This file was deleted.

javascripts/hyperscript.js

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
const xmlns = 'http://www.w3.org/2000/svg'
2+
3+
const plainObjectConstructor = {}.constructor
4+
5+
function exists (value) {
6+
return value !== null && typeof value !== 'undefined'
7+
}
8+
9+
function isPlainObject (value) {
10+
return value.constructor === plainObjectConstructor
11+
}
12+
13+
function isString (value) {
14+
return typeof value === 'string'
15+
}
16+
17+
function renderChildren (el, children) {
18+
for (const child of children) {
19+
if (isPlainObject(child)) {
20+
Object.entries(child)
21+
.filter(([key, value]) => exists(value))
22+
.forEach(([key, value]) => el.setAttribute(key, value))
23+
} else if (Array.isArray(child)) {
24+
renderChildren(el, child)
25+
} else if (isString(child)) {
26+
el.append(document.createTextNode(child))
27+
} else {
28+
el.append(child)
29+
}
30+
}
31+
}
32+
33+
export default function h (tagName, ...children) {
34+
const el = ['svg', 'path'].includes(tagName)
35+
? document.createElementNS(xmlns, tagName)
36+
: document.createElement(tagName)
37+
renderChildren(el, children)
38+
return el
39+
}
40+
41+
export const tags = Object.fromEntries(
42+
['div', 'form', 'a', 'input', 'button', 'ol', 'li', 'em']
43+
.map(tagName => [tagName, (...args) => h(tagName, ...args)])
44+
)

0 commit comments

Comments
 (0)