SaaS CMS has officially launched! Learn more now.

Filter extension method

Vote:
 

I am using UnifiedSearch and want to filter with an extension method like below:

            var findQuery = SearchClient.Instance
                                        .UnifiedSearchFor(Query, Language.GetSupportedLanguage(currentPage.Language))
                                        .Filter(x => x.Test().Match(true))
                                        .GetResult();

The extension method Test:

    public static class FindHelper
    {
        public static bool Test(this ISearchContent content)
        {
            return true;
        }
    }

The problem is that I am getting no hits...
And yes, the filter method will be more complex :)

What am I doing wrong?

#113717
Nov 26, 2014 21:04
Vote:
 

The thing I want to do is to find following that contains the searched text:

  • Get published pages that lies below a specified page (the search root).
  • Get files that are referenced from published pages that lies below the search root.
  • Get pages (below the search root) that has shared blocks that:
    • Contains the searched text.
    • Contains references to files that contains the searched text.

I want to make an extension method where I can check every searched ISearchContent if it also fulfills the criterias listed above.

On our site we have several search pages with different search roots.

Any suggestions?!

#113718
Nov 26, 2014 21:22
Vote:
 

Have you included the field/method Test() so it exists on all items in in the index? The filtering takes place in the search engine, so it must exist in the index.

Please see http://world.episerver.com/documentation/Items/Developers-Guide/EPiServer-Find/8/DotNET-Client-API/Customizing-serialization/Including-fields/.

#113725
Nov 27, 2014 7:30
Vote:
 

I have now :)
But how do I add the method to the index? I have EPiServer Find Version 7.0.586.24.

I have added a FindHelpers class with this method:

        public static IEnumerable<int> AncestorsForPagesWithFileReference<T>(this T file) where T : UnifiedFile
        {
            var ancestorLinks = new HashSet<int>();
            ...
            ...
        }

But how am I supposed to add this method to the index for all UnifiedFile's?

I hoped that I could do something like:

FileIndexer.Instance.Conventions.ForInstancesOf<UnifiedFile>().IncludeField(x => x.AncestorsForPagesWithFileReference());

But FileIndexer does not support the IncludeField method...

Any suggestions?

By the way, I've found this in the forum but I guess that is for EPiServer Find 7.5:

http://world.episerver.com/Modules/Forum/Pages/Thread.aspx?id=79729&epslanguage=en

#114017
Dec 02, 2014 22:50
Vote:
 

Try using SearchClient instead of FileIndexer. Haven't tested it, but I suppose that should work.

#114032
Dec 03, 2014 10:31
Vote:
 

It works!

SearchClient.Instance.Conventions.ForInstancesOf<UnifiedFile>().IncludeField(x => x.AncestorsForPagesWithFileReference());

But the next thing is to index files when the references to them are updated (as I have understood from another forum post).

I can listen to PublishedContent event for blocks and pages. But what should I do when a page/block with file references is deleted or if it expires (StopPublish). Are there any events to fetch then?

Are there any other scenarios when a file reference can be "deleted"?

#114081
Dec 04, 2014 9:59
Vote:
 

You can set related content to content, and when the related content is changed the content is re-indexed.

ContentIndexer.Instance.Conventions.ForInstancesOf<IContent>().RelatedContent(c => c.RelatedPages())
#114084
Dec 04, 2014 10:05
Vote:
 

But isn't the RelatedContent supposed to return a list of IContent? I want to reindex a list of files which is not IContent but a UnifiedFile in EPiServer Find Version 7.0.586.24.

#114085
Dec 04, 2014 10:15
Vote:
 

I think Johan means that you set it up so that you use related pages so that if a page has a relation to a file it will also update the related file.

#114141
Dec 05, 2014 6:26
* 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.