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
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
9 changes: 2 additions & 7 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 @@ -63,11 +62,7 @@ post:
hits:
type: array
items:
type: object
additionalProperties: false
properties:
objectID:
$ref: '../../responses/common.yml#/objectID'
$ref: ../../schemas/Record.yml#/record
nbHits:
type: integer
queryID:
Expand Down
99 changes: 90 additions & 9 deletions openapi_spec/paths/indexes/search.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ 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
Expand All @@ -17,20 +23,95 @@ post:
type: object
additionalProperties: false
properties:
abTestID:
bodinsamuel marked this conversation as resolved.
Show resolved Hide resolved
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.
aroundLatLng:
type: string
description: The computed geo location.
pattern: ^(-?\d+(\.\d+)?),\s*(-?\d+(\.\d+)?)$
shortcuts marked this conversation as resolved.
Show resolved Hide resolved
automaticRadius:
type: string
description: The automatically computed radius. For legacy reasons, this parameter is a string and not an integer.
exhaustiveFacetsCount:
type: boolean
description: Whether the facet count is exhaustive or approximate.
exhaustiveNbHits:
type: boolean
description: Indicate if the nbHits count was exhaustive or approximate
exhaustiveTypo:
type: boolean
description: Indicate if the typo-tolerence search was exhaustive or approximate (only included when typo-tolerance is enabled)
facets:
type: object
additionalProperties:
type: object
additionalProperties:
type: string
description: A mapping of each facet name to the corresponding facet counts.
example:
category:
food: 1
tech: 42
facets_stats:
type: object
description: Statistics for numerical facets.
queryID:
shortcuts marked this conversation as resolved.
Show resolved Hide resolved
$ref: ../../responses/common.yml#/queryID
hits:
type: array
items:
type: object
additionalProperties: false
properties:
objectID:
$ref: '../../responses/common.yml#/objectID'
$ref: ../../schemas/Record.yml#/record
hitsPerPage:
$ref: ../../schemas/SearchParams.yml#/searchParams/properties/hitsPerPage
index:
type: string
example: indexName
indexUsed:
type: string
description: Index name used for the query. In the case of an A/B test, the targeted index isn’t always the index used by the query.
example: indexNameAlt
message:
type: string
description: Used to return warnings about the query.
nbHits:
type: integer
queryID:
description: Number of hits that the search query matched
example: 20
nbPages:
type: integer
description: Number of pages available for the current query
example: 1
nbSortedHits:
type: integer
description: The number of hits selected and sorted by the relevant sort algorithm
example: 20
page:
$ref: ../../schemas/SearchParams.yml#/searchParams/properties/page
params:
type: string
description: A url-encoded string of all search parameters.
example: query=a&hitsPerPage=20
parsedQuery:
type: string
description: The query string that will be searched, after normalization.
processingTimeMS:
type: number
description: Time the server took to process the request, in milliseconds.
example: 20
query:
$ref: ../../schemas/SearchParams.yml#/searchParams/properties/query
queryAfterRemoval:
type: string
description: A markup text indicating which parts of the original query have been removed in order to retrieve a non-empty result set.
serverUsed:
type: string
pattern: '^[a-f0-9]{32}$'
example: 43b15df305339e827f0ac0bdc5ebcaa7
description: Actual host name of the server that processed the request.
userData:
$ref: ../../schemas/IndexSettingsParams.yml#/userData
'400':
$ref: '../../responses/BadRequest.yml'
'404':
Expand Down
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: []
Loading