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 249 karma points c-trib
    Sep 04, 2012 @ 12:48
    Ed Parry
    0

    Best way to feature selected articles

    Hi,

    I have a property for all content nodes which is "Feature in Search Results". The idea being that if the true/false box is selected, then that page will show above other pages for relevant searches. I'm aware of the scoring system already in place, and so I'm wondering if there's a way to plug into this, maybe something along the lines of:

    if (featured) { score = score + 1000; }

    ...but obviously different syntax!

    Any advice of how to acomplish this would be much appreciated :)

    Cheers,
    Ed

  • Douglas Robar 3565 posts 4640 karma points MVP 6x admin c-trib
    Sep 04, 2012 @ 14:39
    Douglas Robar
    1

    Yes, that's a perfectly fine way to do it! You'd update the xslt template that does the scoring and look for the features setting on the document and bump up the score there.

     

    Another option, that wouldn't require any changes to XSLTsearch (though it would require a change to your documents and thus might not meet your needs) would be to add a property to your Document Types for mega-powerful search terms. As you know, XSLTsearch not only looks for occurances of whatever is searched for but also weights the results to show those mostly likely to be better hits at the top of the list according to the searchFields= macro parameter.

    The math goes something like this to calculate the 'weight' of a page. To make it clearer, let's assume the following two pages and this XSLTsearch configuration:

    XSLTsearch macro parameters include:
    searchFields=pageName,@nodeName,metaKeywords,bodyText

    3 Pages in the site:
    @nodeName = Rock
    pageName = Rock 'n' Roll
    bodyText = All rock, all the time.

    @nodeName = Jazz
    pageName = (not set)
    bodyText = All that jazz.

    @nodeName = Classical
    pageName = Classical
    bodyText = Mostly piano and violin and stuff.

     

    So let's imagine we searched for 'all'.

     

    The letters 'a-l-l' are found in the bodyText of the page called 'Rock', so that page will get returned. It's total score is determined by how many times the search term is found in the various searchFields. 

     

    The order of the searchField properties determine the weight for each match. The last item in the list of searchFields (the 'bodyText' property) will have a multiplier of 1. The next to last property (metaKeywords) a multiplier of 2. The nodeName attribute (note the @ sign indicating it is an attribute in the xml) would be multiplied by 4, and the pageName property multiplied by 8. The idea here is that when a search term is found in an earlier property or attribute it is much more significant than if found later in the list of searchFields. If the term you are looking for is in the pageName property, for instance, that is very significant, much more significant than if it happens to show up even a few times in the bodyText. The order of the searchFields is therefore very important to scoring results in a default XSLTsearch implementation. 

    So, searching for 'all' gives a score of 2 for the the Rock page. That is, the search term is found twice in bodyText, and bodyText has a weight multiplier of 1 for each match. Similarly, the Jazz page gets a score of 1. Therefore, Rock is returned first and Jazz after that.

     

    Let's imagine we searched for the letter 'a':

    Rock page has a score of: 2 matches in bodyText * 1 = 2
    Jazz page has a score of: 1 match in nodeName * 4, plus 3 matches in bodyText * 1 = 7
    Classical page has a score of: 2 matches in pageName * 8, plus 2 matches in nodeName * 4, plus 3 matches in bodyText * 1 = 27

     

    The results would show Classical, then Jazz, then Rock.

     

     

    Now let's get clever.

    If you were to add a special searchTerms property on all the docTypes and included it first in the macro's searchFields= list. Whatever term(s) are in that field will be heavily weighted in the search results. 

    But wait, there's more!

    A trick to give a field a MUCH higher (or lower) weight is to insert a few commas in the searchFields= macro parameter. These act as empty fields between those to be very highly weighted and those very low. Since each search field is is twice as weighty as the next in the list it adds up fast. For example, searchFields="searchTerms,,,pageName,@nodeName,metaKeywords,bodyText" would make make any hit in the searchTerms property 8X more weighty than even in the pageName property. 

     

     

    Hope that explains the XSLTsearch algorithm for ranking and gives you the tools to modify it to meet your needs.

    cheers,
    doug. 

  • Ed Parry 64 posts 249 karma points c-trib
    Sep 04, 2012 @ 15:43
    Ed Parry
    0

    Thank you very much for that response, Doug! Very helpful indeed!

Please Sign in or register to post replies

Write your reply to:

Draft