Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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);
}
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`;