Document search query with resolved: false causing error
In "flexsearch":"0.8.204" in node esm version if I have index like this:
const searchIndex = new Document({
document: {
id: 'id',
index: 'text',
store: [
'text', 'tag', 'site'
],
tag: ['tag', 'site']
},
tokenize: 'reverse',
charset: 'latin:advanced',
optimize: true,
cache: false,
resolution: 9,
worker: false
});
and I perform search like this:
const sr = searchIndex.search('test',{
// enrich: true,
index: 'text',
field:'text',
tag: {
site:'docs'
},
limit: 35,
highlight: "<b>$1</b>",
// resolve: false
})
things are good and I get results like:
...
{
"id": "ab105.49",
"doc": {
"text": "<test_name>/anytime_<command>",
"tag": "block",
"site": "docs"
},
"highlight": "<b><test_na</b>me>/anytime_<command>"
},
{
"id": "cfc6c.50",
"doc": {
"text": "Test the cluster and health-checker setup locally:",
"tag": "block",
"site": "docs"
},
"highlight": "<b>Test</b> the cluster and health-checker setup locally:"
}
...
But if I make resolve: false on the document search query like this:
const sr = searchIndex.search('test',{
// enrich: true,
index: 'text',
field:'text',
tag: {
site:'docs'
},
limit: 35,
highlight: "<b>$1</b>",
resolve: false
})
I have an error
Cannot read properties of undefined (reading 'length') (via TypeError)
Original error stack trace: TypeError: Cannot read properties of undefined (reading 'length')
at fb (...node_modules/flexsearch/dist/flexsearch.bundle.module.min.js:57:209)
at Qa.search (.../node_modules/flexsearch/dist/flexsearch.bundle.module.min.js:61:295)
I guess instead I should do query and resolving like that:
const raw = new Resolver({
index: searchIndex,
field: 'text',
query: query,
});
const sr = raw.resolve({
limit: 10,
offset: 0,
enrich: true,
highlight: "<b>$1</b>"
});
but it wasn't straightforward that I should pass highlight to the latest resolver instead of the first one
@terpimost Hello, thanks for the report. There is a new version 0.8.205 which has better support for result highlighting when using resolver: https://github.com/nextapps-de/flexsearch/blob/master/doc/result-highlighting.md#using-result-highlighting-on-resolver
You should pick one resolver stage which also has a query and assign the highlight option to this stage. But you can pick just one query/stage for result highlighting. If you see any improvements please feel free to make some suggestions.
The charset notation has slightly changed to charset: 'LatinAdvanced'
Before I close this thread, let me put this full working example:
const data = [{
"id": "ab105.49",
"text": "<test_name>/anytime_<command>",
"tag": "block",
"site": "docs"
},{
"id": "cfc6c.50",
"text": "Test the cluster and health-checker setup locally:",
"tag": "block",
"site": "docs"
}];
const index = new Document({
document: {
id: 'id',
index: 'text',
store: [
'text', 'tag', 'site'
],
tag: ['tag', 'site']
},
tokenize: 'reverse',
encoder: Charset.LatinAdvanced
});
data.forEach(item => index.add(item));
const result = new Resolver({
index: index,
query: "test",
field: 'text',
tag: {
site: 'docs'
},
limit: 35,
highlight: "<b>$1</b>"
}).resolve();