Skip to content

radulucut/search

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Search

In-memory fuzzy search engine for Golang.

Go Reference Test

Installation

go get github.com/radulucut/search

Usage

package main

import (
	"fmt"

	"github.com/radulucut/search"
)

type Book struct {
	Id   int64
	Text string
}

var items = []Book{
	{Id: 1, Text: "Ultima noapte de dragoste, întâia noapte de război de Camil Petrescu"},
	{Id: 2, Text: "Pădurea spânzuraţilor de Liviu Rebreanu"},
	{Id: 3, Text: "Moromeții I de Marin Preda"},
	{Id: 4, Text: "Maitreyi de Mircea Eliade"},
	{Id: 5, Text: "Enigma Otiliei de George Călinescu"},
	{Id: 6, Text: "La țigănci de Mircea Eliade"},
	{Id: 7, Text: "Moara cu noroc de Ioan Slavici"},
	{Id: 8, Text: "Amintiri din copilărie de Ion Creangă"},
	{Id: 9, Text: "Patul lui Procust de Camil Petrescu"},
	{Id: 10, Text: "Elevul Dima dintr-a VII-A de Mihail Drumeș"},
	{Id: 11, Text: "Întoarcerea din rai de Mircea Eliade"},
	{Id: 12, Text: "La hanul lui Mânjoală de Ion Luca Caragiale"},
	{Id: 13, Text: "O scrisoare pierdută de Ion Luca Caragiale"},
	{Id: 14, Text: "Ion de Liviu Rebreanu"},
	{Id: 15, Text: "Baltagul de Mihail Sadoveanu"},
}

func main() {
	// Create a new search engine
	engine := search.NewEngine()
	engine.SetTolerance(2)

	// Add items to the search engine
	for _, item := range items {
		engine.SetItem(item.Id, item.Text)
	}

	// Search for a book
	results := engine.Search(search.SearchOptions{ Query: "Eliade", Limit: 5 })

	// Print the results
	// search.SearchResult{ Items: { 11, 6, 4 }, Total: 3, Pages: 1 }
	fmt.Println(results)
}

TODO

  • Add stemming support
  • Add tf-idf support

About

In-memory fuzzy search engine for Golang

Topics

Resources

License

Stars

Watchers

Forks

Languages