A critical vulnerability was discovered in React Server Components (Next.js). Our systems remain protected but we advise to update packages to newest version. Learn More

Filter on class property type having issues

Vote:
 

Hi,

I am facing issue while applying filter to episerver find.

I want to filter results based on condition that items found should be based on Document Class Property "HideDocumentInSearchResults" Value True/False.

If True should filter out from results, if False should be there in results.

My code is as below:

private string theQuery; //it is set as "08132.pdf"

private FilterBuilder BuildTypeFilters(string facet)
{
var filter = this.client.BuildFilter();

filter = filter.And(y => y.MatchTypeHierarchy(typeof(SiteBasePageData)) | y.MatchType(typeof(SiteBasePageData)));
filter = filter.Or(y => y.MatchTypeHierarchy(typeof(Document)) | y.MatchType(typeof(Document)));

filter = filter.And(q => !((SiteBasePageData)q).HideInSearchResult.Match(true)); //this works fine

filter = filter.And(q => !((Document)q).Name.Match("08132.pdf")); //this works fine

filter = filter.And(q => !((Document)q).HideDocumentInSearchResults.Match(true)); //this fails


return filter;
}

private IContentResult GetResult(int take = 10, int skip = 0) where T : class, IContent
{

this.theQuery = query;

var result = this.client.Search(Language.Swedish).For(this.theQuery)
.UsingSynonyms()
.InField(x => x.SearchTitle())
.InField(x => x.SearchText())
.InAllField()
.ApplyBestBets()
.CurrentlyPublished()
.PublishedInCurrentLanguage()
.Filter(this.typefilter)
.Filter(this.wherefilter)
.FilterForVisitor()
.ExcludeDeleted()
.Track()
.Skip(skip)
.Take(take)
.FilterFacet("document", x => x.MatchTypeHierarchy(typeof(Document)) | x.MatchType(typeof(Document)))
.FilterFacet("news", x => x.MatchTypeHierarchy(typeof(NewsPageType)) | x.MatchType(typeof(NewsPageType)))
.StaticallyCacheFor(new TimeSpan(0, 0, 0,CacheSeconds))
.GetContentResult(CacheSeconds)
;


return result;

}

Thanks.

BR/Rajesh K

#197712
Edited, Oct 10, 2018 23:13
Vote:
 

Applied below fixes which solved my issue...

a) added [IndexInContentAreas] to class.

b) The new property was already added with [CultureSpecific] attribute.

c) Run search indexing job. It should add this new value to search indexes. and so the below filter conditions will work...

d) filter = filter.And(q => !((Document)q).HideDocumentInSearchResults.Match(true)); //for us it means hide documents/files from search results who are set true 

Regards,

Rajesh K

#200045
Dec 27, 2018 12:51
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* 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.