-
Notifications
You must be signed in to change notification settings - Fork 451
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(default-layout): sortable search results, search phrases, experi…
…mental config (#3652) This commit updates search with the following features: - Order search results by relevance, created and last updated date. - Search for documents containing an exact phrase by wrapping text inside double quotes. - Use the experimental config `__experimental_omnisearch_visibility` to hide documents from global search. - Display relevance scores in search results via a debug flag (`#_debug_search_score`) It comes with the following fixes: - Fixes an issue where the scroll position of search results wasn’t being correctly retained in some instances. - Fixes an issue where search would cause the studio to crash if Local Storage is unavailable.
- Loading branch information
Showing
49 changed files
with
1,613 additions
and
634 deletions.
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
18 changes: 18 additions & 0 deletions
18
dev/test-studio/schema/debug/experimentalOmnisearchVisibilityTest.js
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,18 @@ | ||
/** | ||
* Documents of this type should never be visible in omnisearch results, | ||
* nor should they appear in the omnisearch document filter list. | ||
*/ | ||
export default { | ||
// eslint-disable-next-line camelcase | ||
__experimental_omnisearch_visibility: false, | ||
type: 'document', | ||
name: 'experimentalOmnisearchVisibilityTest', | ||
title: 'Experimental omnisearch visibility test', | ||
fields: [ | ||
{ | ||
type: 'string', | ||
name: 'title', | ||
title: 'Title', | ||
}, | ||
], | ||
} |
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
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
4 changes: 2 additions & 2 deletions
4
...@sanity/base/test/search-tokenize.test.js → ...y/base/src/search/common/tokenize.test.ts
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
49 changes: 49 additions & 0 deletions
49
packages/@sanity/base/src/search/weighted/applyWeights.test.ts
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,49 @@ | ||
import { | ||
calculatePhraseScore, | ||
calculateWordScore, | ||
partitionAndSanitizeSearchTerms, | ||
} from './applyWeights' | ||
|
||
describe('calculatePhraseScore', () => { | ||
it('should handle exact matches', () => { | ||
expect(calculatePhraseScore(['the fox'], 'the fox')).toEqual([1, '[Phrase] Exact match']) | ||
}) | ||
it('should handle partial matches', () => { | ||
expect(calculatePhraseScore(['the fox'], 'the fox of foo')).toEqual([ | ||
0.25, | ||
'[Phrase] Matched 7 of 14 characters', | ||
]) | ||
}) | ||
}) | ||
|
||
describe('calculateWordScore', () => { | ||
it('should handle exact matches', () => { | ||
expect(calculateWordScore(['foo'], 'foo')).toEqual([1, '[Word] Exact match']) | ||
expect(calculateWordScore(['foo', 'foo'], 'foo foo')).toEqual([1, '[Word] Exact match']) | ||
expect(calculateWordScore(['bar', 'foo'], 'foo bar')).toEqual([1, '[Word] Exact match']) | ||
expect(calculateWordScore(['foo', 'bar'], 'bar, foo')).toEqual([1, '[Word] Exact match']) | ||
expect(calculateWordScore(['foo', 'bar'], 'bar & foo')).toEqual([1, '[Word] Exact match']) | ||
}) | ||
it('should handle partial matches', () => { | ||
expect(calculateWordScore(['foo'], 'bar foo')).toEqual([ | ||
0.25, | ||
'[Word] Matched 1 of 2 terms: [foo]', | ||
]) | ||
expect(calculateWordScore(['foo', 'bar'], 'foo')).toEqual([ | ||
0.25, | ||
`[Word] Matched 1 of 2 terms: [foo]`, | ||
]) | ||
expect(calculateWordScore(['foo', 'bar', 'baz'], 'foo foo bar')).toEqual([ | ||
1 / 3, | ||
`[Word] Matched 2 of 3 terms: [foo, bar]`, | ||
]) | ||
}) | ||
}) | ||
|
||
describe('partitionAndSanitizeSearchTerms', () => { | ||
it('should separate words and phrases', () => { | ||
const {phrases, words} = partitionAndSanitizeSearchTerms(['foo', 'bar', `"foo bar"`]) | ||
expect(phrases).toEqual(['foo bar']) | ||
expect(words).toEqual(['foo', 'bar']) | ||
}) | ||
}) |
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
Oops, something went wrong.