Skip to content

Commit 2ec15f8

Browse files
authored
Merge pull request #4198 from ClickHouse/4187-improve-algolia-search-infra
4187 improve algolia search infra
2 parents e65d389 + f412d11 commit 2ec15f8

File tree

2 files changed

+118
-165
lines changed

2 files changed

+118
-165
lines changed

scripts/search/settings.json

Lines changed: 53 additions & 164 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
"hitsPerPage": 20,
66
"maxValuesPerFacet": 100,
77
"searchableAttributes": [
8+
"title",
89
"h1",
9-
"h2",
10-
"unordered(keywords)",
10+
"h2",
1111
"h3",
12+
"keywords",
1213
"content",
13-
"h4",
14-
"title"
14+
"h4"
1515
],
1616
"numericAttributesToIndex": null,
1717
"attributesToRetrieve": [
@@ -20,26 +20,53 @@
2020
"anchor",
2121
"url",
2222
"url_without_anchor",
23-
"type"
23+
"type",
24+
"title"
2425
],
2526
"camelCaseAttributes": [
26-
"h2"
27+
"h1",
28+
"h2",
29+
"h3",
30+
"title"
2731
],
2832
"attributeCriteriaComputedByMinProximity": false,
2933
"distinct": true,
3034
"unretrievableAttributes": null,
31-
"optionalWords": null,
35+
"optionalWords": [
36+
"clickhouse",
37+
"database",
38+
"function",
39+
"query",
40+
"table",
41+
"how",
42+
"to",
43+
"what",
44+
"is",
45+
"can",
46+
"do",
47+
"does",
48+
"will",
49+
"should",
50+
"the",
51+
"a",
52+
"an"
53+
],
3254
"attributesForFaceting": null,
3355
"attributesToSnippet": [
34-
"content:10"
56+
"content:15",
57+
"title:10"
3558
],
3659
"attributesToHighlight": [
3760
"hierarchy",
38-
"content"
61+
"content",
62+
"title",
63+
"h1",
64+
"h2",
65+
"h3"
3966
],
4067
"paginationLimitedTo": 1000,
4168
"attributeForDistinct": "url",
42-
"exactOnSingleWordQuery": "attribute",
69+
"exactOnSingleWordQuery": "word",
4370
"disableExactOnAttributes": [
4471
"content"
4572
],
@@ -56,8 +83,8 @@
5683
"desc(score)",
5784
"desc(page_rank)"
5885
],
59-
"separatorsToIndex": "_",
60-
"removeWordsIfNoResults": "none",
86+
"separatorsToIndex": "_-",
87+
"removeWordsIfNoResults": "allOptional",
6188
"queryType": "prefixLast",
6289
"highlightPreTag": "<em>",
6390
"highlightPostTag": "</span>",
@@ -72,129 +99,51 @@
7299
},
73100
"rules": [
74101
{
75-
"_metadata": {
76-
"lastUpdate": 1740676875
77-
},
78102
"conditions": [
79103
{
80-
"anchoring": "is",
81-
"pattern": "if",
82-
"alternatives": true
104+
"anchoring": "contains",
105+
"pattern": "how to scale"
83106
}
84107
],
85108
"consequence": {
86109
"params": {
87-
"query": "conditional functions"
88-
},
89-
"filterPromotes": true
90-
},
91-
"enabled": true,
92-
"objectID": "qr-1738846919179"
93-
},
94-
{
95-
"_metadata": {
96-
"lastUpdate": 1740676875
97-
},
98-
"conditions": [
99-
{
100-
"anchoring": "is",
101-
"pattern": "engine",
102-
"alternatives": true
110+
"query": "scaling horizontal distributed"
103111
}
104-
],
105-
"consequence": {
106-
"params": {
107-
"query": "table engine"
108-
},
109-
"filterPromotes": true
110112
},
111113
"enabled": true,
112-
"objectID": "qr-1737830547773"
114+
"objectID": "how-to-scale-rule"
113115
},
114116
{
115-
"_metadata": {
116-
"lastUpdate": 1740676875
117-
},
118117
"conditions": [
119118
{
120-
"anchoring": "is",
121-
"pattern": "log",
122-
"alternatives": true
119+
"anchoring": "contains",
120+
"pattern": "how to optimize"
123121
}
124122
],
125123
"consequence": {
126124
"params": {
127-
"query": "log logarithm"
128-
},
129-
"filterPromotes": true
130-
},
131-
"enabled": true,
132-
"objectID": "qr-1737830510872"
133-
},
134-
{
135-
"_metadata": {
136-
"lastUpdate": 1740676875
137-
},
138-
"conditions": [
139-
{
140-
"anchoring": "is",
141-
"pattern": "distinct",
142-
"alternatives": true
125+
"query": "optimization performance tuning"
143126
}
144-
],
145-
"consequence": {
146-
"params": {
147-
"query": "distinct clause"
148-
},
149-
"filterPromotes": true
150127
},
151128
"enabled": true,
152-
"objectID": "qr-1737830488435"
129+
"objectID": "how-to-optimize-rule"
153130
},
154131
{
155-
"_metadata": {
156-
"lastUpdate": 1740676875
157-
},
158132
"conditions": [
159133
{
160-
"anchoring": "is",
161-
"pattern": "case when",
162-
"alternatives": true
134+
"anchoring": "contains",
135+
"pattern": "what is"
163136
}
164137
],
165138
"consequence": {
166139
"params": {
167-
"query": "conditional functions"
168-
},
169-
"filterPromotes": true
170-
},
171-
"enabled": true,
172-
"objectID": "qr-1737830405215"
173-
},
174-
{
175-
"_metadata": {
176-
"lastUpdate": 1740676875
177-
},
178-
"conditions": [
179-
{
180-
"anchoring": "is",
181-
"pattern": "case",
182-
"alternatives": true
140+
"removeWordsIfNoResults": "allOptional"
183141
}
184-
],
185-
"consequence": {
186-
"params": {
187-
"query": "conditional function"
188-
},
189-
"filterPromotes": true
190142
},
191143
"enabled": true,
192-
"objectID": "qr-1737828323150"
144+
"objectID": "what-is-rule"
193145
},
194146
{
195-
"_metadata": {
196-
"lastUpdate": 1740676875
197-
},
198147
"conditions": [
199148
{
200149
"anchoring": "is",
@@ -209,67 +158,7 @@
209158
"filterPromotes": true
210159
},
211160
"enabled": true,
212-
"objectID": "qr-1737813426327"
213-
},
214-
{
215-
"_metadata": {
216-
"lastUpdate": 1740676875
217-
},
218-
"conditions": [
219-
{
220-
"anchoring": "is",
221-
"pattern": "config.xml",
222-
"alternatives": true
223-
}
224-
],
225-
"consequence": {
226-
"params": {
227-
"query": "Server Settings"
228-
},
229-
"filterPromotes": true
230-
},
231-
"enabled": true,
232-
"objectID": "qr-1737813311997"
233-
},
234-
{
235-
"_metadata": {
236-
"lastUpdate": 1740676875
237-
},
238-
"conditions": [
239-
{
240-
"anchoring": "is",
241-
"pattern": "client",
242-
"alternatives": true
243-
}
244-
],
245-
"consequence": {
246-
"params": {
247-
"query": "clickhouse client"
248-
},
249-
"filterPromotes": true
250-
},
251-
"enabled": true,
252-
"objectID": "qr-1737813247403"
253-
},
254-
{
255-
"_metadata": {
256-
"lastUpdate": 1740676875
257-
},
258-
"conditions": [
259-
{
260-
"anchoring": "is",
261-
"pattern": "between",
262-
"alternatives": true
263-
}
264-
],
265-
"consequence": {
266-
"params": {
267-
"query": "between function"
268-
},
269-
"filterPromotes": true
270-
},
271-
"enabled": true,
272-
"objectID": "qr-1737813177623"
161+
"objectID": "qr-clickhouse-main"
273162
}
274163
]
275-
}
164+
}

src/theme/SearchBar/index.js

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,77 @@ function Hit({ hit, children }) {
3737

3838
function ResultsFooter({ state, onClose }) {
3939
const generateSearchPageLink = useSearchLinkCreator();
40+
41+
const handleKapaClick = useCallback(() => {
42+
onClose(); // Close search modal first
43+
44+
// Use Kapa's official API to open with query
45+
if (typeof window !== 'undefined' && window.Kapa) {
46+
window.Kapa('open', {
47+
query: state.query || '',
48+
submit: !!state.query
49+
});
50+
} else {
51+
console.warn('Kapa widget not loaded');
52+
}
53+
}, [state.query, onClose]);
54+
4055
return (
41-
<Link to={generateSearchPageLink(state.query)} onClick={onClose}>
56+
<div style={{
57+
padding: '12px 16px',
58+
borderTop: '1px solid var(--docsearch-modal-shadow)',
59+
display: 'flex',
60+
flexDirection: 'column',
61+
gap: '8px'
62+
}}>
63+
{/* Kapa AI Button */}
64+
<button
65+
onClick={handleKapaClick}
66+
style={{
67+
display: 'flex',
68+
alignItems: 'center',
69+
justifyContent: 'center',
70+
width: '100%',
71+
padding: '12px 16px',
72+
backgroundColor: '#5b4cfe',
73+
color: 'white',
74+
border: 'none',
75+
borderRadius: '6px',
76+
fontSize: '14px',
77+
cursor: 'pointer',
78+
fontWeight: 600,
79+
transition: 'all 0.2s ease'
80+
}}
81+
onMouseEnter={(e) => {
82+
e.target.style.backgroundColor = '#4a3dcc';
83+
e.target.style.transform = 'translateY(-1px)';
84+
}}
85+
onMouseLeave={(e) => {
86+
e.target.style.backgroundColor = '#5b4cfe';
87+
e.target.style.transform = 'translateY(0)';
88+
}}
89+
>
90+
🤖 Ask AI{state.query ? ` about "${state.query}"` : ''}
91+
</button>
92+
93+
{/* Original "See all results" link */}
94+
<Link
95+
to={generateSearchPageLink(state.query)}
96+
onClick={onClose}
97+
style={{
98+
textAlign: 'center',
99+
fontSize: '13px',
100+
color: 'var(--docsearch-muted-color)',
101+
textDecoration: 'none'
102+
}}
103+
>
42104
<Translate
43105
id="theme.SearchBar.seeAll"
44106
values={{ count: state.context.nbHits }}>
45107
{'See all {count} results'}
46108
</Translate>
47109
</Link>
110+
</div>
48111
);
49112
}
50113

@@ -69,6 +132,7 @@ function DocSearch({ contextualSearch, externalUrlRegex, ...props }) {
69132
...props.searchParameters,
70133
facetFilters,
71134
clickAnalytics: true,
135+
hitsPerPage: 3,
72136
};
73137
const { isAskAIOpen, currentMode } = useAskAI();
74138
const history = useHistory();

0 commit comments

Comments
 (0)