Code Monkey home page Code Monkey logo

gofindit's Introduction

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}]

gofindit's People

Contributors

brianvoe avatar

Watchers

 avatar  avatar

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.