Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion .github/workflows/pre-release-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ jobs:
- name: Get the latest Meilisearch RC
run: echo "MEILISEARCH_VERSION=$(curl https://raw.githubusercontent.com/meilisearch/integration-guides/main/scripts/get-latest-meilisearch-rc.sh | bash)" >> $GITHUB_ENV
- name: Meilisearch (${{ env.MEILISEARCH_VERSION }}) setup with Docker
run: docker run -d -p 7700:7700 getmeili/meilisearch:${{ env.MEILISEARCH_VERSION }} ./meilisearch --master-key=masterKey --no-analytics
run: docker run -d -p 7700:7700 getmeili/meilisearch:${{ env.MEILISEARCH_VERSION }} meilisearch --master-key=masterKey --no-analytics
- name: Install dependencies
run: yarn install
- name: Run tests
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ jobs:
./node_modules
key: ${{ hashFiles('yarn.lock') }}
- name: Docker setup
run: docker run -d -p 7700:7700 getmeili/meilisearch:latest ./meilisearch --no-analytics --master-key='masterKey'
run: docker run -d -p 7700:7700 getmeili/meilisearch:latest meilisearch --no-analytics --master-key='masterKey'
- name: Install dependencies
run: yarn install
- name: Run tests
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Each PR should pass the tests and the linter to be accepted.
```bash
# Tests with Jest
docker pull getmeili/meilisearch:latest # Fetch the latest version of Meilisearch image from Docker Hub
docker run -p 7700:7700 getmeili/meilisearch:latest ./meilisearch --master-key=masterKey --no-analytics
docker run -p 7700:7700 getmeili/meilisearch:latest meilisearch --master-key=masterKey --no-analytics
# Integration tests
yarn test
# End-to-end tests
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ This package only guarantees the compatibility with the [version v4 of InstantSe

**Supported Meilisearch versions**:

This package only guarantees the compatibility with the [version v0.26.0 of Meilisearch](https://github.com/meilisearch/meilisearch/releases/tag/v0.26.0).
This package only guarantees the compatibility with the [version v0.27.0 of Meilisearch](https://github.com/meilisearch/meilisearch/releases/tag/v0.27.0).

**Node / NPM versions**:

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"url": "https://github.com/meilisearch/instant-meilisearch.git"
},
"dependencies": {
"meilisearch": "0.25.0"
"meilisearch": "0.25.1"
},
"devDependencies": {
"@babel/cli": "^7.17.6",
Expand Down
22 changes: 22 additions & 0 deletions src/adapter/search-request-adapter/search-params-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ export function adaptSearchParams(
meiliSearchParams.attributesToCrop = attributesToCrop
}

// Attributes To Crop marker
const cropMarker = searchContext?.snippetEllipsisText
if (cropMarker != null) {
meiliSearchParams.cropMarker = cropMarker
}

// Attributes To Retrieve
const attributesToRetrieve = searchContext?.attributesToRetrieve
if (attributesToRetrieve) {
Expand All @@ -57,6 +63,22 @@ export function adaptSearchParams(
'*',
]

// Highlight pre tag
const highlightPreTag = searchContext?.highlightPreTag
if (highlightPreTag) {
meiliSearchParams.highlightPreTag = highlightPreTag
} else {
meiliSearchParams.highlightPreTag = '__ais-highlight__'
}

// Highlight post tag
const highlightPostTag = searchContext?.highlightPostTag
if (highlightPostTag) {
meiliSearchParams.highlightPostTag = highlightPostTag
} else {
meiliSearchParams.highlightPostTag = '__/ais-highlight__'
}

const placeholderSearch = searchContext.placeholderSearch
const query = searchContext.query

Expand Down
Original file line number Diff line number Diff line change
@@ -1,36 +1,75 @@
import { adaptHighlight } from './highlight-adapter'
import { adaptSnippet } from './snippet-adapter'
import { SearchContext } from '../../../types'
import { isPureObject } from '../../../utils'

/**
* Adapt Meilisearch formating to formating compliant with instantsearch.js.
* Stringify values following instantsearch practices.
*
* @param {any} value - value that needs to be stringified
*/
function stringifyValue(value: any) {
if (typeof value === 'string') {
// String
return value
} else if (value === undefined) {
// undefined
return JSON.stringify(null)
} else {
return JSON.stringify(value)
}
}

/**
* Recursif function wrap the deepest possible value
* the following way: { value: "xx" }.
*
* For example:
*
* {
* "rootField": { "value": "x" }
* "nestedField": { child: { value: "y" } }
* }
*
* recursivity continues until the value is not an array or an object.
*
* @param {any} value - value of a field
*
* @returns Record<string, any>
*/
function wrapValue(value: any): Record<string, any> {
if (Array.isArray(value)) {
// Array
return value.map((elem) => wrapValue(elem))
} else if (isPureObject(value)) {
// Object
return Object.keys(value).reduce<Record<string, any>>(
(nested: Record<string, any>, key: string) => {
nested[key] = wrapValue(value[key])

return nested
},
{}
)
} else {
return { value: stringifyValue(value) }
}
}

/**
* Adapt Meilisearch formatted fields to a format compliant to instantsearch.js.
*
* @param {Record<string} formattedHit
* @param {SearchContext} searchContext
* @returns {Record}
*/
export function adaptFormating(
hit: Record<string, any>,
searchContext: SearchContext
export function adaptFormattedFields(
hit: Record<string, any>
): Record<string, any> {
const attributesToSnippet = searchContext?.attributesToSnippet
const ellipsis = searchContext?.snippetEllipsisText
const preTag = searchContext?.highlightPreTag
const postTag = searchContext?.highlightPostTag

if (!hit._formatted) return {}
const _highlightResult = adaptHighlight(hit, preTag, postTag)

// what is ellipsis by default
const _snippetResult = adaptHighlight(
adaptSnippet(hit, attributesToSnippet, ellipsis),
preTag,
postTag
)
if (!hit) return {}
const _formattedResult = wrapValue(hit)

const highlightedHit = {
_highlightResult,
_snippetResult,
// We could not determine what the differences are between those two fields.
_highlightResult: _formattedResult,
_snippetResult: _formattedResult,
}

return highlightedHit
Expand Down

This file was deleted.

This file was deleted.

22 changes: 13 additions & 9 deletions src/adapter/search-response-adapter/hits-adapter.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { PaginationContext, SearchContext } from '../../types'
import { adaptPagination } from './pagination-adapter'
import { adaptFormating } from './format-adapter'
import { adaptFormattedFields } from './format-adapter'
import { adaptGeoResponse } from './geo-reponse-adapter'

/**
Expand All @@ -18,19 +18,23 @@ export function adaptHits(
const { hitsPerPage, page } = paginationContext
const paginatedHits = adaptPagination(hits, page, hitsPerPage)

let formattedHits = paginatedHits.map((hit: Record<string, any>) => {
let adaptedHits = paginatedHits.map((hit: Record<string, any>) => {
// Creates Hit object compliant with InstantSearch
if (Object.keys(hit).length > 0) {
const { _formatted: formattedHit, _matchesInfo, ...restOfHit } = hit
const { _formatted: formattedHit, _matchesInfo, ...documentFields } = hit

return {
...restOfHit,
...adaptFormating(hit, searchContext),
...(primaryKey && { objectID: hit[primaryKey] }),
const adaptedHit: Record<string, any> = Object.assign(
documentFields,
adaptFormattedFields(formattedHit)
)

if (primaryKey) {
adaptedHit.objectID = hit[primaryKey]
}
return adaptedHit
}
return hit
})
formattedHits = adaptGeoResponse(formattedHits)
return formattedHits
adaptedHits = adaptGeoResponse(adaptedHits)
return adaptedHits
}
Loading