Comments (1)
Hello;
The problem you're encountering is because the query you're executing (the query string) doesn't explicitly mention a field, which means it defaults to searching in the general field (_all). As a result, the analyzer applied to the query string is the default analyzer, which you've defined as "en." To resolve this problem, please include the "Body" field in your query string. This will utilize the custom analyzer you've configured for the "Body" field in the default mapping.
Heres the updated code:
tmpIndexPath := createTmpIndexPath(t)
defer cleanupTmpIndexPath(t, tmpIndexPath)
idxMapping := NewIndexMapping()
idxMapping.DefaultAnalyzer = "en"
if err := idxMapping.AddCustomAnalyzer("custom-html", map[string]interface{}{
"type": custom.Name,
"tokenizer": "unicode",
"char_filters": []interface{}{html_char_filter.Name},
}); err != nil {
t.Fatal(err)
}
msg := []struct {
Id string
Body string
}{
{
Id: "1",
Body: "You trusted bbs server all proxies",
},
{
Id: "2",
Body: "this is NOT bbs server safe",
},
}
fm := mapping.NewTextFieldMapping()
fm.Analyzer = "custom-html"
idxMapping.DefaultMapping.AddFieldMappingsAt("Body", fm)
idx, err := New(tmpIndexPath, idxMapping)
if err != nil {
t.Fatal(err)
}
defer func() {
err = idx.Close()
if err != nil {
t.Fatal(err)
}
}()
for _, v := range msg {
idx.Index(v.Id, v)
}
keywords := []string{"Body:bbs", "Body:server"}
for _, v := range keywords {
query := NewQueryStringQuery(v)
searchRequest := NewSearchRequest(query)
searchResult, err := idx.Search(searchRequest)
if err != nil {
panic(err)
}
if searchResult.Hits.Len() > 0 {
fmt.Println("Search "+v+" found ", searchResult.Hits.Len())
} else {
fmt.Println("Search " + v + " Not found!")
}
}
from bleve.
Related Issues (20)
- 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
- NewRegexpQuery cannot return the correct result HOT 4
- 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
- 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?
- Error error parsing created field: parsing time "1714686445000000000" as "2006-01-02T15:04:05Z07:00": cannot parse "686445000000000" as "-" HOT 7
- Vector example returns empty result list HOT 2
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.