vuepress-theme-uniapp-official 1.6.17 → 1.6.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md
CHANGED
|
@@ -386,30 +386,37 @@ export default {
|
|
|
386
386
|
this.showLoading = true;
|
|
387
387
|
this.searchByAlgolia()
|
|
388
388
|
.then(({ hitsPerPage, nbHits, nbPages, page, hits, queryID, indexName }) => {
|
|
389
|
-
this.
|
|
389
|
+
this.noResult = !this.resultList.length;
|
|
390
|
+
this.curHits = nbHits;
|
|
391
|
+
this.pageSize = hitsPerPage;
|
|
392
|
+
this.totalPage = nbPages;
|
|
393
|
+
this.curPage = page + 1;
|
|
394
|
+
|
|
395
|
+
this.resultList = hits.map((item, index) => {
|
|
390
396
|
const items = item.getItems();
|
|
391
397
|
return {
|
|
392
398
|
...item,
|
|
393
399
|
title: removeHighlightTags(items[0]),
|
|
394
400
|
items,
|
|
395
401
|
onSelect: ({ item, event }) => {
|
|
402
|
+
/* aa("convertedObjectIDsAfterSearch", {
|
|
403
|
+
eventName: "Article Read",
|
|
404
|
+
index: "YourIndexName",
|
|
405
|
+
queryID: "query-1",
|
|
406
|
+
objectIDs: ["objectID-1"],
|
|
407
|
+
}); */
|
|
396
408
|
aa("clickedObjectIDsAfterSearch", {
|
|
397
409
|
index: indexName,
|
|
398
410
|
eventName: `[${this.currentCategory.text}] Item Clicked`,
|
|
399
411
|
queryID,
|
|
400
412
|
objectIDs: [item.objectID],
|
|
401
|
-
positions: [1],
|
|
413
|
+
positions: [(index + 1) + (page * hitsPerPage)],
|
|
402
414
|
});
|
|
415
|
+
item.onSelect()
|
|
403
416
|
}
|
|
404
417
|
};
|
|
405
418
|
});
|
|
406
419
|
|
|
407
|
-
this.noResult = !this.resultList.length;
|
|
408
|
-
this.curHits = nbHits;
|
|
409
|
-
this.pageSize = hitsPerPage;
|
|
410
|
-
this.totalPage = nbPages;
|
|
411
|
-
this.curPage = page + 1;
|
|
412
|
-
|
|
413
420
|
if (this.curPage === 1 && this.showAIMessage) {
|
|
414
421
|
this.resultList.splice(1, 0, this.aiMessage);
|
|
415
422
|
}
|
|
@@ -1,106 +1,119 @@
|
|
|
1
|
-
import algoliasearch from 'algoliasearch
|
|
2
|
-
import aa from
|
|
3
|
-
import { removeHighlightTags, groupBy } from './searchUtils'
|
|
1
|
+
import algoliasearch from 'algoliasearch';
|
|
2
|
+
import aa from 'search-insights';
|
|
3
|
+
import { removeHighlightTags, groupBy } from './searchUtils';
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
searchClient = algoliasearch(appId, apiKey);
|
|
9
|
-
aa("init", { appId, apiKey });
|
|
10
|
-
searchClient.addAlgoliaAgent('dcloudsearch', '1.0.0');
|
|
5
|
+
/**
|
|
6
|
+
* @typedef {import('algoliasearch').SearchClient} SearchClient
|
|
7
|
+
*/
|
|
11
8
|
|
|
12
|
-
|
|
9
|
+
let searchIndex;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
*
|
|
13
|
+
* @param {string} appId
|
|
14
|
+
* @param {string} apiKey
|
|
15
|
+
* @returns {ReturnType<SearchClient['initIndex']>}
|
|
16
|
+
*/
|
|
17
|
+
function getSearchIndex(appId, apiKey, indexName) {
|
|
18
|
+
if (searchIndex) return searchIndex;
|
|
19
|
+
const searchClient = algoliasearch(appId, apiKey);
|
|
20
|
+
searchIndex = searchClient.initIndex(indexName);
|
|
21
|
+
aa('init', { appId, apiKey });
|
|
22
|
+
searchClient.addAlgoliaAgent('dcloudsearch', '1.0.0');
|
|
23
|
+
|
|
24
|
+
return searchIndex;
|
|
13
25
|
}
|
|
14
26
|
|
|
15
|
-
export function search({
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
27
|
+
export function search({
|
|
28
|
+
query,
|
|
29
|
+
indexName,
|
|
30
|
+
appId,
|
|
31
|
+
apiKey,
|
|
32
|
+
searchParameters = {},
|
|
33
|
+
snippetLength = 0,
|
|
34
|
+
transformItems = () => {},
|
|
35
|
+
onClose = () => {},
|
|
36
|
+
...args
|
|
37
|
+
}) {
|
|
38
|
+
return getSearchIndex(appId, apiKey, indexName)
|
|
39
|
+
.search(query, {
|
|
40
|
+
attributesToRetrieve: [
|
|
41
|
+
'hierarchy.lvl0',
|
|
42
|
+
'hierarchy.lvl1',
|
|
43
|
+
'hierarchy.lvl2',
|
|
44
|
+
'hierarchy.lvl3',
|
|
45
|
+
'hierarchy.lvl4',
|
|
46
|
+
'hierarchy.lvl5',
|
|
47
|
+
'hierarchy.lvl6',
|
|
48
|
+
'content',
|
|
49
|
+
'type',
|
|
50
|
+
'url',
|
|
51
|
+
'url_without_anchor',
|
|
52
|
+
'category',
|
|
53
|
+
'tag',
|
|
54
|
+
],
|
|
55
|
+
attributesToSnippet: [
|
|
56
|
+
`hierarchy.lvl1:${snippetLength}`,
|
|
57
|
+
`hierarchy.lvl2:${snippetLength}`,
|
|
58
|
+
`hierarchy.lvl3:${snippetLength}`,
|
|
59
|
+
`hierarchy.lvl4:${snippetLength}`,
|
|
60
|
+
`hierarchy.lvl5:${snippetLength}`,
|
|
61
|
+
`hierarchy.lvl6:${snippetLength}`,
|
|
62
|
+
`content:${snippetLength}`,
|
|
63
|
+
],
|
|
64
|
+
snippetEllipsisText: '…',
|
|
65
|
+
highlightPreTag: '<mark>',
|
|
66
|
+
highlightPostTag: '</mark>',
|
|
67
|
+
hitsPerPage: 20,
|
|
68
|
+
clickAnalytics: true,
|
|
69
|
+
...searchParameters,
|
|
70
|
+
...args,
|
|
71
|
+
})
|
|
72
|
+
.catch(error => {
|
|
73
|
+
throw error;
|
|
74
|
+
})
|
|
75
|
+
.then(({ hits, hitsPerPage, nbHits, nbPages, page, queryID }) => {
|
|
76
|
+
const sources = groupBy(hits, hit => removeHighlightTags(hit));
|
|
77
|
+
return {
|
|
78
|
+
hitsPerPage,
|
|
79
|
+
nbHits,
|
|
80
|
+
nbPages,
|
|
81
|
+
page,
|
|
82
|
+
hits: Object.values(sources).map((items, index) => {
|
|
83
|
+
return {
|
|
84
|
+
sourceId: `hits${index}`,
|
|
85
|
+
onSelect({ item, event }) {
|
|
86
|
+
// saveRecentSearch(item);
|
|
70
87
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
indexName
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
}
|
|
88
|
+
if (!event.shiftKey && !event.ctrlKey && !event.metaKey) {
|
|
89
|
+
onClose();
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
getItemUrl({ item }) {
|
|
93
|
+
return item.url;
|
|
94
|
+
},
|
|
95
|
+
getItems() {
|
|
96
|
+
return Object.values(groupBy(items, item => item.hierarchy.lvl1))
|
|
97
|
+
.map(transformItems)
|
|
98
|
+
.map(groupedHits =>
|
|
99
|
+
groupedHits.map(item => {
|
|
100
|
+
return {
|
|
101
|
+
...item,
|
|
102
|
+
__docsearch_parent:
|
|
103
|
+
item.type !== 'lvl1' &&
|
|
104
|
+
groupedHits.find(
|
|
105
|
+
siblingItem =>
|
|
106
|
+
siblingItem.type === 'lvl1' && siblingItem.hierarchy.lvl1 === item.hierarchy.lvl1
|
|
107
|
+
),
|
|
108
|
+
};
|
|
109
|
+
})
|
|
110
|
+
)
|
|
111
|
+
.flat();
|
|
112
|
+
},
|
|
113
|
+
};
|
|
114
|
+
}),
|
|
115
|
+
queryID,
|
|
116
|
+
indexName,
|
|
117
|
+
};
|
|
118
|
+
});
|
|
119
|
+
}
|