gsebleve

package module
v0.40.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 23, 2023 License: BSD-2-Clause Imports: 8 Imported by: 0

README

gse-bleve

Build Status Build Status CircleCI Status codecov Go Report Card GoDoc Release

Use

package main

import (
	"fmt"
	"os"

	"github.com/blevesearch/bleve/v2"
	gse "github.com/vcaesar/gse-bleve"
)

func main() {
	opt := gse.Option{
		Index: "test.blv",
		Dicts: "embed, ja",
		// Dicts: "embed, zh", 
		Stop: "",
		Opt: "search-hmm", 
		Trim: "trim",
		}

	index, err := gse.New(opt)
	if err != nil {
		fmt.Println("new mapping error is: ", err)
		return
	}

	text := `見解では、謙虚なヴォードヴィリアンのベテランは、運命の犠牲者と悪役の両方の変遷として代償を払っています`
	err = index.Index("1", text)
	index.Index("3", text+"浮き沈み")
	index.Index("4", `In view, a humble vaudevillian veteran cast vicariously as both victim and villain vicissitudes of fate.`)
	index.Index("2", `It's difficult to understand the sum of a person's life.`)
	if err != nil {
		fmt.Println("index error: ", err)
	}

	query := "運命の犠牲者"
	req := bleve.NewSearchRequest(bleve.NewQueryStringQuery(query))
	req.Highlight = bleve.NewHighlight()
	res, err := index.Search(req)
	fmt.Println(res, err)

	os.RemoveAll("test.blv")
}

Documentation

Index

Constants

View Source
const (
	TokenName    = "gse"
	SeparateName = "sep"
)

Variables

View Source
var Dicter = sat.DefaultDict()

Functions

func New

func New(opt Option) (bleve.Index, error)

New new bleve index

func NewAnalyzer

func NewAnalyzer(config map[string]interface{}, cache *registry.Cache) (analysis.Analyzer, error)

func NewDoc

func NewDoc() *mapping.DocumentMapping

NewDoc new bleve index document mapping

func NewMapping

func NewMapping(opt Option) (*mapping.IndexMappingImpl, error)

NewMapping new bleve index mapping

func NewMappingSep

func NewMappingSep(sep string, trim ...string) (*mapping.IndexMappingImpl, error)

NewMappingSep new separator mapping

func NewMem

func NewMem(opt Option) (bleve.Index, error)

NewMem new bleve index only memory

func NewSepMap

func NewSepMap() *mapping.FieldMapping

NewSepMap new text field mapping with sep

func NewTextMap

func NewTextMap() *mapping.FieldMapping

NewTextMap new text field mapping with gse

func Trim

func Trim(s []string, trim string, seg *gse.Segmenter) []string

Trim trim the unused token string

Types

type GseCut

type GseCut struct {
	// contains filtered or unexported fields
}

GseCut gse cut token structure

func NewGse

func NewGse(dicts, stop, opt, trim string, alpha bool) (*GseCut, error)

NewGseCut create a gse cut tokenizer

func (*GseCut) Cut

func (c *GseCut) Cut(text string, opt string) []string

Cut option the gse cut mode

func (*GseCut) Tokenize

func (c *GseCut) Tokenize(text []byte) analysis.TokenStream

Tokenize cut the text to bleve token stream

func (*GseCut) Trim

func (c *GseCut) Trim(s []string) []string

Trim trim the unused token string

type Option

type Option struct {
	Index                  string
	Dicts, Stop, Opt, Trim string
	Alpha                  bool
	Name, Sep              string
}

Option gse bleve option structure

type Separator

type Separator struct {
	// contains filtered or unexported fields
}

Separator type separator tokenizer struct

func NewSep

func NewSep(sep, trim string) (*Separator, error)

NewSep create a separator tokenizer

func (*Separator) Tokenize

func (s *Separator) Tokenize(text []byte) analysis.TokenStream

Tokenize cut the text to bleve token stream

func (*Separator) Trim

func (c *Separator) Trim(s []string) []string

Trim trim the unused token string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL