Merge pull request #31836 from SnowBlitzer/jordans/tokenizer
Changing tokenizer separator for search indexing
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/plugin-search-backend-node': minor
|
||||
---
|
||||
|
||||
Improving method that search tokenizer breaks apart entity names
|
||||
@@ -509,6 +509,7 @@ thumbsup
|
||||
todo
|
||||
todos
|
||||
togglable
|
||||
tokenizer
|
||||
tolerations
|
||||
Tolerations
|
||||
toolchain
|
||||
|
||||
@@ -520,7 +520,7 @@ describe('LunrSearchEngine', () => {
|
||||
fields: {
|
||||
title: `${highlightTags.pre}testTitle${highlightTags.post}`,
|
||||
text: `${highlightTags.pre}testText${highlightTags.post}`,
|
||||
location: `${highlightTags.pre}test/location${highlightTags.post}`,
|
||||
location: `${highlightTags.pre}test${highlightTags.post}/location`,
|
||||
},
|
||||
},
|
||||
rank: 1,
|
||||
|
||||
@@ -106,4 +106,31 @@ describe('LunrSearchEngineIndexer', () => {
|
||||
...[lunr.trimmer, lunr.stopWordFilter, lunr.stemmer],
|
||||
);
|
||||
});
|
||||
|
||||
it('should tokenize input on non-alphanumeric characters', () => {
|
||||
const input =
|
||||
"Tokenize_test string, entity-name. Doesn't break abc123def - also Unicode support also!三 stjärna عربي";
|
||||
const expectedTokens = [
|
||||
'tokenize',
|
||||
'test',
|
||||
'string',
|
||||
'entity',
|
||||
'name',
|
||||
'doesn',
|
||||
't',
|
||||
'break',
|
||||
'abc123def',
|
||||
'also',
|
||||
'unicode',
|
||||
'support',
|
||||
'also',
|
||||
'三',
|
||||
'stjärna',
|
||||
'عربي',
|
||||
];
|
||||
|
||||
const tokens = lunr.tokenizer(input).map(token => token.toString());
|
||||
|
||||
expect(tokens).toEqual(expectedTokens);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -29,8 +29,8 @@ export class LunrSearchEngineIndexer extends BatchSearchEngineIndexer {
|
||||
|
||||
constructor() {
|
||||
super({ batchSize: 1000 });
|
||||
|
||||
this.builder = new lunr.Builder();
|
||||
this.builder.tokenizer.separator = /[^\p{L}\p{N}]+/u;
|
||||
this.builder.pipeline.add(lunr.trimmer, lunr.stopWordFilter, lunr.stemmer);
|
||||
this.builder.searchPipeline.add(lunr.stemmer);
|
||||
this.builder.metadataWhitelist = ['position'];
|
||||
|
||||
Reference in New Issue
Block a user