How to use the flexsearch.create function in flexsearch

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

github datenguide / datenguide / src / pages / api / search / measures / index.js View on Github external
import flexsearch from 'flexsearch'

import schema from '../../../../data/schema.json'
import mappings from '../../../../data/mappings.json'

// TODO move to server

const getLabel = identifier => {
  const [statisticId, measureId] = identifier.split(':')

  const statisticMapping = mappings[measureId].find(m => m.name === statisticId)
  return `${statisticMapping.name} ${statisticMapping.title_de}  - ${measureId} ${schema[measureId].name}`
}

const statisticsIndex = flexsearch.create()
Object.keys(schema).forEach(key => {
  mappings[key].forEach(mapping => {
    const identifier = `${mapping.name}:${key}`
    statisticsIndex.add(identifier, getLabel(identifier))
  })
})

export default (req, res) => {
  const { filter } = req.query

  const statistics = statisticsIndex.search({
    query: filter || '1'
  })

  const result = statistics.map(id => ({
    value: id,
github datenguide / datenguide / src / pages / api / search / regions / index.js View on Github external
import flexsearch from 'flexsearch'

import regions from '../../../../data/ags.json'

// TODO move to server

const getLabel = identifier => `${identifier} - ${regions[identifier]}`

const regionsIndex = flexsearch.create()
Object.keys(regions)
  .filter(key => key.length <= 5) // NUTS 1 - 3, no LAU
  .forEach(key => {
    regionsIndex.add(key, getLabel(key))
  })

export default (req, res) => {
  const { filter } = req.query

  const regionsResult = regionsIndex.search({
    query: filter || '1'
  })

  const result = regionsResult.map(id => ({
    value: id,
    name: regions[id],
github AugurProject / augur / packages / augur-sdk / src / state / db / SyncableFlexSearch.ts View on Github external
constructor() {
    this.flexSearchIndex = flexSearch.create(
      {
        async: true,
        cache: true,
        worker: false, // TODO: Check impact on performance before enabling worker option in FlexSearch
        doc:
        {
          id: "market",
          start: "start",
          end: "end",
          field: [
            "market",
            "universe",
            "marketCreator",
            "category1",
            "category2",
            "category3",
github nextapps-de / flexsearch-server / handler.js View on Github external
const { config, init, read_from_file, write_schedule } = require("./helper");

const flexsearch = require("flexsearch").create(config ? config.preset || {

    async: true,
    cache: config.cache,
    threshold: config.threshold,
    depth: config.depth,
    limit: config.limit,
    encode: config.encode,
    tokenize: config.tokenize,
    filter: config.filter,
    stemmer: config.stemmer

} : null);

const index_map = {};
const connection = {};
const state = {};
github angeloashmore / react-use-flexsearch / src / index.js View on Github external
useEffect(() => {
    if (providedIndex instanceof FlexSearch) {
      setIndex(providedIndex)

      return
    }

    const importedIndex = FlexSearch.create()
    importedIndex.import(providedIndex)

    setIndex(importedIndex)
  }, [providedIndex])
github fluent-org / fluent-ui / docs / src / docs / components / Icon / template.tsx View on Github external
blackIcon: {
      color: theme.colors!.white!.default,
      backgroundColor: theme.colors!.black!.default
    }
  })
)

const tagList = Object.keys(tags).reduce(
  (acc, cur): {} => ({
    ...acc,
    ...tags[cur]
  }),
  {}
)

const searchIndex = FlexSearch.create({
  async: true,
  tokenize: 'full'
})

interface IconType {
  key: string
  tag: string
  Icon: any
}
const allIconsMap: { [name: string]: IconType } = {}
const allIcons = Object.keys(Icons)
  .sort()
  .map(
    (key): IconType => {
      let tag
      if (key.indexOf('Line') !== -1) {
github OriginProtocol / origin / dapps / shop / src / data / state.js View on Github external
const quantity = get(newState, `cart.items[${existing}].quantity`)
      newState = set(newState, `cart.items[${existing}].quantity`, quantity + 1)
    } else {
      const lastIdx = state.cart.items.length
      newState = set(newState, `cart.items[${lastIdx}]`, action.item)
    }
  } else if (action.type === 'removeFromCart') {
    const items = get(state, 'cart.items')
    items.splice(action.item, 1)
    newState = set(newState, 'cart.items', items)
  } else if (action.type === 'updateCartQuantity') {
    const { quantity } = action
    newState = set(newState, `cart.items[${action.item}].quantity`, quantity)
  } else if (action.type === 'setProducts') {
    newState = set(newState, `products`, action.products)
    const index = FlexSearch.create()
    action.products.forEach(product => index.add(product.id, product.title))
    newState = set(newState, `productIndex`, index)
    const productIds = action.products.map(p => p.id)
    newState = set(
      newState,
      'cart.items',
      state.cart.items.filter(i => productIds.indexOf(i.product) >= 0)
    )
  } else if (action.type === 'setCollections') {
    newState = set(newState, `collections`, action.collections)
  } else if (action.type === 'setShippingZones') {
    newState = set(newState, `shippingZones`, action.zones)
  } else if (action.type === 'setOrders') {
    newState = set(newState, `orders`, action.orders)
  } else if (action.type === 'setDiscounts') {
    newState = set(newState, `discounts`, action.discounts)
github mui-org / material-ui / docs / src / pages / components / material-icons / SearchIcons.js View on Github external
duration: theme.transitions.duration.shortest,
    }),
    fontSize: 40,
    padding: theme.spacing(2),
    margin: theme.spacing(0.5, 0),
    '&:hover': {
      backgroundColor: theme.palette.background.paper,
      boxShadow: theme.shadows[1],
    },
  },
  results: {
    marginBottom: theme.spacing(1),
  },
}));

const searchIndex = FlexSearch.create({
  async: true,
  tokenize: 'full',
});

const allIconsMap = {};
const allIcons = Object.keys(mui)
  .sort()
  .map(key => {
    let tag;
    if (key.indexOf('Outlined') !== -1) {
      tag = 'Outlined';
    } else if (key.indexOf('TwoTone') !== -1) {
      tag = 'Two tone';
    } else if (key.indexOf('Rounded') !== -1) {
      tag = 'Rounded';
    } else if (key.indexOf('Sharp') !== -1) {

flexsearch

Next-Generation full text search library with zero dependencies.

Apache-2.0
Latest version published 1 year ago

Package Health Score

64 / 100
Full package analysis

Similar packages