Skip to content

Commit 6e67740

Browse files
authored
docs(autocomplete-preset-algolia): unify examples (#495)
* docs(autocomplete-preset-algolia): unify examples * docs(autocomplete-preset-algolia): fix remaining examples * docs(autocomplete-preset-algolia): add missing comma
1 parent 4447b1f commit 6e67740

File tree

7 files changed

+122
-66
lines changed

7 files changed

+122
-66
lines changed

packages/website/docs/highlightHit.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ import { highlightHit } from '@algolia/autocomplete-js';
4242
const hit = {
4343
hierarchicalCategories: {
4444
lvl1: 'Cameras & Camcoders',
45-
}
45+
},
4646
_highlightResult: {
4747
hierarchicalCategories: {
4848
lvl1: {

packages/website/docs/parseAlgoliaHitHighlight.md

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,13 @@ If you don't use a package manager, you can use a standalone endpoint:
3939
```js
4040
import { parseAlgoliaHitHighlight } from '@algolia/autocomplete-preset-algolia';
4141

42-
// An Algolia hit for query "lap"
42+
// An Algolia hit for query "the"
4343
const hit = {
44-
name: 'Laptop',
44+
name: 'The Legend of Zelda: Breath of the Wild',
4545
_highlightResult: {
4646
name: {
47-
value: '__aa_highlight__Lap__/aa_highlight__top',
47+
value:
48+
'__aa-highlight__The__/aa-highlight__ Legend of Zelda: Breath of __aa-highlight__the__/aa-highlight__ Wild',
4849
},
4950
},
5051
};
@@ -53,33 +54,48 @@ const highlightedParts = parseAlgoliaHitHighlight({
5354
attribute: 'name',
5455
});
5556

56-
// [{ value: 'Lap', isHighlighted: true }, { value: 'top', isHighlighted: false }]
57+
/*
58+
* [
59+
* { value: 'The', isHighlighted: true },
60+
* { value: ' Legend of Zelda: Breath of ', isHighlighted: false },
61+
* { value: 'the', isHighlighted: true },
62+
* { value: ' Wild', isHighlighted: false },
63+
* ]
64+
*/
5765
```
5866

5967
### With nested attributes
6068

6169
```js
6270
import { parseAlgoliaHitHighlight } from '@algolia/autocomplete-preset-algolia';
6371

64-
// An Algolia hit for query "lap"
72+
// An Algolia hit for query "cam"
6573
const hit = {
66-
name: {
67-
type: 'Laptop',
74+
hierarchicalCategories: {
75+
lvl1: 'Cameras & Camcoders',
6876
},
6977
_highlightResult: {
70-
name: {
71-
type: {
72-
value: '__aa_highlight__Lap__/aa_highlight__top',
78+
hierarchicalCategories: {
79+
lvl1: {
80+
value:
81+
'__aa-highlight__Cam__/aa-highlight__eras & __aa-highlight__Cam__/aa-highlight__coders',
7382
},
7483
},
7584
},
7685
};
7786
const highlightedParts = parseAlgoliaHitHighlight({
7887
hit,
79-
attribute: ['name', 'type'],
88+
attribute: ['hierarchicalCategories', 'lvl1'],
8089
});
8190

82-
// [{ value: 'Lap', isHighlighted: true }, { value: 'top', isHighlighted: false }]
91+
/*
92+
* [
93+
* { value: 'Cam', isHighlighted: true },
94+
* { value: 'eras & ', isHighlighted: false },
95+
* { value: 'Cam', isHighlighted: true },
96+
* { value: 'coders', isHighlighted: false },
97+
* ]
98+
*/
8399
```
84100

85101
## Parameters

packages/website/docs/parseAlgoliaHitReverseHighlight.md

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,47 +39,59 @@ If you don't use a package manager, you can use a standalone endpoint:
3939
```js
4040
import { parseAlgoliaHitReverseHighlight } from '@algolia/autocomplete-preset-algolia';
4141

42-
// An Algolia hit for query "lap"
42+
// An Algolia hit for query "zelda"
4343
const hit = {
44-
name: 'Laptop',
44+
query: 'zelda switch',
4545
_highlightResult: {
46-
name: {
47-
value: '__aa_highlight__Lap__/aa_highlight__top',
46+
query: {
47+
value:
48+
'__aa-highlight__zelda__/aa-highlight__ switch',
4849
},
4950
},
5051
};
5152
const reverseHighlightedParts = parseAlgoliaHitReverseHighlight({
5253
hit,
53-
attribute: 'name',
54+
attribute: 'query',
5455
});
5556

56-
// [{ value: 'Lap', isHighlighted: false }, { value: 'top', isHighlighted: true }]
57+
/*
58+
* [
59+
* { value: 'zelda', isHighlighted: false },
60+
* { value: ' switch', isHighlighted: true },
61+
* ]
62+
*/
5763
```
5864

5965
### With nested attributes
6066

6167
```js
6268
import { parseAlgoliaHitReverseHighlight } from '@algolia/autocomplete-preset-algolia';
6369

64-
// An Algolia hit for query "lap"
70+
// An Algolia hit for query "video"
6571
const hit = {
66-
name: {
67-
type: 'Laptop',
72+
hierarchicalCategories: {
73+
lvl1: 'Video games',
6874
},
6975
_highlightResult: {
70-
name: {
71-
type: {
72-
value: '__aa_highlight__Lap__/aa_highlight__top',
76+
hierarchicalCategories: {
77+
lvl1: {
78+
value:
79+
'__aa-highlight__Video__/aa-highlight__ games',
7380
},
7481
},
7582
},
7683
};
7784
const reverseHighlightedParts = parseAlgoliaHitReverseHighlight({
7885
hit,
79-
attribute: ['name', 'type'],
86+
attribute: ['hierarchicalCategories', 'lvl1'],
8087
});
8188

82-
// [{ value: 'Lap', isHighlighted: false }, { value: 'top', isHighlighted: true }]
89+
/*
90+
* [
91+
* { value: 'Video', isHighlighted: false },
92+
* { value: ' games', isHighlighted: true },
93+
* ]
94+
*/
8395
```
8496

8597
## Parameters

packages/website/docs/parseAlgoliaHitReverseSnippet.md

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,47 +39,59 @@ If you don't use a package manager, you can use a standalone endpoint:
3939
```js
4040
import { parseAlgoliaHitReverseSnippet } from '@algolia/autocomplete-preset-algolia';
4141

42-
// An Algolia hit for query "lap"
42+
// An Algolia hit for query "zelda"
4343
const hit = {
44-
name: 'Laptop',
44+
query: 'zelda switch',
4545
_snippetResult: {
46-
name: {
47-
value: '__aa_highlight__Lap__/aa_highlight__top',
46+
query: {
47+
value:
48+
'__aa-highlight__zelda__/aa-highlight__ switch',
4849
},
4950
},
5051
};
5152
const reverseSnippetedParts = parseAlgoliaHitReverseSnippet({
5253
hit,
53-
attribute: 'name',
54+
attribute: 'query',
5455
});
5556

56-
// [{ value: 'Lap', isHighlighted: false }, { value: 'top', isHighlighted: true }]
57+
/*
58+
* [
59+
* { value: 'zelda', isHighlighted: false },
60+
* { value: ' switch', isHighlighted: true },
61+
* ]
62+
*/
5763
```
5864

5965
## Example with nested attributes
6066

6167
```js
6268
import { parseAlgoliaHitReverseSnippet } from '@algolia/autocomplete-preset-algolia';
6369

64-
// An Algolia hit for query "lap"
70+
// An Algolia hit for query "video"
6571
const hit = {
66-
name: {
67-
type: 'Laptop',
72+
hierarchicalCategories: {
73+
lvl1: 'Video games',
6874
},
6975
_snippetResult: {
70-
name: {
71-
type: {
72-
value: '__aa_highlight__Lap__/aa_highlight__top',
76+
hierarchicalCategories: {
77+
lvl1: {
78+
value:
79+
'__aa-highlight__Video__/aa-highlight__ games',
7380
},
7481
},
7582
},
7683
};
7784
const reverseSnippetedParts = parseAlgoliaHitReverseSnippet({
7885
hit,
79-
attribute: ['name', 'type'],
86+
attribute: ['hierarchicalCategories', 'lvl1'],
8087
});
8188

82-
// [{ value: 'Lap', isHighlighted: false }, { value: 'top', isHighlighted: true }]
89+
/*
90+
* [
91+
* { value: 'Video', isHighlighted: false },
92+
* { value: ' games', isHighlighted: true },
93+
* ]
94+
*/
8395
```
8496

8597
## Parameters

packages/website/docs/parseAlgoliaHitSnippet.md

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,15 @@ If you don't use a package manager, you can use a standalone endpoint:
3737
### With a single string
3838

3939
```js
40-
import { parseAlgoliaHitSnippet } from '@algolia/autocomplete-preset-algolia';
40+
import { parseAlgoliaHitHighlight } from '@algolia/autocomplete-preset-algolia';
4141

42-
// An Algolia hit for query "lap"
42+
// An Algolia hit for query "the"
4343
const hit = {
44-
name: 'Laptop',
44+
name: 'The Legend of Zelda: Breath of the Wild',
4545
_snippetResult: {
4646
name: {
47-
value: '__aa_highlight__Lap__/aa_highlight__top',
47+
value:
48+
'__aa-highlight__The__/aa-highlight__ Legend of Zelda: Breath of __aa-highlight__the__/aa-highlight__ Wild',
4849
},
4950
},
5051
};
@@ -53,33 +54,48 @@ const snippetedParts = parseAlgoliaHitSnippet({
5354
attribute: 'name',
5455
});
5556

56-
// [{ value: 'Lap', isHighlighted: true }, { value: 'top', isHighlighted: false }]
57+
/*
58+
* [
59+
* { value: 'The', isHighlighted: true },
60+
* { value: ' Legend of Zelda: Breath of ', isHighlighted: false },
61+
* { value: 'the', isHighlighted: true },
62+
* { value: ' Wild', isHighlighted: false },
63+
* ]
64+
*/
5765
```
5866

5967
### With nested attributes
6068

6169
```js
6270
import { parseAlgoliaHitSnippet } from '@algolia/autocomplete-preset-algolia';
6371

64-
// An Algolia hit for query "lap"
72+
// An Algolia hit for query "cam"
6573
const hit = {
66-
name: {
67-
type: 'Laptop',
74+
hierarchicalCategories: {
75+
lvl1: 'Cameras & Camcoders',
6876
},
6977
_snippetResult: {
70-
name: {
71-
type: {
72-
value: '__aa_highlight__Lap__/aa_highlight__top',
78+
hierarchicalCategories: {
79+
lvl1: {
80+
value:
81+
'__aa-highlight__Cam__/aa-highlight__eras & __aa-highlight__Cam__/aa-highlight__coders',
7382
},
7483
},
7584
},
7685
};
7786
const snippetedParts = parseAlgoliaHitSnippet({
7887
hit,
79-
attribute: ['name', 'type'],
88+
attribute: ['hierarchicalCategories', 'lvl1'],
8089
});
8190

82-
// [{ value: 'Lap', isHighlighted: true }, { value: 'top', isHighlighted: false }]
91+
/*
92+
* [
93+
* { value: 'Cam', isHighlighted: true },
94+
* { value: 'eras & ', isHighlighted: false },
95+
* { value: 'Cam', isHighlighted: true },
96+
* { value: 'coders', isHighlighted: false },
97+
* ]
98+
*/
8399
```
84100

85101
## Parameters

packages/website/docs/reverseSnippetHit.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ If you're referencing a nested attribute, you can use the array syntax.
3838
```js
3939
import { reverseSnippetHit } from '@algolia/autocomplete-js';
4040

41-
// An Algolia hit for query "hello"
41+
// An Algolia hit for query "video"
4242
const hit = {
4343
hierarchicalCategories: {
4444
lvl1: 'Video games',

packages/website/docs/snippetHit.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ To determine what attribute to parse, you can pass it as a string.
1515
```js
1616
import { snippetHit } from '@algolia/autocomplete-js';
1717

18-
// An Algolia hit for query "he"
18+
// An Algolia hit for query "the"
1919
const hit = {
20-
query: 'Hello there',
20+
name: 'The Legend of Zelda: Breath of the Wild',
2121
_snippetResult: {
2222
query: {
2323
value:
24-
'__aa-highlight__He__/aa-highlight__llo t__aa-highlight__he__/aa-highlight__re',
24+
'__aa-highlight__The__/aa-highlight__ Legend of Zelda: Breath of __aa-highlight__the__/aa-highlight__ Wild',
2525
},
2626
},
2727
};
@@ -38,23 +38,23 @@ If you're referencing a nested attribute, you can use the array syntax.
3838
```js
3939
import { snippetHit } from '@algolia/autocomplete-js';
4040

41-
// An Algolia hit for query "he"
41+
// An Algolia hit for query "cam"
4242
const hit = {
43-
query: {
44-
title: 'Hello there',
45-
}
43+
hierarchicalCategories: {
44+
lvl1: 'Cameras & Camcoders',
45+
},
4646
_snippetResult: {
47-
query: {
48-
title: {
47+
hierarchicalCategories: {
48+
lvl1: {
4949
value:
50-
'__aa-highlight__He__/aa-highlight__llo t__aa-highlight__he__/aa-highlight__re',
50+
'__aa-highlight__Cam__/aa-highlight__eras & __aa-highlight__Cam__/aa-highlight__coders',
5151
},
5252
},
5353
},
5454
};
5555
const snippetedValue = snippetHit({
5656
hit,
57-
attribute: ['query', 'title'],
57+
attribute: ['hierarchicalCategories', 'lvl1'],
5858
});
5959
```
6060

0 commit comments

Comments
 (0)