Copied to clipboard

Flag this post as spam?

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


  • J 351 posts 606 karma points
    May 24, 2017 @ 16:25
    J
    0

    Add additional field to search

    I have a field which is part of my document type. Could i add this field to XSLTSearch so it returns results based on part of this field?

  • Douglas Robar 3570 posts 4671 karma points MVP ∞ admin c-trib
    May 24, 2017 @ 18:50
    Douglas Robar
    1

    Hi, J,

    Yes, you can! You'd include the fields from your document type(s) that you want to search in the searchFields parameter of the macro.

    Check the PDF documentation that give full details about how to do it and the importance of the order you put the fields to search (those you list first are given much higher ranking weight than those nearer the end of the list of property fields to search).

    But may I suggest, unless you're fluent with XSLT and/or have an Umbraco v4 or earlier website, that you use ezSearch instead? It does all the same things as XSLTsearch, uses the same concepts for which fields to search, but is faster and uses the more current Razor syntax.

    cheers,
    doug.

  • J 351 posts 606 karma points
    Jun 02, 2017 @ 10:50
    J
    0

    Thanks - Its a pretty old site so i dont really want to add any new features in case it breaks something :-( so hoping i can get away with a few modifications here and there.

    I noticed the search results page takes in 1 argument i.e. ....?search=Michael%20Jackson which then shows all records with Michael Jackson listed.

    My search page has two controls one is a textbox and other is a list of years. Is it possible to search for two criterias? So MJ has a few albums released in different years, so if i typed "Michael Jackson" and selected a year it would display all MJ albums with the year selected or if year was only selected then it would show all content which contains the year?

  • Douglas Robar 3570 posts 4671 karma points MVP ∞ admin c-trib
    Jun 02, 2017 @ 13:21
    Douglas Robar
    0

    Hi, J,

    It's possible to modify XSLTsearch.xslt to do that, but it is truly a customization and not something to be thought of as a quick tweak.

    One possible option that would be quick and might get you far enough to be workable... remember that XSLTsearch only returns matches that have all the search terms somewhere in the searched terms. If you were to search for "Michael Jackson 2006" and include the field containing the release year in the searchFields list, that would only return those albums by MJ released in 2006. So perhaps you could have your list of years append to the 'search' querystring?

    cheers,
    doug.

  • J 351 posts 606 karma points
    Jun 02, 2017 @ 14:26
    J
    0

    I "think" i understand what you are suggesting. My Doc type has two fields (for this example)

    Name Year

    When they arrive to the search page they enter a name and an optional field - year. Ive added both fields to the search criteria.

    The issue im facing is the site must be searchable by both fields as the user may come onto the site and select only a year - i can append the year to the search parameter, however when i do that i dont get the results i was expecting:

    First entry is Michael Jackson with the Year 1980 Second entry is Madonna with the Year 2017

    I enter the search as Michael%20Jackson&2017 in the address bar it would look like

    ?search=Michael%20Jackson&2017
    

    but it only brings back MJ entry and not Madonna's? Am i doing something wrong?

    BTW - thanks very much for help, i appreciate it a lot.

    Cheers

  • Douglas Robar 3570 posts 4671 karma points MVP ∞ admin c-trib
    Jun 02, 2017 @ 16:38
    Douglas Robar
    0

    Need to dash so just a quick reply for the moment that I hope will get you going... shout if you need a longer discussion later on.

    Remember that querystring parameters passed in to the same item are separated with a +. Your query could be ?search=Michael+Jackson+2017. Which would be three individual items passed in to the search querystring.

    Though, XSLTsearch handles spaces just as well so you could equally have ?search=Michael%20Jackson+2017 Any combination of spaces and pluses will work with XSLTsearch. And will mean that only items that match all three terms will be displayed.

    If you only has ?search=2017 you'd get albums released in 2017 (or that had 2017 in one of the other searchfields).

    Hope this helps. Practice with manually adjusting the querystring in the browser's url until you get the hang of it. Then figure out how to make your form create the proper querystring.

    cheers,
    doug.

Please Sign in or register to post replies

Write your reply to:

Draft