1
votes

I am creating a search for a website and using many filter options. I want to use filter on my many search results and for that i saw Filter property in SearchParameters for Azure Cognitive search. What i want is to pass a variable in Filter when i try to pass those parameters in filter search. Is there any possible way that i do not have to manually pass the Boulevard House from my data and use the variable houseName instead as i have provided options to choose and this is just plain-hardcode. Any refernce will help as well, as i tried to read the documents but in vain.

                {
                    Filter = String.Format("HouseName eq '{0}'", houseName)
                } ; 

                var names = new List<Search>();

                if (nameResult.Results.Count > 0)
                    {
                        foreach (SearchResult<Search> results in nameResult.Results)
                        {
                            names.Add(results.Document);
                        }
                    }

                NameSearchViewModel nameSearchViewModel = new NameSearchViewModel();
                nameSearchViewModel.Grants = names;
                return View(namesSearchViewModel);
1
I don't totally understand what the problem is. If you pass the options with the filter to your search method, it should work. Also, last month we released Azure.Search.Documents - the new version we are focusing on going forward - which has OData filter helps that can escape values for you as needed. See nuget.org/packages/Azure.Search.Documents for an example. - Heath

1 Answers

0
votes

I'm assuming you are using the C# SDK. You could do something like this

parameters = new SearchParameters
{
    Filter = String.Format("HouseName eq '{0}'", houseName) 
}