Skip to content

Commit acbaf8f

Browse files
docs(sandbox): add Query Suggestions with categories (#466)
Co-authored-by: François Chalifour <[email protected]>
1 parent 10223b1 commit acbaf8f

File tree

8 files changed

+111
-0
lines changed

8 files changed

+111
-0
lines changed

.codesandbox/ci.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"/examples/query-suggestions-with-rich-hits",
99
"/examples/query-suggestions",
1010
"/examples/query-suggestions-with-recent-searches",
11+
"/examples/query-suggestions-with-categories",
1112
"/examples/query-suggestions-with-inline-categories",
1213
"/examples/recently-viewed-items"
1314
],

examples/query-suggestions-with-categories/README.md

Whitespace-only changes.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { autocomplete } from '@algolia/autocomplete-js';
2+
import { createQuerySuggestionsPlugin } from '@algolia/autocomplete-plugin-query-suggestions';
3+
import algoliasearch from 'algoliasearch';
4+
5+
import '@algolia/autocomplete-theme-classic';
6+
7+
const appId = 'latency';
8+
const apiKey = '6be0576ff61c053d5f9a3225e2a90f76';
9+
const searchClient = algoliasearch(appId, apiKey);
10+
11+
const querySuggestionsPlugin = createQuerySuggestionsPlugin({
12+
searchClient,
13+
indexName: 'instant_search_demo_query_suggestions',
14+
getSearchParams() {
15+
return {
16+
hitsPerPage: 10,
17+
};
18+
},
19+
categoryAttribute: [
20+
'instant_search',
21+
'facets',
22+
'exact_matches',
23+
'categories',
24+
],
25+
categoriesPerItem: 1,
26+
categoriesLimit: 2,
27+
});
28+
29+
autocomplete({
30+
container: '#autocomplete',
31+
placeholder: 'Search',
32+
openOnFocus: true,
33+
plugins: [querySuggestionsPlugin],
34+
});
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { h } from 'preact';
2+
3+
// Parcel picks the `source` field of the monorepo packages and thus doesn't
4+
// apply the Babel config to replace our `__DEV__` global expression.
5+
// We therefore need to manually override it in the example app.
6+
// See https://twitter.com/devongovett/status/1134231234605830144
7+
(global as any).__DEV__ = process.env.NODE_ENV !== 'production';
8+
(global as any).__TEST__ = false;
9+
(global as any).h = h;
228 KB
Loading
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<html lang="en">
2+
<head>
3+
<meta charset="UTF-8" />
4+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
5+
6+
<link rel="shortcut icon" href="favicon.png" type="image/x-icon" />
7+
<link rel="stylesheet" href="style.css" />
8+
9+
<title>Autocomplete Query Suggestions with categories</title>
10+
</head>
11+
12+
<body>
13+
<div class="container">
14+
<div id="autocomplete"></div>
15+
</div>
16+
17+
<script src="env.ts"></script>
18+
<script src="app.tsx"></script>
19+
</body>
20+
</html>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"name": "@algolia/query-suggestion-with-categories",
3+
"description": "Autocomplete Query Suggestions with categories",
4+
"version": "1.0.0-alpha.44",
5+
"private": true,
6+
"license": "MIT",
7+
"main": "index.html",
8+
"scripts": {
9+
"build": "parcel build index.html",
10+
"start": "parcel index.html"
11+
},
12+
"dependencies": {
13+
"@algolia/autocomplete-js": "1.0.0-alpha.44",
14+
"@algolia/autocomplete-plugin-query-suggestions": "1.0.0-alpha.44",
15+
"@algolia/autocomplete-theme-classic": "1.0.0-alpha.44",
16+
"algoliasearch": "4.8.3",
17+
"preact": "10.5.7"
18+
},
19+
"devDependencies": {
20+
"parcel-bundler": "1.12.4"
21+
},
22+
"keywords": [
23+
"algolia",
24+
"autocomplete",
25+
"javascript"
26+
]
27+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
* {
2+
box-sizing: border-box;
3+
}
4+
5+
body {
6+
background-color: rgb(244, 244, 249);
7+
color: rgb(65, 65, 65);
8+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
9+
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
10+
sans-serif;
11+
-webkit-font-smoothing: antialiased;
12+
-moz-osx-font-smoothing: grayscale;
13+
padding: 1rem;
14+
}
15+
16+
.container {
17+
margin: 0 auto;
18+
max-width: 640px;
19+
width: 100%;
20+
}

0 commit comments

Comments
 (0)