Mindex - 简单的JS索引工具


BSD
跨平台
JavaScript

软件简介

Mindex是一个简单的JS索引工具,主要基于LokiJS。适用对象中的集合 ,
Mindex几乎能瞬间从大量数据中查找到想要的结果,并且支持快速排序。它的查询语法非常的直观,同样也支持模糊查询,另外,Mindex与同类软件相比,查询效率也是极高的。

主要特性:

  • 体积小 - 仅300行代码

  • 速度快 - 瞬间匹配到结果

  • 功能强大 - 支持简单查询也支持复杂查询

安装

性能测试相关数据

***********************
Test Mindex performance
***********************

Testing insertRecord(record)

Mindex 16.80 ops/sec, Native Array 45.51 ops/sec
Mindex is 63% slower


Testing get(key)

Mindex 3485998.20 ops/sec, Native Array 642.11 ops/sec
Mindex is 542799% faster


Testing getAll(), get all records

Mindex 374.92 ops/sec, Native Array 14.41 ops/sec
Mindex is 2502% faster


Testing removeRecord(key, value)

Mindex 1955971.50 ops/sec, Native Array 220.43 ops/sec
Mindex is 887260% faster

示例代码

var Mindex = require('mindex')

var index = Mindex(['age'])

index.insertRecord({
  id: 'John',
  age: 25
})
index.insertRecord({
  id: 'Darcy',
  age: 28
})
index.insertRecord({
  id: 'Jim',
  age: 29
})
index.insertRecord({
  id: 'Betty',
  age: 25
})

// Get IDs by key
console.log(index.get(25)) // [ 'Betty', 'John' ]

// Get all IDs sorted by key (age)
console.log(index.getAll()) // [ 'Betty', 'John', 'Darcy', 'Jim' ]

// Get all IDs within a given range
console.log(index.query({'>': [22], '<': [29]})) // [ 'Betty', 'John', 'Darcy' ]