Skip to content

Search for EXACT Array? #637

@bt

Description

@bt

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions