The type of the documents being indexed.
The type of the documents being indexed.
const documents = [
{
id: 1,
title: 'Moby Dick',
text: 'Call me Ishmael. Some years ago...',
category: 'fiction'
},
{
id: 2,
title: 'Zen and the Art of Motorcycle Maintenance',
text: 'I can see by my watch...',
category: 'fiction'
},
{
id: 3,
title: 'Neuromancer',
text: 'The sky above the port was...',
category: 'fiction'
},
{
id: 4,
title: 'Zen and the Art of Archery',
text: 'At first sight it must seem...',
category: 'non-fiction'
},
// ...and more
]
// Create a search engine that indexes the 'title' and 'text' fields for
// full-text search. Search results will include 'title' and 'category' (plus the
// id field, that is always stored and returned)
const searchIndex = createIndex({
fields: ['title', 'text'],
storeFields: ['title', 'category']
})
// Add documents to the index
addAll(searchIndex, documents)
// Search for documents:
const results = search(searchIndex, 'zen art motorcycle')
// => [
// { id: 2, title: 'Zen and the Art of Motorcycle Maintenance', category: 'fiction', score: 2.77258 },
// { id: 4, title: 'Zen and the Art of Archery', category: 'non-fiction', score: 1.38629 }
// ]
The number of documents discarded since the most recent vacuuming
A number between 0 and 1 giving an indication about the proportion of documents that are discarded, and can therefore be cleaned up by vacuuming. A value close to 0 means that the index is relatively clean, while a higher value means that the index is relatively dirty, and vacuuming could release memory.
Total number of documents available to search
Is true
if a vacuuming operation is ongoing, false
otherwise
Number of terms in the index
Allows serialization of the index to JSON, to possibly store it and later
deserialize it with loadJSONIndex
.
Normally one does not directly call this method, but rather call the
standard JavaScript JSON.stringify()
passing the SearchIndex
instance,
and JavaScript will internally call this method. Upon deserialization, one
must pass to loadJSONIndex
the same options used to create the original
instance that was serialized.
// Serialize the index:
let searchIndex = createIndex({ fields: ['title', 'text'] })
addAll(searchIndex, documents)
const json = JSON.stringify(index)
// Later, to deserialize it:
searchIndex = loadJSONIndex(json, { fields: ['title', 'text'] })
A plain-object serializable representation of the search index.
The id type of the documents being indexed.