blevesearch / bleve

A modern text/numeric/geo-spatial/vector indexing library for go
Apache License 2.0
10.06k stars 683 forks source link

Index out of range since v2 installed #1993

Closed metalwolf closed 2 months ago

metalwolf commented 7 months ago

Using v1, was working perfectly, since I upgraded to v2, there is a random recurring error, of a panic error due to a out of range index. The error occurs totally random, i.e works perfectly many times, then suddenly breaks and panic, with the same query. This is a complex query with some ands and ors, ona string searched into a database of approx 25 thousands registers. Maybe some conflict with multi threaded processes?

Recovered in Server.Start runtime error: index out of range [6] with length 6 goroutine 229912 [running]: runtime/debug.Stack() /usr/local/go/src/runtime/debug/stack.go:24 +0x65 github.com/webability-go/xamboo/cms.(CMS).ServeHTTP.func1() /root/go/pkg/mod/github.com/webability-go/xamboo@v1.7.6/cms/cms.go:52 +0xda panic({0xdb9520, 0xc01f172408}) /usr/local/go/src/runtime/panic.go:884 +0x21f github.com/blevesearch/bleve/v2/index/scorch.(IndexSnapshotTermFieldReader).Next(0xc0007a5a00, 0x9957?) /root/go/pkg/mod/github.com/blevesearch/bleve/v2@v2.3.10/index/scorch/snapshot_index_tfr.go:94 +0x2cd github.com/blevesearch/bleve/v2/index/scorch.(IndexSnapshotTermFieldReader).Advance(0xc0007a5a00, {0xc05a532e60, 0x8, 0x8}, 0xc06f9b59a8) /root/go/pkg/mod/github.com/blevesearch/bleve/v2@v2.3.10/index/scorch/snapshot_index_tfr.go:177 +0x52e github.com/blevesearch/bleve/v2/search/searcher.(TermSearcher).Advance(0xc06f9b5980, 0xc041cf2f40?, {0xc05a532e60?, 0xc019afe980?, 0xc05bbe5000?}) /root/go/pkg/mod/github.com/blevesearch/bleve/v2@v2.3.10/search/searcher/search_term.go:109 +0x14e github.com/blevesearch/bleve/v2/search/searcher.(DisjunctionSliceSearcher).Advance(0xc0119eb220, 0xc02defa300, {0xc05a532e60, 0x8, 0x8}) /root/go/pkg/mod/github.com/blevesearch/bleve/v2@v2.3.10/search/searcher/search_disjunction_slice.go:243 +0x227 github.com/blevesearch/bleve/v2/search/searcher.(ConjunctionSearcher).advanceChild(0xc06f9b5a00, 0xc02defa300?, 0x0, {0xc05a532e60?, 0x8?, 0x8?}) /root/go/pkg/mod/github.com/blevesearch/bleve/v2@v2.3.10/search/searcher/search_conjunction.go:253 +0xe2 github.com/blevesearch/bleve/v2/search/searcher.(ConjunctionSearcher).Advance(0xc06f9b5a00, 0x0?, {0xc05a532e60, 0x8, 0x8}) /root/go/pkg/mod/github.com/blevesearch/bleve/v2@v2.3.10/search/searcher/search_conjunction.go:241 +0x117 github.com/blevesearch/bleve/v2/search/searcher.(BooleanSearcher).Advance(0xc05efad550, 0xc02defa300, {0xc05a532e60, 0x8, 0x8}) /root/go/pkg/mod/github.com/blevesearch/bleve/v2@v2.3.10/search/searcher/search_boolean.go:356 +0x95e github.com/blevesearch/bleve/v2/search/searcher.(ConjunctionSearcher).advanceChild(0xc06f9b5a80, 0xc02defa300?, 0x1, {0xc05a532e60?, 0x8?, 0x8?}) /root/go/pkg/mod/github.com/blevesearch/bleve/v2@v2.3.10/search/searcher/search_conjunction.go:253 +0xe2 github.com/blevesearch/bleve/v2/search/searcher.(ConjunctionSearcher).Next(0xc06f9b5a80, 0xc02defa300) /root/go/pkg/mod/github.com/blevesearch/bleve/v2@v2.3.10/search/searcher/search_conjunction.go:200 +0x1fa github.com/blevesearch/bleve/v2/search/collector.(TopNCollector).Collect(0xc031bb0b40, {0xeef7b0, 0xc053505c80}, {0x7fc0e77202d8, 0xc06f9b5a80}, {0x7fc0e7722480?, 0xc000034980?}) /root/go/pkg/mod/github.com/blevesearch/bleve/v2@v2.3.10/search/collector/topn.go:228 +0x55c github.com/blevesearch/bleve/v2.(indexImpl).SearchInContext(0xc000378070, {0xeef740, 0xc000130040}, 0xc054aff1e0) /root/go/pkg/mod/github.com/blevesearch/bleve/v2@v2.3.10/index_impl.go:580 +0x910 github.com/blevesearch/bleve/v2.(*indexImpl).Search(0xc03fee9088?, 0x2?) /root/go/pkg/mod/github.com/blevesearch/bleve/v2@v2.3.10/indeximpl.go:371 +0x2d kiwilimon/entities/blevesearch.fuzzyQ(, {, , _}, {0x0, 0x12, 0x1, {0xc000234c07, 0x4}, {0xc00f6abc27, ...}, ...}, ...) /home/sites/kiwi7/app7/kiwilimon/entities/blevesearch/blevesearch.go:614 +0xd4a

query is similar to this:

query := bleve.NewConjunctionQuery()

if params.Q != "" {
    // Cortar Q en varias palabras y aplicar peso
    condQ := util.StripWord(params.Q)
    xcondQ := strings.Split(condQ, " ")
    regla := ""
    for _, p := range xcondQ {
        if p != "" {
            regla += "Nombre:" + p + "^16" + " Descripcion:" + p + "^4" + " Extra:" + p + " "
        }
    }
    //      fmt.Println("Regla Q:", regla)
    q := bleve.NewQueryStringQuery(regla)
    query.AddQuery(q)
}

if params.Tipo != "" {
    regla := "+Tipo:" + params.Tipo
    q := bleve.NewQueryStringQuery(regla)
    query.AddQuery(q)
}

if params.Familia != "" {
    regla := "+Familias:" + params.Familia
    q := bleve.NewQueryStringQuery(regla)
    query.AddQuery(q)
}

if params.FamiliaReceta != "" {
    regla := "+Familias:" + params.FamiliaReceta + " +Tipo:" + kiwilimontypes.OBJECTID_RECETA
    q := bleve.NewQueryStringQuery(regla)
    query.AddQuery(q)
}

if params.ClasificacionReceta > 0 {
    regla := "+Clasificaciones:" + strconv.Itoa(params.ClasificacionReceta) + " +Tipo:" + kiwilimontypes.OBJECTID_RECETA
    q := bleve.NewQueryStringQuery(regla)
    query.AddQuery(q)
}

if params.FamiliaTip != "" {
    regla := "+Familias:" + params.FamiliaTip + " +Tipo:" + kiwilimontypes.OBJECTID_TIP
    q := bleve.NewQueryStringQuery(regla)
    query.AddQuery(q)
}

if params.ClasificacionTip > 0 {
    regla := "+Clasificaciones:" + strconv.Itoa(params.ClasificacionTip) + " +Tipo:" + kiwilimontypes.OBJECTID_TIP
    q := bleve.NewQueryStringQuery(regla)
    query.AddQuery(q)
}

if params.ClasificacionArticulo > 0 {
    regla := "+Clasificaciones:" + strconv.Itoa(params.ClasificacionArticulo) + " +Tipo:" + kiwilimontypes.OBJECTID_ARTICULO
    q := bleve.NewQueryStringQuery(regla)
    query.AddQuery(q)
}

if params.Multimedia > 0 {
    regla := "+Multimedia:>=" + strconv.Itoa(params.Multimedia)
    q := bleve.NewQueryStringQuery(regla)
    query.AddQuery(q)
}

if params.Chef > 0 {
    regla := "+Chef:" + strconv.Itoa(params.Chef)
    q := bleve.NewQueryStringQuery(regla)
    query.AddQuery(q)
}

// claves SI
if len(params.ListaClaveSi) > 0 {
    q := bleve.NewDocIDQuery(params.ListaClaveSi)
    query.AddQuery(q)
}

// claves NO
if len(params.ListaClaveNo) > 0 {
    q1 := bleve.NewBooleanQuery()
    q := bleve.NewDocIDQuery(params.ListaClaveNo)
    q1.AddMustNot(q)
    query.AddQuery(q1)
}

//
if params.Status != 0 {
    regla := "+Status:" + strconv.Itoa(params.Status)
    q := bleve.NewQueryStringQuery(regla)
    query.AddQuery(q)
}

search := bleve.NewSearchRequestOptions(query, params.Cantidad, params.Primero, false)
// siempre video primero
switch params.Orden {
case 2: // recomendado: video first, then rating desc
    search.SortBy([]string{"-Multimedia", "-Rating", "-Liberado"})
case 3: // popular: x view desc
    search.SortBy([]string{"-Multimedia", "-View", "-Liberado"})
case 4: // buscar normal por palabra
    search.SortBy([]string{"-Multimedia", "-_score"})
case 5: // buscar normal por mas nuevo
    search.SortBy([]string{"-Liberado"})
default: // lo mas nuevo: video, liberado desc
    search.SortBy([]string{"-Multimedia", "-Liberado"})
}
search.Fields = []string{"Tipo", "Clave"}
//  search.Explain = true

searchResults, err := index.Search(search)
//  fmt.Println(searchResults)
if err != nil {
    return nil, err
}
abhinavdangeti commented 7 months ago

@Likith101 would you look into what is going on here.

Likith101 commented 6 months ago

Can you provide a unit test that reproduces this issue?

Likith101 commented 2 months ago

Since there hasn't been any test cases provided and being unable to reproduce on our systems, I'm closing off this ticket. Please feel free to reopen if required