Skip to content

[BUG] global wildcard symbol is not safe. #307

@jcyuan

Description

@jcyuan
######## query:  Symbol(*)
[ERROR] Failed to perform search: TypeError: Cannot read properties of undefined (reading 'map')
    at MiniSearch.executeQuery (minisearch\MiniSearch.ts:1701:37)
    at MiniSearch.search (minisearch\MiniSearch.ts:1364:29)
    at SearchEngine.search (libs\search\index.ts:518:34)
    at POST$1 (webpack-internal:\(rsc)\app\api\search\app\api\search\route.ts:63:32)
  1699 |     if (typeof query !== 'string') {
  1700 |       const options = { ...searchOptions, ...query, queries: undefined }
> 1701 |       const results = query.queries.map((subquery) => this.executeQuery(subquery, options))
       |                                     ^
  1702 |       return this.combineResults(results, options.combineWith)
  1703 |     }
  1704 |

this is the error stack.

my use case is search with my own filter like search(MiniSearch.wildcard, { filter: (r) => { .... } }
then it throws error in
https://github.com/lucaong/minisearch/blob/3d239d1c3ae7aef1bf5d8945dd7b5f0709f646f5/src/MiniSearch.ts#L1694C3-L1697C6
which means it detects that the parameter is not MiniSearch.wildcard.

my dev stack is Next.js so there will be node process and edge process together, and in both proccesses i will initialize MiniSearch with Redis cache, i guess this is the reason caused different MiniSearch.wildcard instances.

so use Symbol is not a safe way to determine / or indicate whether a search is a global search.

my current solution is to modify the source code until new offical release.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions