blevesearch / bleve

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

Search for EXACT Array? #637

Open bt opened 7 years ago

bt commented 7 years ago

I understand that arrays is not fully implemented as there are some issues that relate to it (eg: #570) but I couldn't find any information on searching on arrays.

Here's example code of what I'm trying to achieve:

package main

import (
    "fmt"
    "github.com/blevesearch/bleve"
    "log"
)

type doc struct {
    Name       string
    Recipients []string
}

func main() {
    mapping := bleve.NewIndexMapping()
    index, err := bleve.NewMemOnly(mapping)

    d := doc{Name: "xyz", Recipients: []string{"a@example.com", "b@example.com"}}
    if err := index.Index("1234", d); err != nil {
        log.Fatal(err)
    }

    d2 := doc{Name: "abc", Recipients: []string{"a@example.com", "b@example.com", "c@example.com"}}
    if err := index.Index("5678", d2); err != nil {
        log.Fatal(err)
    }

    query := bleve.NewMatchQuery("[a@example.com b@example.com]")
    search := bleve.NewSearchRequest(query)
    search.Fields = []string{"Name", "Recipients"}
    searchResults, err := index.Search(search)
    if err != nil {
        log.Fatal(err)
    }

        // Expecting "1", but returning 2
    fmt.Printf("num results: %d\n", searchResults.Hits.Len())

    hit := searchResults.Hits[0]
    fmt.Printf("%s\n", hit.Fields)
}

In the above example, I'm trying to find an array with an exact match of [a@example.com b@example.com], which should only return 1 result; the document with ID 1234, Name: xyz, but it's returning both documents now. Is there a way I can achieve this?

mschoch commented 7 years ago

Currently there is no search mechanism to restrict matches based on their positions within an array. This information is in the index, we just don't have any query operators that use it.

The issue open here: https://github.com/blevesearch/bleve/issues/15 has been left open since we have not yet added support for searching based on these array positions.