Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more

How to filter out file types

Vote:
 

How can I, in the search, easily filter out files that I do not want to get

I would like to exclude all jpg, gif, png files for example

Is it possible to add a .Filter() or something here?

SearchClient.Instance.Search<UnifiedFile>(Language.Swedish)
.Take(300)
.GetResult();

#61802
Oct 02, 2012 12:21
Vote:
 

Hi Fredrik,

Yes you can. This is an example of how to filter away files by there extension

var result = client.Search<UnifiedFile>()
.Filter(x => !x.Extension.Match(".gif"))
.GetFilesResult();

 

If you never want to search for them, then best thing would to remove them at indexing time so they never enter the index. This could be done by setting up a convention for them.

FileIndexer.Instance.Conventions.ForInstancesOf<UnifiedFile>().ShouldIndex(x => !x.Extension.Equals(".gif"));

 

Hope that helps you.

#61803
Oct 02, 2012 13:02
Vote:
 

Thanks Marcus, works fine!

#61806
Oct 02, 2012 13:38
Vote:
 

Hi Fredrik, 

Just out of curiousity, is there any particular reason you're doing Take(300)? In general you should only Take(Number_of_hits_that_should_be_displayed) and then do paging using using Skip(). That is,

var pageSize = 10;
var pageNum = //From query string or whatever

.Skip((pageNum-1)*pageSize)
.Take(pageSize);

That way you won't be sending more data than needed over the wire and users will get snappier results. Then of course, sometimes there are exceptions.. :)

#61819
Oct 02, 2012 20:34
Vote:
 

Hi Joel,

Well that was when I was much younger and before I knew how to filter out the bad extensions (gif, jpg etc) from the resultset directly in the request (as Marcus pointed out in this thread). So I did the filtering on my end, bad performance of course, and just a nasty workaround.

Now I know better, and I surely will only fetch the items I actually need.

But there could be exceptions... ;-)

 

#61825
Oct 03, 2012 8:55
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.