2

I would like to use suggest query and filter documents to be considered for suggestions by few fields. Is it even possible? I could not find anything about this in ravendb documentation link to doc

I have tried to add my filter conditions to queryable but no luck

using (IDocumentSession documentSession = _storeProvider.GetStore().OpenSession())
            {
                var queryable = documentSession.Query<SearchableProduct>("SearchableProducts");

                var result = queryable
                    //I would like to filter by this field!
                    .Where(m => m.BrandNo == query.BrandNumber)
                    .Suggest(new SuggestionQuery
                {
                    Term = query.SearchTerm,
                    Accuracy = 0.4f,
                    Field = nameof(SearchableProduct.ProductName),
                    MaxSuggestions = 10,
                    Distance = (StringDistanceTypes)2,
                    Popularity = true
                });

                return result.Suggestions;
            }

Ravendb version: 3.0

Ihor
  • 299
  • 1
  • 11

1 Answers1

1

You cannot use additional filters on suggestion query. The way suggestion works, it evaluate a search term against the stored terms in the index, without considering other fields that may apply there.

You can use facets, to do filtering based on additional filters, and use the suggestion output as input to the facets, though.

Ayende Rahien
  • 22,925
  • 1
  • 36
  • 41