Skip to content

Commit

Permalink
Merge branch 'main' into expose-meilisearch-package
Browse files Browse the repository at this point in the history
  • Loading branch information
brunoocasali authored Feb 27, 2024
2 parents ac6eb90 + 8bf9016 commit ad3c63b
Show file tree
Hide file tree
Showing 27 changed files with 105 additions and 31 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/meilisearch-prototype-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ jobs:
strategy:
fail-fast: false
matrix:
node: ['14', '16', '18']
node: ['18', '20']
name: integration-tests (Node.js ${{ matrix.node }})
steps:
- uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pre-release-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ jobs:
strategy:
fail-fast: false
matrix:
node: ['14', '16', '18']
node: ['18', '20']
name: integration-tests (Node.js ${{ matrix.node }})
steps:
- uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ jobs:
strategy:
fail-fast: false
matrix:
node: ['14', '16', '18']
node: ['18', '20']
name: integration-tests (Node.js ${{ matrix.node }})
steps:
- uses: actions/checkout@v4
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
<p align="center">
<a href="https://github.com/meilisearch/meilisearch-js-plugins/actions"><img src="https://github.com/meilisearch/meilisearch-js-plugins/workflows/Tests/badge.svg?branch=main" alt="Tests"></a>
<a href="https://github.com/meilisearch/meilisearch-js-plugins/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-MIT-informational" alt="License"></a>
<a href="https://github.com/meilisearch/meilisearch/discussions" alt="Discussions"><img src="https://img.shields.io/badge/github-discussions-red" /></a>
<a href="https://ms-bors.herokuapp.com/repositories/48"><img src="https://bors.tech/images/badge_small.svg" alt="Bors enabled"></a>
</p>

Expand Down
3 changes: 1 addition & 2 deletions bors.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
status = [
'style-check',
'types-check',
'integration-tests (Node.js 14)',
'integration-tests (Node.js 16)',
'integration-tests (Node.js 18)',
'integration-tests (Node.js 20)',
'autocomplete-client end-to-end-tests',
'instant-meilisearch end-to-end-tests',
]
Expand Down
6 changes: 6 additions & 0 deletions packages/autocomplete-client/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @meilisearch/autocomplete-client

## 0.3.0

### Minor Changes

- 00f30c9: Remove node 14 and 16 from workflow

## 0.2.2

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/autocomplete-client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ This package guarantees compatibility with [version v1.x of Meilisearch](https:/

**Node / NPM versions**:

- NodeJS >= 14 <= 18
- NodeJS >= 18

## ⚙️ Development Workflow and Contributing

Expand Down
2 changes: 1 addition & 1 deletion packages/autocomplete-client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@meilisearch/autocomplete-client",
"version": "0.2.2",
"version": "0.3.0",
"private": false,
"description": "The search client to use Meilisearch with autocomplete.js.",
"homepage": "https://github.com/meilisearch/meilisearch-js-plugins/tree/main/packages/autocomplete-client",
Expand Down
2 changes: 1 addition & 1 deletion packages/autocomplete-client/src/package-version.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const PACKAGE_VERSION = '0.2.2'
export const PACKAGE_VERSION = '0.3.0'
13 changes: 13 additions & 0 deletions packages/instant-meilisearch/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# @meilisearch/instant-meilisearch

## 0.16.0

### Minor Changes

- b1343c1: Enable experimental hybrid search

## 0.15.0

### Minor Changes

- 72726ac: Update meilisearch-js version
- 36b5a62: Fixed RegExp in filter-adapter.ts and sort-context.ts to work in Safari

## 0.14.0

### Minor Changes
Expand Down
3 changes: 2 additions & 1 deletion packages/instant-meilisearch/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,8 @@ The following options can be overridden:
[`showMatchesPosition`](https://www.meilisearch.com/docs/reference/api/search#show-matches-position),
[`matchingStrategy`](https://www.meilisearch.com/docs/reference/api/search#matching-strategy),
[`showRankingScore`](https://www.meilisearch.com/docs/reference/api/search#ranking-score),
[`attributesToSearchOn`](https://www.meilisearch.com/docs/reference/api/search#customize-attributes-to-search-on-at-search-time).
[`attributesToSearchOn`](https://www.meilisearch.com/docs/reference/api/search#customize-attributes-to-search-on-at-search-time),
[`hybrid`](https://www.meilisearch.com/docs/learn/experimental/vector_search)

```js
instantMeiliSearch(
Expand Down
12 changes: 12 additions & 0 deletions packages/instant-meilisearch/__tests__/sort.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,18 @@ describe('Sort browser test', () => {
])
})

test('split multiple sorting rules in different order', () => {
const sortRules = splitSortString(
'title:asc,_geoPoint(37.8153, -122.4784):asc,description:desc'
)

expect(sortRules).toEqual([
'title:asc',
'_geoPoint(37.8153, -122.4784):asc',
'description:desc',
])
})

test('split one sorting rule', () => {
const sortRules = splitSortString('_geoPoint(37.8153, -122.4784):asc')

Expand Down
4 changes: 2 additions & 2 deletions packages/instant-meilisearch/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@meilisearch/instant-meilisearch",
"version": "0.14.0",
"version": "0.16.0",
"private": false,
"description": "The search client to use Meilisearch with InstantSearch.",
"homepage": "https://github.com/meilisearch/meilisearch-js-plugins/tree/main/packages/instant-meilisearch",
Expand Down Expand Up @@ -50,7 +50,7 @@
"templates"
],
"dependencies": {
"meilisearch": "^0.36.0"
"meilisearch": "^0.37.0"
},
"devDependencies": {
"@babel/cli": "^7.22.9",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,22 @@ describe('Parameters adapter', () => {
meiliSearchParams.matchingStrategy
)
})

test('hybrid search configuration can be set via search parameters', () => {
const hybridSearchConfig = {
semanticRatio: 0,
embedder: 'default',
}

const searchParams = adaptSearchParams({
...DEFAULT_CONTEXT,
meiliSearchParams: {
hybrid: hybridSearchConfig,
},
})

expect(searchParams.hybrid).toBe(hybridSearchConfig)
})
})

describe('Geo filter adapter', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ function transformFacetFilter(filter: string): string {
return `"${attribute}"="${value}"`
}

// Matches first occurrence of an operator
const numericSplitRegExp = /(?<!(?:[<!>]?=|<|>|:).*)([<!>]?=|<|>|:)/

/**
* Transform InstantSearch [numeric filter](https://www.algolia.com/doc/api-reference/api-parameters/numericFilters/)
* to Meilisearch compatible filter format.
Expand All @@ -47,9 +44,25 @@ const numericSplitRegExp = /(?<!(?:[<!>]?=|<|>|:).*)([<!>]?=|<|>|:)/
* @returns {string}
*/
function transformNumericFilter(filter: string): string {
// TODO: Warn users to not enable facet values escape for negative numbers.
// https://github.com/algolia/instantsearch/blob/da701529ed325bb7a1d782e80cb994711e20d94a/packages/instantsearch.js/src/lib/utils/escapeFacetValue.ts#L13-L21
const [attribute, operator, value] = filter.split(numericSplitRegExp)
const splitNumericFilter = (): [string, string, string] => {
const attributeMatch = filter.match(/^([^<!>:=]*)([<!>:=]+)(.*)$/)

if (attributeMatch) {
const [attribute, dirtyOperator, valueEnd] = attributeMatch.slice(1)
const operatorMatch = dirtyOperator.match(/^([<!>]?=|<|>|:){1}(.*)/) || [
'',
'',
]
const [operator, valueStart] = operatorMatch.slice(1)
const cleanedValue = valueStart + valueEnd

return [attribute, operator, cleanedValue]
}

return [filter, '', '']
}

const [attribute, operator, value] = splitNumericFilter()
const escapedAttribute = getValueWithEscapedBackslashesAndQuotes(attribute)
return `"${escapedAttribute.trim()}"${
operator === ':' ? ' ' : operator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,12 @@ export function MeiliParamsCreator(searchContext: SearchContext) {
meiliSearchParams.attributesToSearchOn = value
}
},
addHybridSearch() {
const value = overrideParams?.hybrid
if (value !== undefined) {
meiliSearchParams.hybrid = value
}
},
}
}

Expand Down Expand Up @@ -263,6 +269,7 @@ export function adaptSearchParams(
meilisearchParams.addMatchingStrategy()
meilisearchParams.addShowRankingScore()
meilisearchParams.addAttributesToSearchOn()
meilisearchParams.addHybridSearch()

return meilisearchParams.getParams()
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export function instantMeiliSearch(
meiliSearchInstance: meilisearchClient,
setMeiliSearchParams: (params): void => {
const { meiliSearchParams } = instantMeiliSearchOptions

instantMeiliSearchOptions.meiliSearchParams =
meiliSearchParams === undefined
? params
Expand Down
10 changes: 8 additions & 2 deletions packages/instant-meilisearch/src/contexts/sort-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@
*/
export function splitSortString(sortStr: string): string[] {
if (!sortStr) return []
const sortRules = sortStr.split(/,(?=\w+:(?:asc|desc))/)
const regex = /[^:]+:(?:asc|desc)/g
const sortRules: string[] = []

return sortRules
let match
while ((match = regex.exec(sortStr)) !== null) {
sortRules.push(match[0])
}

return sortRules.map((str) => str.replace(/^,+|,+$/, ''))
}
2 changes: 1 addition & 1 deletion packages/instant-meilisearch/src/package-version.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const PACKAGE_VERSION = '0.14.0'
export const PACKAGE_VERSION = '0.16.0'
1 change: 1 addition & 0 deletions packages/instant-meilisearch/src/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export type OverridableMeiliSearchSearchParameters = Pick<
| 'matchingStrategy'
| 'showRankingScore'
| 'attributesToSearchOn'
| 'hybrid'
>

type BaseInstantMeiliSearchOptions = {
Expand Down
2 changes: 1 addition & 1 deletion playgrounds/angular/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"@angular/platform-browser": "~15.1.0",
"@angular/platform-browser-dynamic": "~15.1.0",
"@angular/router": "~15.1.0",
"@meilisearch/instant-meilisearch": "0.14.0",
"@meilisearch/instant-meilisearch": "0.16.0",
"algoliasearch": "^4.17.2",
"angular-instantsearch": "^4.4.1",
"instantsearch.js": "^4.56.2",
Expand Down
2 changes: 1 addition & 1 deletion playgrounds/geo-javascript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
},
"devDependencies": {
"@babel/core": "^7.20.12",
"@meilisearch/instant-meilisearch": "0.14.0",
"@meilisearch/instant-meilisearch": "0.16.0",
"eslint-config-meilisearch": "*"
},
"browserslist": [
Expand Down
2 changes: 1 addition & 1 deletion playgrounds/javascript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@
],
"license": "MIT",
"dependencies": {
"@meilisearch/instant-meilisearch": "0.14.0"
"@meilisearch/instant-meilisearch": "0.16.0"
}
}
2 changes: 1 addition & 1 deletion playgrounds/local-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"author": "",
"license": "ISC",
"dependencies": {
"@meilisearch/instant-meilisearch": "0.14.0",
"@meilisearch/instant-meilisearch": "0.16.0",
"instantsearch.css": "^8.0.0",
"react": "^17.0.1",
"react-dom": "^17.0.1",
Expand Down
2 changes: 1 addition & 1 deletion playgrounds/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-instantsearch": "^7.1.0",
"@meilisearch/instant-meilisearch": "0.14.0"
"@meilisearch/instant-meilisearch": "0.16.0"
},
"devDependencies": {
"@babel/core": "^7.13.1",
Expand Down
2 changes: 1 addition & 1 deletion playgrounds/vue3-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"test:types": "yarn tsc"
},
"dependencies": {
"@meilisearch/instant-meilisearch": "0.14.0",
"@meilisearch/instant-meilisearch": "0.16.0",
"vue": "^3.2.45",
"vue-instantsearch": "^4.10.8"
},
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10223,10 +10223,10 @@ media-typer@0.3.0:
resolved "https://registry.yarnpkg.com/media-typer/-/media-typer-0.3.0.tgz#8710d7af0aa626f8fffa1ce00168545263255748"
integrity sha512-dq+qelQ9akHpcOl/gUVRTxVIOkAJ1wR3QAvb4RsVjS8oVoFjDGTc679wJYmUmknUF5HwMLOgb5O+a3KxfWapPQ==

meilisearch@^0.36.0:
version "0.36.0"
resolved "https://registry.yarnpkg.com/meilisearch/-/meilisearch-0.36.0.tgz#b2d1f6b342aabc89557832638a6ce2a6a7c6bf64"
integrity sha512-swcvEYrct0/zsGj3jlbPm1OYxbH14IURnlysKlXywNicIQ5EMkSYLYCLCwOuBKAaGcdISWdgdylH9TXVLegmOQ==
meilisearch@^0.37.0:
version "0.37.0"
resolved "https://registry.yarnpkg.com/meilisearch/-/meilisearch-0.37.0.tgz#b4cafd434d1a854a77b92d17d6977ed6c47fd485"
integrity sha512-LdbK6JmRghCawrmWKJSEQF0OiE82md+YqJGE/U2JcCD8ROwlhTx0KM6NX4rQt0u0VpV0QZVG9umYiu3CSSIJAQ==
dependencies:
cross-fetch "^3.1.6"

Expand Down

0 comments on commit ad3c63b

Please sign in to comment.