lucaong / minisearch

Tiny and powerful JavaScript full-text search engine for browser and Node
https://lucaong.github.io/minisearch/
MIT License
4.64k stars 133 forks source link

Wildcard query that matches all documents #234

Closed lucaong closed 10 months ago

lucaong commented 10 months ago

This pull request introduces a special wildcard value, MiniSearch.wildcard, that matches all documents:

// Return search results for all documents
minisearch.search(MiniSearch.wildcard)

// Return search results for all documents in the 'fiction' category
minisearch.search(MiniSearch.wildcard, {
  filter: (result) => result.category === 'fiction'
})

This is useful for retrieving all results, but still apply search options such as filter and boostDocument. It can also be useful in query combinations, for example to query for all documents that DO NOT contain a specific term:

// Search for all documents that do NOT contain the term "maintenance"
const results = ms.search({
  combineWith: 'AND_NOT',
  queries: [
    MiniSearch.wildcard,
    'maintenance'
  ]
})