UnifiedSearch - Filtering based on Content location

Vote:
 

I've recently taken over maintainance of an EPiServer site using UnifiedSearch for two search functions on the site - one for all content within a specific folder (PublicationFiles), and one for all other content. When the site was running EPiServer 7.1, this was working with the following filters:

search = SearchClient.Instance.UnifiedSearchFor(query, Language.English);
return 
	search
	.BoostMatching(x => x.SearchTitle.MatchCaseInsensitive(query), 4)
	.Filter(x =>
		x.MatchTypeHierarchy(typeof(EPiServer.Web.Hosting.UnifiedFile))
		& ((EPiServer.Web.Hosting.UnifiedFile)x).Provider.ProviderName.Match("SitePublicationFiles"));

Shown here is the filter that only returned results from the top-level SitePublicationFiles folder - there is a corresponding filter that simply returns everything other than the contents of this folder!

However, since moving to the EPiServer 7.5+ world (CMS 7.16.1 and Find 8.10.0.1509 at present) this top level folder has been migrated into the new shared Block/Media directory structure, and now resides in ~/globalassets/publicationfiles/. I also understand that a lot of UnifiedFile functionality has been quietly deprecated (although I have struggled to find documentation for this, and VisualStudio throws no obsolete/deprecated warnings). The net result is that these filters no longer work at all - one returns everything, the other returns nothing!

I've reworked our searches to use new classes based on MediaData in place of UnifiedFile, but I'm struggling to find a replacement for this filtering-by-folder functionality. I had thought that I could use the following to filter based on the relative URL:

search = SearchClient.Instance.UnifiedSearchFor(query, Language.English);
var resolver = ServiceLocator.Current.GetInstance();
return
	search
	.BoostMatching(x => x.SearchTitle.MatchCaseInsensitive(query), 4)
	.Filter(x =>
		x.MatchType(typeof(PdfFile))
		& x.SearchHitUrl.PrefixCaseInsensitive("/globalassets/publicationfiles/")
		);

(Note that I'm only interested in PdfFiles from this directory. PdfFile here is a class that inherits from MediaData)

However, this returns no results. I've checked the UnifiedSearchHits returned, and I can see that they have Url properties that should be matched by this filter, so I'm not sure why, and it doesn't seem possible to debug 'inside' the filter. Other attempted filters include:

var resolver = ServiceLocator.Current.GetInstance();

...

.Filter(x =>
	x.MatchType(typeof(PdfFile))
	& resolver.GetUrl(((PdfFile)x).ContentLink).Contains("publicationfiles").Match(true));

This also doesn't work.

Is there any known way I can reliably filter based on content location, either URL or folder name within the EPiServer Blocks/Media directory structure?

#119803
Apr 02, 2015 19:34
Vote:
 

To clarify:

 I've checked the UnifiedSearchHits returned, and I can see that they have Url properties that should be matched by this filter

I mean to say that I've checked the UnifiedSearchHits returned when I remove the x.SearchHitUrl.PrefixCaseInsensitive call - the filter limiting results to PdfFile types is still in place, and works correctly.

#119804
Edited, Apr 02, 2015 19:36
Vote:
 

Hi Alex,

Have you tried using the AnyWordBeginsWith("/globalassets/publicationfiles/")) instead? 

/T


                        
#119805
Apr 02, 2015 20:13
Vote:
 

Hi Toni,

Just gave that a try, no joy. Also tried splitting the SearchHitURL by '/' then using Match("publicationfiles") on the string array, no luck.

This would be a lot easier if there was a way to actually poke at the ISearchContent objects in the debugger, but I can't see that this is possible - they only seem to exist in a transient, non-debuggable (at least in VS2012) state. I can see the relevant fields are present and correct on the UnifiedSearchHit objects, but can't cast these back to ISearchContent.

Does anyone have any other suggestions, or alternative approaches which may allow the same functionality?

#119914
Apr 07, 2015 14:44
Vote:
 

In case anyone else finds themselves in the same boat,I eventually hit a solution, after EPiServer Support pointed me in the direction of ContentFolders:

var repository = ServiceLocator.Current.GetInstance<IContentRepository>();
var rootFolder = ContentReference.GlobalBlockFolder;
var publicationFiles = repository.GetChildren<ContentFolder>(rootFolder).Single<ContentFolder>(x => x.Name == "PublicationFiles");

return
	search
	.BoostMatching(x => x.SearchTitle.MatchCaseInsensitive(query), 4)
	.Filter(x =>
		x.MatchType(typeof(PdfFile))
		& ((PdfFile)x).Ancestors().Match(publicationFiles.ContentLink.ID.ToString())
		);

Ancestors (which I found just by poking around) generates an array of strings of ContentIDs all the way down to the root node, so this does the trick for any PDF file sitting anywhere under the PublicationFiles folder.

#120793
Apr 24, 2015 11:45
Vote:
 

Alex, was looking for the exact same application with Ancestors(). Thanks!

#198621
Nov 01, 2018 11:01
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.