Skip to content

brianvoe/gofindit

Repository files navigation

Gofindit

Gofindit Go Report Card Test GoDoc license

Struct index and searching

ko-fi

Buy Me A Coffee

Features

  • Simplicity

Installation

go get github.com/brianvoe/gofindit

Simple Usage

import "github.com/brianvoe/gofindit"

type Test struct {
    Name string `find:"name"` // Tag with find
    Age  int                  // or field name Age is used
}

// Create a new index
index := gofindit.New()

// Create a new document
doc := Test{
    Name: "Test",
    Age:  10,
}

// Index the document
id := "1"
err := index.Index(id, doc)
if err != nil {
    fmt.Println(err)
    return
}

// Get the document
docGet, err := index.Get(id)
if err != nil {
    fmt.Println(err)
    return
}

fmt.Printf("%+v", docGet)

// Output: {Name:Test Age:10}

Search Usage

// Create a new index
index := gofindit.New()

// Add all your documents
for i := 0; i < 1000; i++ {
    // Add to index
    // ... Code here
}

// Create a search query
search := SearchQuery{
    Limit:  10, // default 10
	Skip:   0,  // default 0
	Sort:   "", // "", asc or desc
	SortBy: "", // field name

    // Search fields
    Fields: []SearchQueryField{
        {
            Field: "name",    // find tag
            Type:  "partial", // match, partial or range
            Value: "billy",   // Case insensitive
        },
    },
}

// Search for the document
results, err := index.Search(search)
if err != nil {
    fmt.Println(err)
    return
}

fmt.Printf("%+v", results)

// Output: [{Name:Billy Age:10}]

About

Struct index and searching

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages