Giter Club home page Giter Club logo

Comments (4)

aokaywe avatar aokaywe commented on June 1, 2024

Is there any other method can query accurately?

I hope that I can use a func like ‘regexp’ because it can search accurately.

For example, here is a sentence ‘I hope that I can fly in the future’, I save it as a predicate ‘sentence’,if I give dgraph ‘fut’,it can match {‘sentence’ : ‘I hope that I can fly in the future’} because ‘future’ contains a continuous ‘fut’.

from bleve.

metonymic-smokey avatar metonymic-smokey commented on June 1, 2024

@aokaywe thanks for reaching out!

From what I see, using the default index mapping results in your documents being indexed with the standard analyser which breaks down the referred document into tokens separated by space. Hence, the regexp matching 2 words returns no matches.
(To underscore my point, if your regex was ".*ext3*", that would return the expected document)

You should use a custom analyser with a "single" tokenizer since that doesn't split input text and indexes it as is.

I will work on a code sample which I can share to further illustrate my point.

P.S.
You could consider batching your index operations into a single Batch() operation.

from bleve.

metonymic-smokey avatar metonymic-smokey commented on June 1, 2024

@aokaywe
Turns out you can use the keyword analyser too, as an alternative to building a custom analyser with the "single" tokenizer.

Here's the code to do that:

package main

import (
	"fmt"

	"github.com/blevesearch/bleve/v2"
	"github.com/blevesearch/bleve/v2/mapping"
)

func buildIndexMapping() (mapping.IndexMapping, error) {
	indexMapping := bleve.NewIndexMapping()
	indexMapping.DefaultAnalyzer = "keyword"

	return indexMapping, nil
}

func main() {
	// open a new index
	mapping, err := buildIndexMapping()
	if err != nil {
		fmt.Println(err)
		return
	}
	index, err := bleve.New("example1.bleve", mapping)
	if err != nil {
		fmt.Println(err)
		return
	}

	dataList := []struct {
		Name string
	}{
		{Name: "find text1 in file"},
		{Name: "find text1 in file2"},
		{Name: "find text2 in document"},
		{Name: "find text3 in content"},
	}

	b := index.NewBatch()
	for i, data := range dataList {
		docID := fmt.Sprintf("doc%d", i)
		err = b.Index(docID, data)
		if err != nil {
			fmt.Printf("Error indexing document %s: %v\n", docID, err)
		}
	}
	err = index.Batch(b)
	if err != nil {
		fmt.Printf("Error indexing batch: %v \n", err)
		return
	}

	// search for some text
	query := bleve.NewRegexpQuery(".*ext3 in.*")

	search := bleve.NewSearchRequest(query)
	searchResults, err := index.Search(search)
	if err != nil {
		fmt.Println(err)
		return
	}

	fmt.Println(searchResults)

}

Pls let me know if you require any further info. Feel free to close the issue once your query is resolved.

thanks!

from bleve.

aokaywe avatar aokaywe commented on June 1, 2024

@metonymic-smokey Thank you, this works.

from bleve.

Related Issues (20)

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.