Skip to content

Commit bfb8af2

Browse files
Samuel Bodinshortcuts
Samuel Bodin
andauthored
fix: search index spec (#8)
Co-authored-by: Clément Vannicatte <[email protected]>
1 parent d4e2278 commit bfb8af2

29 files changed

+2226
-540
lines changed

.env.example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
ALGOLIA_APPLICATION_ID=""
2+
ALGOLIA_ADMIN_KEY=""
3+
ALGOLIA_SEARCH_KEY=""

app.ts

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1-
import { searchClient } from 'algoliasearch-client-javascript';
1+
import { searchClient, HttpError } from 'algoliasearch-client-javascript';
2+
import dotenv from 'dotenv';
3+
4+
dotenv.config();
5+
6+
const appId = process.env.ALGOLIA_APPLICATION_ID || '**** APP_ID *****';
7+
const apiKey = process.env.ALGOLIA_SEARCH_KEY || '**** SEARCH_API_KEY *****';
28

3-
const appId = process.env.ALGOLIA_APPLICATION_ID_1 || '**** APP_ID *****';
4-
const apiKey = process.env.ALGOLIA_ADMIN_KEY_1 || '**** API_KEY *****';
59
// Init client with appId and apiKey
610
const client = new searchClient(appId, apiKey);
711

8-
async function testClient() {
9-
// test openapi gen
12+
async function testMultiQueries() {
1013
try {
1114
const res = await client.multipleQueries({
1215
requests: [
@@ -17,10 +20,31 @@ async function testClient() {
1720
],
1821
});
1922

20-
console.log('[1-RESPONSE]', res);
23+
console.log(`[OK]`, res);
2124
} catch (e) {
22-
console.error('[1-ERROR]', e);
25+
if (e instanceof HttpError) {
26+
return console.log(`[${e.statusCode} - ${e.response.statusMessage}]`, e.response);
27+
}
28+
29+
console.log('[ERROR]', e);
30+
}
31+
}
32+
33+
async function testSearch() {
34+
try {
35+
const res = await client.search('docsearch', {
36+
query: 'crawler',
37+
});
38+
39+
console.log(`[OK]`, res);
40+
} catch (e) {
41+
if (e instanceof HttpError) {
42+
return console.log(`[${e.statusCode} - ${e.response.statusMessage}]`, e.response);
43+
}
44+
45+
console.log('[ERROR]', e);
2346
}
2447
}
2548

26-
testClient();
49+
// testMultiQueries();
50+
testSearch();

openapi_spec/paths/indexes/batch.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ post:
1212
schema:
1313
title: batchObject
1414
type: object
15+
additionalProperties: false
1516
properties:
1617
requests:
1718
type: array

openapi_spec/paths/indexes/multipleQueries.yml

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ post:
2424
example: products
2525
description: The Algolia index name
2626
query:
27-
type: string
28-
description: The query to search for
27+
$ref: ../../schemas/SearchParams.yml#/searchParams/properties/query
2928
type:
3029
type: string
3130
enum: [default, facet]
@@ -57,22 +56,8 @@ post:
5756
results:
5857
type: array
5958
items:
60-
type: object
61-
additionalProperties: false
62-
properties:
63-
hits:
64-
type: array
65-
items:
66-
type: object
67-
additionalProperties: false
68-
properties:
69-
objectID:
70-
$ref: '../../responses/common.yml#/objectID'
71-
nbHits:
72-
type: integer
73-
queryID:
74-
$ref: '../../responses/common.yml#/queryID'
59+
$ref: ../../schemas/SearchResponse.yml#/searchResponse
7560
'400':
76-
$ref: '../../responses/BadRequest.yml'
61+
$ref: ../../responses/BadRequest.yml
7762
'404':
78-
$ref: '../../responses/IndexNotFound.yml'
63+
$ref: ../../responses/IndexNotFound.yml

openapi_spec/paths/indexes/search.yml

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,22 @@ post:
66
parameters:
77
- $ref: '../../parameters.yml#/IndexName'
88
requestBody:
9-
$ref: '../../schemas/SearchParams.yml'
9+
required: true
10+
content:
11+
application/json:
12+
schema:
13+
oneOf:
14+
- $ref: ../../schemas/SearchParams.yml#/searchParams
15+
- $ref: ../../schemas/SearchParams.yml#/searchParamsString
1016
responses:
1117
'200':
1218
description: OK
1319
content:
1420
application/json:
1521
schema:
1622
title: singleQueryResponse
17-
type: object
18-
additionalProperties: false
19-
properties:
20-
hits:
21-
type: array
22-
items:
23-
type: object
24-
additionalProperties: false
25-
properties:
26-
objectID:
27-
$ref: '../../responses/common.yml#/objectID'
28-
nbHits:
29-
type: integer
30-
queryID:
31-
type: string
32-
pattern: '^[a-f0-9]{32}$'
33-
example: 43b15df305339e827f0ac0bdc5ebcaa7
23+
$ref: ../../schemas/SearchResponse.yml#/searchResponse
3424
'400':
35-
$ref: '../../responses/BadRequest.yml'
25+
$ref: ../../responses/BadRequest.yml
3626
'404':
37-
$ref: '../../responses/IndexNotFound.yml'
27+
$ref: ../../responses/IndexNotFound.yml

openapi_spec/responses/common.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,26 @@
11
taskID:
22
type: integer
33
description: taskID of the indexing task to wait for.
4+
45
objectID:
56
type: string
67
description: Unique identifier of the object
8+
79
objectIDs:
810
type: array
911
items:
1012
type: string
1113
description: List of objectID
14+
1215
queryID:
1316
type: string
1417
pattern: '^[a-f0-9]{32}$'
1518
example: 43b15df305339e827f0ac0bdc5ebcaa7
19+
20+
abTestID:
21+
type: integer
22+
description: If a search encounters an index that is being A/B tested, abTestID reports the ongoing A/B test ID.
23+
24+
abTestVariantID:
25+
type: integer
26+
description: If a search encounters an index that is being A/B tested, abTestVariantID reports the variant ID of the index used.
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
allowCompressionOfIntegerArray:
2+
type: boolean
3+
description: Enables compression of large integer arrays.
4+
default: false
5+
6+
attributeForDistinct:
7+
type: string
8+
description: Name of the de-duplication attribute to be used with the distinct feature.
9+
default: null
10+
11+
attributesToTransliterate:
12+
type: array
13+
items:
14+
type: string
15+
description: Specify on which attributes to apply transliteration.
16+
17+
camelCaseAttributes:
18+
type: array
19+
items:
20+
type: string
21+
description: List of attributes on which to do a decomposition of camel case words.
22+
default: []
23+
24+
customNormalization:
25+
type: object
26+
additionalProperties: true
27+
description: Override the default normalization handled by the engine.
28+
default: {}
29+
30+
decompoundedAttributes:
31+
type: object
32+
additionalProperties: true
33+
description: Specify on which attributes in your index Algolia should apply word segmentation, also known as decompounding.
34+
default: {}
35+
36+
disablePrefixOnAttributes:
37+
type: array
38+
items:
39+
type: string
40+
description: List of attributes on which you want to disable prefix matching.
41+
default: []
42+
43+
disableTypoToleranceOnWords:
44+
type: array
45+
items:
46+
type: string
47+
description: A list of words for which you want to turn off typo tolerance.
48+
default: []
49+
50+
filterPromotes:
51+
type: boolean
52+
description: Whether promoted results should match the filters of the current search, except for geographic filters.
53+
default: false
54+
55+
indexLanguages:
56+
type: array
57+
items:
58+
type: string
59+
description: Sets the languages at the index level for language-specific processing such as tokenization and normalization.
60+
default: []
61+
62+
numericAttributesForFiltering:
63+
type: array
64+
items:
65+
type: string
66+
description: List of numeric attributes that can be used as numerical filters.
67+
default: null
68+
69+
paginationLimitedTo:
70+
type: integer
71+
description: Set the maximum number of hits accessible via pagination.
72+
default: 1000
73+
74+
userData:
75+
type: object
76+
additionalProperties: true
77+
description: Lets you store custom data in your indices.
78+
default: {}
79+
80+
replicas:
81+
type: array
82+
items:
83+
type: string
84+
description: Creates replicas, exact copies of an index.
85+
default: []

openapi_spec/schemas/Record.yml

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
record:
2+
type: object
3+
description: A single record
4+
additionalProperties: true
5+
required:
6+
- objectID
7+
properties:
8+
objectID:
9+
$ref: '../responses/common.yml#/objectID'
10+
_highlightResult:
11+
$ref: '#/highlightResult'
12+
_snippetResult:
13+
$ref: '#/snippetResult'
14+
_rankingInfo:
15+
$ref: '#/rankingInfo'
16+
_distinctSeqID:
17+
type: number
18+
19+
# Props
20+
highlightResult:
21+
type: object
22+
additionalProperties: false
23+
properties:
24+
value:
25+
type: string
26+
description: 'Markup text with occurrences highlighted.'
27+
example: '<em>George</em> <em>Clo</em>oney'
28+
matchLevel:
29+
type: string
30+
description: 'Indicates how well the attribute matched the search query.'
31+
enum: [none, partial, full]
32+
matchedWords:
33+
type: array
34+
description: List of words from the query that matched the object.
35+
items:
36+
type: string
37+
fullyHighlighted:
38+
type: boolean
39+
description: 'Whether the entire attribute value is highlighted.'
40+
41+
snippetResult:
42+
type: object
43+
additionalProperties: false
44+
properties:
45+
value:
46+
type: string
47+
description: 'Markup text with occurrences highlighted.'
48+
example: '<em>George</em> <em>Clo</em>oney...'
49+
matchLevel:
50+
type: string
51+
description: 'Indicates how well the attribute matched the search query.'
52+
enum: [none, partial, full]
53+
54+
rankingInfo:
55+
type: object
56+
additionalProperties: false
57+
properties:
58+
filters:
59+
type: integer
60+
description: 'This field is reserved for advanced usage.'
61+
firstMatchedWord:
62+
type: integer
63+
description: 'Position of the most important matched attribute in the attributes to index list.'
64+
geoDistance:
65+
type: integer
66+
description: 'Distance between the geo location in the search query and the best matching geo location in the record, divided by the geo precision (in meters).'
67+
geoPrecision:
68+
type: integer
69+
description: 'Precision used when computing the geo distance, in meters.'
70+
matchedGeoLocation:
71+
type: object
72+
additionalProperties:
73+
type: object
74+
additionalProperties: false
75+
properties:
76+
lat:
77+
type: float
78+
description: 'Latitude of the matched location.'
79+
lng:
80+
type: float
81+
description: 'Longitude of the matched location.'
82+
distance:
83+
type: integer
84+
description: 'Distance between the matched location and the search location (in meters).'
85+
nbExactWords:
86+
type: integer
87+
description: 'Number of exactly matched words.'
88+
nbTypos:
89+
type: integer
90+
description: 'Number of typos encountered when matching the record.'
91+
promoted:
92+
type: boolean
93+
description: 'Present and set to true if a Rule promoted the hit.'
94+
proximityDistance:
95+
type: integer
96+
description: 'When the query contains more than one word, the sum of the distances between matched words (in meters).'
97+
userScore:
98+
type: integer
99+
description: 'Custom ranking for the object, expressed as a single integer value.'
100+
word:
101+
type: integer
102+
description: 'Number of matched words, including prefixes and typos.'
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Not used yet
2+
3+
# timeouts:
4+
# type: object
5+
# additionalProperties: false
6+
# properties:
7+
# connect:
8+
# type: integer
9+
# description: 'Connection timeout in seconds.'
10+
# example: 2
11+
# read:
12+
# type: integer
13+
# description: 'Read timeout in seconds.'
14+
# example: 5
15+
# write:
16+
# type: integer
17+
# description: 'Write timeout in seconds.'
18+
# example: 30
19+
20+
# X-Algolia-UserToken:
21+
# type: string
22+
# X-Forwarded-For:
23+
# type: string

0 commit comments

Comments
 (0)