FileUpload form element: Hide file from search results?

Vote:
 

Hello all,

We have forms that use a FileUpload form element, with a link sent via email.  The uploaded files are linked to a /contentassets/../uploaded-files/ folder.  It makes sense that these files are findable in our site search, but that is not desirable for us.

Question: how do I exclude these uploaded files from search?  How do I identify this type of search result?  My experience is limited with Opti's search in general, plus the custom code I inherited.  

Thanks, Kevin

#312185
Nov 08, 2023 16:49
Vote:
 

Would you like to not index the files, or just not want the files to be shown in the public search results ?

are you using Find (Search & Navigation)

#312186
Nov 08, 2023 17:01
Vote:
 

Thanks Quan.  Yes, we are using Search & Nav.

I can't think of why any of our uploaded files need to be indexed, but either way should achieve the immediate goal.

#312187
Nov 08, 2023 17:13
Vote:
 

You can add a convention to prevent those files from being indexed. P/s you should update to latest version of Form if you haven't already

#312188
Nov 08, 2023 18:58
Vote:
 

Adding a convention is one thing I was looking at, but how do I target files specifically uploaded via the FileUpload element?

Re: EPiServer.Forms, I am on the latest

#312190
Nov 08, 2023 20:06
Vote:
 

A quick way to do it - not bulletproof but probably good enough, is check a file of type IContentMedia if it belongs to folder named EPiServer.Forms.Constants.FileUploadFolderName before indexing 

#312231
Nov 09, 2023 7:21
Vote:
 

Quan, I'm making a guess you are referring to something like:

ContentIndexer.Instance.Conventions.ForInstancesOf<IContentMedia>().ShouldIndex(x => x.???)

If so, how would I check for it's containing folder?

If not, can you share more info on how to do this?

#312245
Nov 09, 2023 14:06
Vote:
 

Yes, you can get its parent, something like this (pseudo code of course) 

x =>  {

var parent = _contentRepo.Get<ContentFolder>(x.ParentLink);

if (parent.Name == EPiServer.Forms.Constants.FileUploadFolderName) { return false ; }

return true;

}

#312246
Nov 09, 2023 14:13
Kevin Gainey - Nov 09, 2023 18:07
Thanks Quan! This solution works and is plenty good enough for what we need.
Kevin Gainey - Jan 10, 2024 19:05
I removed Quan's solution as an accepted answer. While this did remove these files, it also added all globalassets files to our search results. It is unknown if it added or excluded any other results.
Vote:
 

I'll try this.  I'll add this to our SearchInitialization module, which I assume is used during indexing.  I am wondering though... could this approach have a significant impact on performance of indexing?  I suppose I needn't be too concerned about the overnight job, but wanted to check.

#312259
Nov 09, 2023 14:37
Vote:
 

it depends on how many files you have - and under how many folders. if you have many files but only a few folders it would not take a lot of time (Get<T> is cached )

#312260
Nov 09, 2023 15:12
Kevin Gainey - Nov 09, 2023 18:06
In a quick test, it was only about 10% longer. No big deal
Vote:
 

If we take a step back, this should not happen. Can you please reach out to support at support@optimizely.com, refer to this thread and cc me (quan.mai [at] optimizely.com ) ? we are interested in looking into this. thank you

#312310
Nov 10, 2023 9:48
Vote:
 

Hello all,

I had to reopen this issue.  The offered solution did function as suggested, and I thought all was well.

However, it had the side effect of including files from other locations (namely globalassets) in the search that weren't there before.  My code (based on Quan's) was:

var _contentRepo = ServiceLocator.Current.GetInstance<IContentRepository>();
ContentIndexer.Instance.Conventions.ForInstancesOf<IContentMedia>().ShouldIndex(x => _contentRepo.Get<ContentFolder>(x.ParentLink).Name != EPiServer.Forms.Constants.FileUploadFolderName);

Without this code, I have no idea how globassets are excluded, but with it they are included.  I suppose other types of files were incorrectly included too, but I didn't scour our thousands of results.

Any ideas on why, and how to fix it so uploaded files are added to files to exclude?

#315531
Jan 12, 2024 20:17
Vote:
 

I suggest to find if you have any other conventions with IContentMedia which this overrides, and merge them into one 

#315640
Jan 15, 2024 8:05
Vote:
 

I have no other conventions with IContentMedia that I could merge.

#315703
Jan 16, 2024 13:35
Vote:
 

It turns out that the originally suggested code aslo broke our search statistics, and we don't know why.  Anyway, my resolution to this issue also fixed our search statistics & autocomplete functionality.

The code that ended up working was:

var _contentRepo = ServiceLocator.Current.GetInstance<IContentRepository>();
ContentIndexer.Instance.Conventions
	.ForInstancesOf<IContentMedia>()
	.ShouldIndex(x => x is not ImageData && _contentRepo.Get<ContentFolder>(x.ParentLink).Name != EPiServer.Forms.Constants.FileUploadFolderName);
#316498
Feb 01, 2024 16:53
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.