Giter VIP home page Giter VIP logo

msearch's Introduction

msearch

  • 基于本地文件(非内存),实现海量数据的存储、搜索功能 ,查询性能近百万QPS。 存储数据类型: key-values, 一个key对应多个value。

  • 接口方法 支持操作:Add, Del, Get等满足基本需求。删除value后,有新的value插入自动寻找空缺位,避免空间浪费。

    例如一个一条数据key1包含3个value: aaa bbb ccc, 删除bbb后变为,aaa _ ccc, 此时新插入一个value ddd,则变为 aaa ddd ccc. 如果插入长度超过空缺位长度,自动向后寻找合适的位置. 插入dddd 变为aaa _ ccc dddd,此时再插入fff,变为aaa fff ccc ddddd

  • 可以借助kafka等实现分布式。

  • 使用场景: 例如, 做根据昵称实时搜索好友、粉丝,粉丝用户可能数量100-100万粉丝不等。 输入一个用户的粉丝的昵称。然后进行模糊匹配搜索。

基于MMAP(Memory mapping)技术,将硬盘映射到内存,轻松映射超过100G硬盘空间至内存(不影响实际内存占用),相当于无限内存。

Support

  • 支持linux,mac os, 不支持windows(TODO)

Usage

package main

import (    
	"fmt"
	"github.com/vito-go/msearch"
)

func main() {
	fileName := "test.msearch" // 底层文件名
	ms, err := msearch.NewMsearch(fileName, 0)
	if err != nil {
		panic(err)
	}
	user := "[email protected]"
	userLi := "[email protected]"
	values := []string{"[email protected]", "[email protected]", "[email protected]", "[email protected]", "[email protected]", "[email protected]", "[email protected]", "[email protected]"}
	err = ms.Add(user, values...) // 添加一组values
	if err != nil {
		panic(err)
	}
	fmt.Println(ms.Get(user))               // 获取一个key对应的一组values   
	// 添加一个value
	if err=ms.Add(userLi, "[email protected]|nickname1");err!=nil{
		panic(err)
	} 
	ms.Del(user, values[:len(values)-2]...) // 删除多个value
	fmt.Println(ms.Get(user))               // 获取一组values
	fmt.Println(ms.Get(`userNil`))          // 获取一组values,如果没有values返回空数组。 
}

msearch's People

Stargazers

 avatar Vito avatar misasky avatar  avatar zhan avatar G.J. Cheng avatar

Watchers

Vito avatar

Forkers

tjlcast

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.