How to use minisearch - 2 common examples

To help you get started, we’ve selected a few minisearch examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github samuelmeuli / mini-diary / src / renderer / utils / searchIndex.ts View on Github external
export async function createIndex(entries: Entries): Promise {
	// Define index structure
	index = new MiniSearch({
		fields: ["title", "text"],
		idField: "indexDate",
		// Function for splitting fields into individual terms
		tokenize: (str: string): string[] => str.split(SPACE_OR_PUNCTUATION),
	});

	// Index all existing diary entries
	const indexDocs = await Promise.all(
		Object.entries(entries).map(
			async ([indexDate, entry]): Promise => createIndexDoc(indexDate, entry),
		),
	);
	await index.addAllAsync(indexDocs);
}
github PACTCare / Dweb.page / src / js / search / search.js View on Github external
import MiniSearch from 'minisearch';
import FileType from '../services/FileType';
import removeMetaData from './removeMetaData';
import sortByScoreAndTime from './sortByScoreAndTime';
import MetadataDb from './MetadataDb';
import prepSearchText from './prepSearchText';
import loadMetadata from './loadMetadata';
import { DEFAULT_DESCRIPTION } from './searchConfig';
import Error from '../error';

window.miniSearch = new MiniSearch({
  idField: 'fileId',
  fields: ['fileName', 'fileType', 'description'],
  searchOptions: {
    boost: { fileName: 2 },
    fuzzy: 0.2,
  },
});

// TODO: improve file types preselection
function fileTypePreselection(val) {
  if (window.searchKind === 'images') {
    return `${val} jpg png gif svg bmp webp tiff`;
  } if (window.searchKind === 'videos') {
    return `${val} mp4 mov flv avi wmv webm`;
  } if (window.searchKind === 'music') {
    return `${val} mp3 wma wav ogg acc flac`;

minisearch

Tiny but powerful full-text search engine for browser and Node

MIT
Latest version published 4 months ago

Package Health Score

83 / 100
Full package analysis

Popular minisearch functions