November Happy Hour will be moved to Thursday December 5th.

Another question on Searching multiple Fields

Vote:
 

If I have the code below, but I want to search more than one field for given values that I KNOW, how do I do that?

            var searchRequest = new EPiServer.Find.Api.SearchRequestBody
            {
                Size = 1,
                From = 0,
                Query = new EPiServer.Find.Api.Querying.Queries.FieldQuery("SearchFilename$$string",filename)
            };
           
            var searchHits = client.Search(searchRequest, command => { });
#195262
Jul 18, 2018 20:46
Vote:
 

You should be able to use Filters right? 

var searchHits = client.Search<RemoteHostedContentItem>().Filter(x =>x.Field1.Match(value1) & x.Field2.Match(value2));

#195601
Jul 31, 2018 21:49
Vote:
 

Hi. I would use _client.BuildFilter<RemoteHostedContentItem> to build out the filter based on the values that you know. An example of useage would be:

var query = _client.Search<RemoteHostedContentItem>().ExcludeDeleted().CurrentlyPublished();

// Check for values you know
// By wrapping in if statement
// filename is just an example add your fields here
if (!string.IsNullOrEmpty(filename)) 
{
	var NameFilter = _client.BuildFilter<RemoteHostedContentItem>().And(x => x.FileName.Match("filename"));
	query = query.Filter(NameFilter);
}

// Example to show adding another Filter to query
// Let's say your type implements this interface which allows you
// To hide a file from search
var SearchableFilter = _client.BuildFilter<IShouldSearch>().And(x => x.IsHiddenFromSearch.Match(false));

// Calling query.Filter multiple times on query adds the querys together, it does not replace the last one
query = query.Filter(SearchableFilter);

var results = query.Skip((page - 1) * pageSize).Take(pageSize).GetContentResult();

Hope this helps!

-John

#197077
Sep 20, 2018 22:11
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.