UNPKG

@am92/securities-utility

Version:
62 lines (61 loc) 2.04 kB
import { getChunkIndex } from '../../Constants/SEARCH_WORKER'; /** * Handles indexing of searchable strings for scripts, organizing them by * search priority into chunked groups. This is useful for efficient search * and retrieval operations. * * @returns {TIndexHandler<TSearchStringIndex>} An object containing methods to add rows to the index * and retrieve the indexed data. */ export const searchStringIndexHandler = () => { const index = {}; const addRow = (segmentKey, itemIndex, itemData, derivativeItemIndex, derivativeItem) => { let exchangeSymbol; let searchString; let searchPriority; let map; let isAslAllowed; if (segmentKey.includes('EQUITY')) { const item = itemData; exchangeSymbol = item[4]; isAslAllowed = item[3]; searchString = item[13]; searchPriority = item[14]; map = [segmentKey, itemIndex]; } else if (segmentKey.includes('UNDERLYING')) { const item = itemData; exchangeSymbol = item[4]; isAslAllowed = item[3]; searchString = item[11]; searchPriority = item[12]; map = [segmentKey, itemIndex]; } else { const item = itemData; exchangeSymbol = item[0]; isAslAllowed = derivativeItem[3]; searchString = derivativeItem[12]; searchPriority = derivativeItem[13]; map = [segmentKey, itemIndex, 3, derivativeItemIndex]; } if (isAslAllowed === 'N') return; const searchObj = { exchangeSymbol, searchString, searchPriority, data: map }; const chunkIndex = getChunkIndex(searchPriority); if (!index[chunkIndex]) { index[chunkIndex] = []; } index[chunkIndex].push(searchObj); }; const getIndex = () => index; return { addRow, getIndex }; };