Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: search index spec #8

Merged
merged 15 commits into from
Nov 18, 2021
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ALGOLIA_APPLICATION_ID=""
ALGOLIA_ADMIN_KEY=""
ALGOLIA_SEARCH_KEY=""
shortcuts marked this conversation as resolved.
Show resolved Hide resolved
38 changes: 29 additions & 9 deletions app.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import { searchClient } from 'algoliasearch-client-javascript';
import { searchClient, HttpError } from 'algoliasearch-client-javascript';
import dotenv from 'dotenv';

dotenv.config();

const appId = process.env.ALGOLIA_APPLICATION_ID || '**** APP_ID *****';
const apiKey = process.env.ALGOLIA_SEARCH_KEY || '**** SEARCH_API_KEY *****';

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

async function testClient() {
// test openapi gen
async function testMultiQueries() {
try {
const res = await client.multipleQueries({
const { response, body } = await client.multipleQueries({
requests: [
{
indexName: 'docsearch',
Expand All @@ -17,10 +20,27 @@ async function testClient() {
],
});

console.log('[1-RESPONSE]', res);
console.log(`[${response.statusCode} - ${response.statusMessage}]`, body.results);
} catch (e) {
if (e instanceof HttpError) {
console.log(`[${e.statusCode} - ${e.response.statusMessage}]`, e.response);
}
}
}

async function testSearch() {
try {
const { response, body } = await client.search('docsearch', {
shortcuts marked this conversation as resolved.
Show resolved Hide resolved
query: 'crawler',
});

console.log(`[${response.statusCode} - ${response.statusMessage}]`, body);
} catch (e) {
console.error('[1-ERROR]', e);
if (e instanceof HttpError) {
console.log(`[${e.statusCode} - ${e.response.statusMessage}]`, e.response);
}
}
}

testClient();
// testMultiQueries();
testSearch();
1 change: 1 addition & 0 deletions openapi_spec/paths/indexes/batch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ post:
schema:
title: batchObject
type: object
additionalProperties: false
properties:
requests:
type: array
Expand Down
23 changes: 4 additions & 19 deletions openapi_spec/paths/indexes/multipleQueries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ post:
example: products
description: The Algolia index name
query:
type: string
description: The query to search for
$ref: ../../schemas/SearchParams.yml#/searchParams/properties/query
type:
type: string
enum: [default, facet]
Expand Down Expand Up @@ -57,22 +56,8 @@ post:
results:
type: array
items:
type: object
additionalProperties: false
properties:
hits:
type: array
items:
type: object
additionalProperties: false
properties:
objectID:
$ref: '../../responses/common.yml#/objectID'
nbHits:
type: integer
queryID:
$ref: '../../responses/common.yml#/queryID'
$ref: ../../schemas/SearchResponse.yml#/searchResponse
bodinsamuel marked this conversation as resolved.
Show resolved Hide resolved
'400':
$ref: '../../responses/BadRequest.yml'
$ref: ../../responses/BadRequest.yml
'404':
$ref: '../../responses/IndexNotFound.yml'
$ref: ../../responses/IndexNotFound.yml
30 changes: 10 additions & 20 deletions openapi_spec/paths/indexes/search.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,22 @@ post:
parameters:
- $ref: '../../parameters.yml#/IndexName'
requestBody:
$ref: '../../schemas/SearchParams.yml'
required: true
content:
application/json:
schema:
oneOf:
- $ref: ../../schemas/SearchParams.yml#/searchParams
- $ref: ../../schemas/SearchParams.yml#/searchParamsString
responses:
'200':
description: OK
content:
application/json:
schema:
title: singleQueryResponse
type: object
additionalProperties: false
properties:
hits:
type: array
items:
type: object
additionalProperties: false
properties:
objectID:
$ref: '../../responses/common.yml#/objectID'
nbHits:
type: integer
queryID:
type: string
pattern: '^[a-f0-9]{32}$'
example: 43b15df305339e827f0ac0bdc5ebcaa7
$ref: ../../schemas/SearchResponse.yml#/searchResponse
'400':
$ref: '../../responses/BadRequest.yml'
$ref: ../../responses/BadRequest.yml
'404':
$ref: '../../responses/IndexNotFound.yml'
$ref: ../../responses/IndexNotFound.yml
11 changes: 11 additions & 0 deletions openapi_spec/responses/common.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
taskID:
type: integer
description: taskID of the indexing task to wait for.

objectID:
type: string
description: Unique identifier of the object

objectIDs:
type: array
items:
type: string
description: List of objectID

queryID:
type: string
pattern: '^[a-f0-9]{32}$'
example: 43b15df305339e827f0ac0bdc5ebcaa7

abTestID:
type: integer
description: If a search encounters an index that is being A/B tested, abTestID reports the ongoing A/B test ID.

abTestVariantID:
type: integer
description: If a search encounters an index that is being A/B tested, abTestVariantID reports the variant ID of the index used.
85 changes: 85 additions & 0 deletions openapi_spec/schemas/IndexSettingsParams.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
allowCompressionOfIntegerArray:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we already have indexSettings params, 1/indexes/{indexName}/settings should be pretty easy

type: boolean
description: Enables compression of large integer arrays.
default: false

attributeForDistinct:
type: string
description: Name of the de-duplication attribute to be used with the distinct feature.
default: null

attributesToTransliterate:
type: array
items:
type: string
description: Specify on which attributes to apply transliteration.

camelCaseAttributes:
type: array
items:
type: string
description: List of attributes on which to do a decomposition of camel case words.
default: []

customNormalization:
type: object
additionalProperties: true
description: Override the default normalization handled by the engine.
default: {}

decompoundedAttributes:
type: object
additionalProperties: true
description: Specify on which attributes in your index Algolia should apply word segmentation, also known as decompounding.
default: {}

disablePrefixOnAttributes:
type: array
items:
type: string
description: List of attributes on which you want to disable prefix matching.
default: []

disableTypoToleranceOnWords:
type: array
items:
type: string
description: A list of words for which you want to turn off typo tolerance.
default: []

filterPromotes:
type: boolean
description: Whether promoted results should match the filters of the current search, except for geographic filters.
default: false

indexLanguages:
type: array
items:
type: string
description: Sets the languages at the index level for language-specific processing such as tokenization and normalization.
default: []

numericAttributesForFiltering:
type: array
items:
type: string
description: List of numeric attributes that can be used as numerical filters.
default: null

paginationLimitedTo:
type: integer
description: Set the maximum number of hits accessible via pagination.
default: 1000

userData:
type: object
additionalProperties: true
description: Lets you store custom data in your indices.
default: {}

replicas:
type: array
items:
type: string
description: Creates replicas, exact copies of an index.
default: []
102 changes: 102 additions & 0 deletions openapi_spec/schemas/Record.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
record:
type: object
description: A single record
additionalProperties: true
required:
- objectID
properties:
objectID:
$ref: '../responses/common.yml#/objectID'
_highlightResult:
$ref: '#/highlightResult'
_snippetResult:
$ref: '#/snippetResult'
_rankingInfo:
$ref: '#/rankingInfo'
_distinctSeqID:
type: number
Comment on lines +10 to +17
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note, we should investigate if we can influence this response object with request param.
e.g: _rankingInfo is only return when getRankingInfo is true

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, it was implemented as all optional for now but we should indeed make it clearer.

Should we consider it in this PR?

Copy link
Contributor Author

@bodinsamuel bodinsamuel Nov 17, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no but we can note it in next investigation ☺️


# Props
highlightResult:
type: object
additionalProperties: false
properties:
value:
type: string
description: 'Markup text with occurrences highlighted.'
example: '<em>George</em> <em>Clo</em>oney'
matchLevel:
type: string
description: 'Indicates how well the attribute matched the search query.'
enum: [none, partial, full]
matchedWords:
type: array
description: List of words from the query that matched the object.
items:
type: string
fullyHighlighted:
type: boolean
description: 'Whether the entire attribute value is highlighted.'

snippetResult:
type: object
additionalProperties: false
properties:
value:
type: string
description: 'Markup text with occurrences highlighted.'
example: '<em>George</em> <em>Clo</em>oney...'
matchLevel:
type: string
description: 'Indicates how well the attribute matched the search query.'
enum: [none, partial, full]

rankingInfo:
type: object
additionalProperties: false
properties:
filters:
type: integer
description: 'This field is reserved for advanced usage.'
firstMatchedWord:
type: integer
description: 'Position of the most important matched attribute in the attributes to index list.'
geoDistance:
type: integer
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).'
geoPrecision:
type: integer
description: 'Precision used when computing the geo distance, in meters.'
matchedGeoLocation:
type: object
additionalProperties:
type: object
additionalProperties: false
properties:
lat:
type: float
description: 'Latitude of the matched location.'
lng:
type: float
description: 'Longitude of the matched location.'
distance:
type: integer
description: 'Distance between the matched location and the search location (in meters).'
nbExactWords:
type: integer
description: 'Number of exactly matched words.'
nbTypos:
type: integer
description: 'Number of typos encountered when matching the record.'
promoted:
type: boolean
description: 'Present and set to true if a Rule promoted the hit.'
proximityDistance:
type: integer
description: 'When the query contains more than one word, the sum of the distances between matched words (in meters).'
userScore:
type: integer
description: 'Custom ranking for the object, expressed as a single integer value.'
word:
type: integer
description: 'Number of matched words, including prefixes and typos.'
23 changes: 23 additions & 0 deletions openapi_spec/schemas/RequestOptions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Not used yet

# timeouts:
# type: object
# additionalProperties: false
# properties:
# connect:
# type: integer
# description: 'Connection timeout in seconds.'
# example: 2
# read:
# type: integer
# description: 'Read timeout in seconds.'
# example: 5
# write:
# type: integer
# description: 'Write timeout in seconds.'
# example: 30

# X-Algolia-UserToken:
# type: string
# X-Forwarded-For:
# type: string
Loading