Jahia Dev Forum > How to retrieve...

0 (0 Good)
0 (0 Bad)

How to retrieve site of search results

by  Flynn »  2011/06/07 20:45

Hi,

We have 2 virtual sites, we need to check what is the site of each results in search template to apply specific css for each result. How this result's site can be retrieve ?

Ty for your help.

Flynn.



ps : Search template is the acme template >> ${hit}
  • How to retrieve site of search results
    2011/07/08 13:39

    Flynn <p> Hi,<br /> <br /> We have 2 virtual sites, we need to check what is the site of each results in search template to apply specific css for each result. How this result&#39;s site can be retrieve ?<br /> <br /> Ty for your help.<br /> <br /> Flynn.</p> <br /> <br /> <div style="clear:both;"> <div> ps : Search template is the acme template &gt;&gt; ${hit}</div> </div>

  • Number of messages  32
    Registration date Jun 7, 2011
    0 (0 Good)
    0 (0 Bad)

    Re: How to retrieve site of search results

    by  pap@commaro.com »  2011/06/07 20:45

     

    Hello,

     

    can you try this:

    <c:choose>
    
    <c:when test="${hit.typeContainer || hit.typePage}">
    
        <c:set var="searchHitSiteID" value="${hit.rawHit.siteID}"/>
    
    </c:when>
    
    <c:when test="${hit.typeDocument && hit.referencedHit != null}">
    
        <c:set var="searchHitSiteID" value="${hit.referencedHit.rawHit.siteID}"/>
    
    </c:when>
    
    </c:choose>

     

    Regards,

    Benjamin

    Benjamin Papez (pap@commaro.com)

    Number of messages  220
    Registration date
    0 (0 Good)
    0 (0 Bad)

    Re: How to retrieve site of search results

    by  Flynn »  2011/06/07 20:45

    Works, but we can't exploit this random siteID with our several servers.

    How can we retrieve site name with this siteID ?

    TY.
  • Re: How to retrieve site of search results
    2011/06/07 20:45

    Flynn Works, but we can't exploit this random siteID with our several servers.<br/><br/>How can we retrieve site name with this siteID ?<br/><br/>TY.

  • Number of messages  32
    Registration date Jun 7, 2011
    0 (0 Good)
    0 (0 Bad)

    Re: How to retrieve site of search results

    by  pap@commaro.com »  2011/06/07 20:45

     

    hello,

     

    unfortunately you can't get it with the expression language, but only with a scriptlet:

    <c:set var="searchHitSiteKey" value='<%=org.jahia.registries.ServicesRegistry.getInstance().getJahiaSitesService().getSite(pageContext.findAttribute("searchHitSiteID")).getSiteKey()%>'/>

     

    Regards,

    Benjamin

     

    Benjamin Papez (pap@commaro.com)

    Number of messages  220
    Registration date
    0 (0 Good)
    0 (0 Bad)

    Re: How to retrieve site of search results

    by  Flynn »  2011/06/07 20:45

    I have an error in logs :

     

    The method getSite(int) in the type JahiaSitesService is not applicable for the arguments (Object)

     

  • Re: How to retrieve site of search results
    2011/07/08 13:43

    Flynn <p> I have an error in logs :</p> <p> &nbsp;</p> <pre> The method getSite(int) in the type JahiaSitesService is not applicable for the arguments (Object)</pre> <p> &nbsp;</p>

  • Number of messages  32
    Registration date Jun 7, 2011
    0 (0 Good)
    0 (0 Bad)

    Re: How to retrieve site of search results

    by  pap@commaro.com »  2011/06/07 20:45

    Sorry, I was just typing the statement by heart. You will need to add a cast to the result of pageContext.findAttribute("searchHitSiteID") which is an Integer (and depedning on the JDK get the intValue from it).

    Regards,
    Benjamin

    Benjamin Papez (pap@commaro.com)

    Number of messages  220
    Registration date
    0 (0 Good)
    0 (0 Bad)

    Re: How to retrieve site of search results

    by  Flynn »  2011/06/07 20:45

    Works perfectly !

    Just another question about search...

    We try to retrieve the "page.path[1].urlKey" and "page.path[2].urlKey" to make a small breadcrumb of each result like :

    News 1
    Site A - first_level_name > second_level_name
    resultslistDesc resultslistDesc resultslistDesc resultslistDesc resultslistDesc

    Any idea ?

  • Re: How to retrieve site of search results
    2011/07/08 13:44

    Flynn <p> Works perfectly !<br /> <br /> Just another question about search...<br /> <br /> We try to retrieve the &quot;page.path[1].urlKey&quot; and &quot;page.path[2].urlKey&quot; to make a small breadcrumb of each result like :<br /> <br /> News 1<br /> Site A - first_level_name &gt; second_level_name<br /> resultslistDesc resultslistDesc resultslistDesc resultslistDesc resultslistDesc<br /> <br /> Any idea ?</p>

  • Number of messages  32
    Registration date Jun 7, 2011
    0 (0 Good)
    0 (0 Bad)

    Re: How to retrieve site of search results

    by  pap@commaro.com »  2011/06/07 20:45

    Hi,

    ok, if you also need the page associated to a hit, you will need to use code like this (again, just typed by heart without testing it, so you may have to fix some typos or obvious errors):



    <c:set var="jahiaHit" value="${hit.typeDocument && hit.referencedHit != null ? hit.referencedHit : hit}"/>
    
    <c:set var="searchHitSiteID" value="${jahiaHit.rawHit.siteID}"/>
    
    <c:set var="searchHitSiteKey" value='<%=org.jahia.registries.ServicesRegistry.getInstance().getJahiaSitesService().getSite((Integer)pageContext.findAttribute("searchHitSiteID")).getSiteKey()%>'/>
    
    <c:set var="contentPage" value="${hit.typeContainer ? jahiaHit.rawHit.page : jahiaHit.rawHit}"/>
    
    <c:set var="page" value='<%=org.jahia.data.beans.PageBean.getChildInstance((org.jahia.content.JahiaObject)pageContext.findAttribute("contentPage"), ((org.jahia.data.beans.RequestBean)pageContext.findAttribute("currentRequest")).getProcessingContext())%>'/>

    Notice, that I have first incorporated the solution for getting the siteKey and then to get the page-bean on which you can then get the path and url-key, like you suggested.

     

    Regards,

    Benjamin

    Benjamin Papez (pap@commaro.com)

    Number of messages  220
    Registration date
    0 (0 Good)
    0 (0 Bad)

    Re: How to retrieve site of search results

    by  Flynn »  2011/06/07 20:45

     

     

     

    The first modification i have to do on "searchHitSiteKey" is ok :

    <c:set var="searchHitSiteKey" value='<%=org.jahia.registries.ServicesRegistry.getInstance().getJahiaSitesService().getSite([b]((Integer) pageContext.findAttribute("searchHitSiteID")).intValue()[/b]).getSiteKey()%>'/>

     

    but i don't see the modification i have to do on the "page" <c:set>  :

    <c:set var="page" value='<%=org.jahia.data.beans.PageBean.getChildInstance((org.jahia.content.JahiaObject)pageContext.findAttribute("contentPage"), ((org.jahia.data.beans.RequestBean)pageContext.findAttribute("currentRequest")).getProcessingContext())%>'/>

    I have this error in logs :

    org.jahia.services.containers.ContentContainer cannot be cast to org.jahia.services.pages.ContentPage

     

    I'm not pro with casting 

  • Re: How to retrieve site of search results
    2011/07/08 13:48

    Flynn <p> &nbsp;</p> <p> &nbsp;</p> <p> &nbsp;</p> <p> <title></title> </p> <p> The first modification i have to do on &quot;searchHitSiteKey&quot; is ok :</p> <pre> &lt;c:set var=&quot;searchHitSiteKey&quot; value=&#39;&lt;%=org.jahia.registries.ServicesRegistry.getInstance().getJahiaSitesService().getSite([b]((Integer) pageContext.findAttribute(&quot;searchHitSiteID&quot;)).intValue()[/b]).getSiteKey()%&gt;&#39;/&gt;</pre> <p> &nbsp;</p> <p> but i don&#39;t see the modification i have to do on the &quot;page&quot; &lt;c:set&gt;&nbsp; :</p> <pre> &lt;c:set var=&quot;page&quot; value=&#39;&lt;%=org.jahia.data.beans.PageBean.getChildInstance((org.jahia.content.JahiaObject)pageContext.findAttribute(&quot;contentPage&quot;), ((org.jahia.data.beans.RequestBean)pageContext.findAttribute(&quot;currentRequest&quot;)).getProcessingContext())%&gt;&#39;/&gt;</pre> <p> I have this error in logs :</p> <p> org.jahia.services.containers.ContentContainer cannot be cast to org.jahia.services.pages.ContentPage</p> <p> &nbsp;</p> <p> I&#39;m not pro with casting&nbsp;</p>

  • Number of messages  32
    Registration date Jun 7, 2011
    0 (0 Good)
    0 (0 Bad)

    Re: How to retrieve site of search results

    by  pap@commaro.com »  2011/06/07 20:45

    Hello,

    instead of:



    <c:set var="contentPage" value="${hit.typeContainer ? jahiaHit.rawHit.page : jahiaHit.rawHit}"/>

    can you try using just this:

    <c:set var="contentPage" value="${jahiaHit.rawHit.page}"/>

    let me know if this works, or if you get other exceptions.

     

    Regards,

    Benjamin

    Benjamin Papez (pap@commaro.com)

    Number of messages  220
    Registration date
    Contact
    Share
    Feedback

    Get in touch

    Whether you are a current user or if you are just evaluating Jahia, we are here to help.

    Contact us

    Share this page