Copied to clipboard

Flag this post as spam?

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


  • Laurence Gillian 600 posts 1219 karma points
    Apr 13, 2011 @ 13:14
    Laurence Gillian
    0

    Using the Search XSLT Extension

    Hello,

    Just discovered the XSLT extension for requesting Examine/Lucene searches via XSLT.

    Having a bit of difficultly getting this going though...

    <!-- Let's define our search variables -->
      <xsl:variable name="searchString" select="'(+contentBody: humira)'"/>
      <xsl:variable name="boolean" select="'+'" />
      
      <!-- Let's write a basic search -->
      <xsl:value-of select="ucomponents.search:AdvancedSearch($searchString, $boolean, 'InternalIndexSet', 'content')"/>

    My questions would be;

    searchText = what is being expected here? 

    useWildcards = what is being expected here?

    providerName = what is being expected here? Would you standardly use 'InternalIndexer'?

    indexType = same ;)

    Thanks! (: Looking forward to building something snappy (: Lau

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Apr 13, 2011 @ 13:20
    Lee Kelleher
    0

    Hi Lau,

    OK, these extensions don't use Lucene query syntax - as they build it up themselves internally... using a querystring format (key=value&key2=value2)

    Also the boolean for the "useWildcard" needs to be a boolean (true/false) ... and the providerName needs to be a search provider, not the index set.

    Soooo... try something like this:

    <xsl:value-of select="ucomponents.search:AdvancedSearch('contentBody=humira', true(), 'InternalSearcher', 'content')"/>

    ... but if you just want to query the search term against all the fields, go with QuickSearch:

    <xsl:value-of select="ucomponents.search:QuickSearch('humira', true(), 'InternalSearcher', 'content')"/>

    Good luck!

    Cheers, Lee.

  • Laurence Gillian 600 posts 1219 karma points
    Apr 13, 2011 @ 13:29
    Laurence Gillian
    0

    Hmm interesting. QuickSearch works perfectly, however AdvancedSearch returns no results.

    Digging a bit deeper, I checked the ExamineIndex.config and noticed the InternalSearcher does not have 'contentBody' as a field.

    So I changed my search query to 'nodeName=humira', which should return some results, however still nothing. Odd! >.<

    Thanks! (: Lau

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Apr 13, 2011 @ 13:40
    Lee Kelleher
    0

    Hi Lau,

    Doh! Why are we using "value-of"? Its meant to return a node-set... so try this and see what it comes back with?

    <xmp>
        <xsl:copy-of select="ucomponents.search:AdvancedSearch('nodeName=humira')" />
    </xmp>

    I got rid of the other params - as they were using the default values anyway.

    Cheers, Lee.

  • Laurence Gillian 600 posts 1219 karma points
    Apr 13, 2011 @ 13:47
    Laurence Gillian
    0

    Just tried that still no joy...

      <!-- Let's write a advanced search -->
      <h1>Advanced Search - with Params</h1>
      <xsl:value-of select="ucomponents.search:AdvancedSearch('nodeName=Humira', true(), 'InternalSearcher', 'Content')"/>
      <h1>Advanced Search - no Params</h1>
      <xsl:copy-of select="ucomponents.search:AdvancedSearch('nodeName=humira')" />
     
      <!-- Basic Search -->
      <xsl:variable name="search" select="ucomponents.search:QuickSearch('humira')"/>
      
      <!-- Let's process our results -->
      <h1>Basic Search</h1>
      <xsl:for-each select="$search/* [@isDoc]">
        <xsl:call-template name="result" />
      </xsl:for-each>

    </xsl:template>
        
    <xsl:template name="result">
      <li><xsl:value-of select="@nodeName" /></li>
    </xsl:template>

    The Basic Search returns a beautiful set of results, and we can then even make them into a nice little list with the template at the bottom.

    But both;

    Advanced Search - With Params & Advanced Search - No Params

    Return no results. :(

  • Laurence Gillian 600 posts 1219 karma points
    Apr 13, 2011 @ 15:25
    Laurence Gillian
    0

    Just quickly fired up Luke to check the index files are working properly.

    So the way I read it

      <xsl:value-of select="ucomponents.search:AdvancedSearch('contentBody=me', true(), 'InternalSearcher', 'Content')"/>

    The search string is saying search for the 'word', which is 'me' in the 'contentBody' column.

    Or in Lucene syntax, that would be contentBody:me

    If I run 'contentBody:me' against my index, then it returns me a nice set of results, so the index is working properly. 

    I have also tried using the AdvancedSearch, against the standard Umbraco indexes, both by defining them, and also by not declaring them.

    -

    Interestingly if I type in a madeup index it throws an error (which is good), however when I type in my custom index. It just returns the 'no search results found'. So I'm guessing the fundemental issue is the format of the search string?

    Maybe? Just a hunch. /Laux

     

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Apr 13, 2011 @ 16:43
    Lee Kelleher
    0

    Hi Lau,

    I keep looking at the last parameter (of your last example) ... pretty sure it needs to be a lowercase "content".

    Also when you change the "<xsl:value-of" to <xsl:copy-of" ... do you get any <error> XML returned?

    Cheers, Lee.

  • Laurence Gillian 600 posts 1219 karma points
    Apr 13, 2011 @ 16:55
    Laurence Gillian
    0

    Okay so I've dug a little deeper...

    copy-of / value-of makes no difference, well except one returns the XML structure and one doesn't (in simple terms).

    So for example I now have...

    <h1>Advanced Search - with Params</h1>
      <xsl:copy-of select="ucomponents.search:AdvancedSearch('id=****', true(), 'InternalSearcher', 'Content')"/>
      <h1>Advanced Search - no Params</h1>
      <xsl:copy-of select="ucomponents.search:AdvancedSearch('id=****', true(), 'BlogPostSearcher', 'content')" />

    The first of which works, but the second doesn't.

    I've also tried 'Content' and 'content' it makes no difference. So I had a look at how the indexes work, as far as I can tell as long as your provider is using the type of type="UmbracoExamine.UmbracoContentIndexer, UmbracoExamine", it should have this dataTypes of content by default.

    Also if for example I change BlogPostSearcher to BlogPostSearcher2, it will throw an error. So its finding the index, it's just unable to search on that datatype. Interestingly you can type in any datatype, e.g mamaslkfjhaosfhaoihfioashfoiafh and it won't throw an error. 

    Just looking now to find a way to examine (haha no pun intended) the index file, to find where these datatypes are being set and how they are reference (if at all, I guess this could be in the examine layer?)

    Lau

  • Laurence Gillian 600 posts 1219 karma points
    Apr 13, 2011 @ 16:57
    Laurence Gillian
    0

    Any further still, on the working on I can change the 'Content' to "asjfopajsfpoasjfpoasjfopja" and it will still return results! 

    ARghh! >.<

Please Sign in or register to post replies

Write your reply to:

Draft