-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change memory search to match by parts and case insensitive
The dev and production deployment uses AzureSearch, where search for pattern "npmjs/red" will return results including npm/npmjs/-/redis/0.1.0. In addition, the search is case insensitive. In comparison, memory search (typically used during local development) searches strictly for coordinates string containing "npmjs/red". Change to match by parts and case insensitive. This is to make memory search more consistent with AzureSearch.
- Loading branch information
1 parent
67f840e
commit 4c1cd38
Showing
2 changed files
with
44 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// (c) Copyright 2022, SAP SE and ClearlyDefined contributors. Licensed under the MIT license. | ||
// SPDX-License-Identifier: MIT | ||
|
||
const { expect } = require('chai') | ||
const EntityCoordinates = require('../../../lib/entityCoordinates') | ||
const MemorySearch = require('../../../providers/search/memory') | ||
|
||
describe('memory search tests', () => { | ||
const searches = { | ||
'npmjs/red': 'npm/npmjs/-/redis/0.1.0', | ||
'github/bit': 'git/github/bitflags/bitflags/518aaf91494e94f41651a40f1b38d6ab522b0235', | ||
'mavencentral/org.apache': 'maven/mavencentral/org.apache.httpcomponents/httpcore/4.1', | ||
'nuget/xunit': 'nuget/nuget/-/xunit.core/2.4.1', | ||
'pypi/back': 'pypi/pypi/-/backports.ssl_match_hostname/3.7.0.1', | ||
'rubygems/sma': 'gem/rubygems/-/small/0.4', | ||
'cratesio/bit': 'crate/cratesio/-/bitflags/1.0.4', | ||
'debian/0a': 'deb/debian/-/0ad/0.0.17-1_amd64', | ||
'packagist/sym': 'composer/packagist/symfony/polyfill-mbstring/1.11.0', | ||
'cocoapods/soft': 'pod/cocoapods/-/SoftButton/0.1.0' | ||
} | ||
|
||
let memorySearch | ||
before(() =>{ | ||
const definitions = Object.values(searches) | ||
.map(EntityCoordinates.fromString) | ||
.map(coordinates => ({ coordinates })) | ||
|
||
memorySearch = MemorySearch({}) | ||
memorySearch.store(definitions) | ||
}) | ||
|
||
it('should search successfully', async () => { | ||
Object.entries(searches).forEach(async ([key, value]) => { | ||
const result = await memorySearch.suggestCoordinates(key) | ||
expect(result[0]).to.be.equal(value) | ||
}) | ||
}) | ||
}) |