Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Ed Parry 64 posts 252 karma points c-trib
    Feb 02, 2017 @ 17:20
    Ed Parry
    0

    Boost a doctype - Examine

    I'm wondering if it's possible to boost certain doctypes when performing an examine search? I know I can for all or parts of the search query, but I'd like to implement something that is able to favour, say, news articles over standard content pages. Is that possible with Examine?

  • Ed Parry 64 posts 252 karma points c-trib
    Feb 03, 2017 @ 17:02
    Ed Parry
    0

    My current attempt at working through this is to:

    • Run the search as normal
    • Search through each result, and depending on its nodetypeaslias update the score given to it.
    • Re-order the results by score, which takes into effect the changes made for each nodetypealias.

    This works well and gives me the desired results, but I'm pretty sure this could be improved from a performance perspective. I'll keep working on it, but would be interested to hear if anyone else had done something similar!

  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    Feb 04, 2017 @ 10:02
    Dave Woestenborghs
    1

    Hi Ed,

    We did something similar but at indexing time by adding a event handler for the DocumentWriting event of your examine indexer.

    Something like this

     public class BootManager : ApplicationEventHandler
        {
    
            protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
            {            
                var contentIndexer = (UmbracoContentIndexer)ExamineManager.Instance.IndexProviderCollection["IndexerName"];                        
                libraIndexer.DocumentWriting += this.DocumentWriting;
    
                ContentService.Saving += ContentServiceOnSaving;
                //MediaService.Saved += MediaServiceSaved;
    
                base.ApplicationStarted(umbracoApplication, applicationContext);
            }
    
            public void DocumentWriting(object sender, DocumentWritingEventArgs e)
            {
                // boost doctype on indexing
                if (e.Fields["nodeTypeAlias"] == "YourDocTypeAlias")
                {
                    e.Document.SetBoost(2);
                }
            }
    
        }
    

    Dave

Please Sign in or register to post replies

Write your reply to:

Draft