Comments (4)
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.
@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.
@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.
@metonymic-smokey Thank you, this works.
from bleve.
Related Issues (20)
- website https://www.blevesearch.com is messy due to invalid(?) ssl cert HOT 5
- bug:Unstable, keywords that can be searched for in the first few meters and seconds, but cannot be indexed
- Very poor search performance
- github.com/blevesearch/bleve/v2/http/search.go bug? HOT 1
- Current `bleve` release broken by more recent change? HOT 4
- search_geoshape.go:107:32: not enough arguments in call to geojson.FilterGeoShapesOnRelation HOT 5
- Panic in ParseFromKeyValue HOT 1
- can not search bool fields HOT 1
- ANSI Windows Console Highlighting
- runtime error: invalid memory address or nil pointer dereference HOT 2
- html search error HOT 1
- How to lower hit's score/position if specific field is empty? HOT 2
- Adding synonyms to search queries HOT 1
- Configuration for only in-memory storage HOT 2
- [Bug] Spanish analyzer not normalizing all accented words. HOT 3
- How can I use the Vector Search feature? HOT 1
- Handling a field whose value may be a different language? HOT 1
- Index out of range since v2 installed HOT 2
- What is the function of segmentMerge.oldNewDocNums?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bleve.