Confused with facets vs mappings

67 views
Skip to first unread message

jared f frag movies

unread,
Nov 8, 2023, 2:01:05 PM11/8/23
to bleve
I have a struct like this.

type Document struct {
Name string
Tool string
}

I want to be able to filter search results by tool (e.g. only search on documents with a tool value of "ABC"), but I don't want the tool value included in search results. I'm not sure how to achieve this, should I be using NewDocumentDisabledMapping?

Thanks

Mohd Shaad Khan

unread,
Nov 9, 2023, 5:40:38 AM11/9/23
to bleve
For this specific use case, you don't need fascets.

Say you have a Query1 which is a fuzzyQuery on Name field and it is giving you 100 hits.
Syntax will look something like this.
```
fq := bleve.NewFuzzyQuery("nameX")
fq.FieldVal = "name"
```

Now, out off 100 hits, you only want those hits, for which Tool="ABC".
To do this, you can use conjunctionQuery.
Syntax:
```
tq := bleve.NewTermQuery("ABC")
cq := bleve.NewConjunctionQuery(fq, tq)

searchRequest := bleve.NewSearchRequest(cq)
```

---------------------------------------------------------------------------------------------------

 I don't want the tool value included in search results

Which fields to display in the searchResult can be controlled while writing the searchRequest.
By default, a searchRequest doesn't include any field ( So you only see document IDs and not the field values in the search result)

You can add fields in the searchRequest like this
```
searchRequest.Fields = []string{"name", "tool"}
```

Mohd Shaad Khan

unread,
Nov 9, 2023, 5:44:17 AM11/9/23
to bleve
You can refer to https://gist.github.com/moshaad7/b993bf72516e50d5b2102d8da76c7765 for a working example.
Reply all
Reply to author
Forward
0 new messages