-3

我已经创建了一个 tridion 网站,现在我想添加一些搜索控件,例如 Google 自定义搜索,是否有 tridion 提供的相同选项?

我的选择:我必须创建一个用户控件并在其中实现 Google 自定义搜索,然后在我的页面上呈现它。或任何其他方法会更好。

搜索控件(包含文本框和一个搜索按钮)应该能够搜索文本。
搜索结果应该像搜索引擎一样格式化。

4

1 回答 1

2

当您说 Google 时,您指的是 Google Search Appliance (GSA) 吗?

假设是这种情况:您似乎已经使用 XSLT 做了很多工作,所以在我看来,最简单的方法是让您的用户控件使用相关查询调用 GSA 的 XML API,并简单地转换响应使用 XSLT。这样可以避免在需要更改布局时重新编译控件,并且可以从 Tridion 发布 XSLT。

我使用以下 XSLT 在此页面http://medicine.yale.edu/search.aspx?q=test&x=0&y=0&site=YSM_School_of_Medicine上生成搜索结果

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:output method="html" omit-xml-declaration="yes"/>
    <xsl:param name="SITE_CATALOG"/>
    <xsl:param name="SITE_NAME"/>   
    <xsl:param name="MAX_PAGES_IN_NAVIGATION">10</xsl:param>
    <xsl:param name="TOTALNUMBER" select="/GSP/RES/M"/>
    <xsl:param name="QUERY" select="/GSP/PARAM[@name='q']/@value"/>
    <xsl:param name="SEARCHED_SITE_CATALOG" select="/GSP/PARAM[@name='site']/@value"/>
    <xsl:template match="/">
        <xsl:variable name="STARTNUMBER" select="/GSP/RES/@SN"/>
        <xsl:variable name="ENDNUMBER" select="/GSP/RES/@EN"/>
        <xsl:variable name="TIMER" select="/GSP/TM"/>
        <!--begin search results -->
        <div class="google-search-form bordered-box shaded-f5 padded-20">
            <xsl:call-template name="WriteSearchForm"/>
        </div>
        <xsl:if test="/GSP/Spelling">
            <p>Did you mean <a href="?q={/GSP/Spelling/Suggestion/@q}&amp;site={/GSP/PARAM[@name='site']/@value}">
                    <xsl:value-of select="/GSP/Spelling/Suggestion/@q"/>
                </a>?</p>
        </xsl:if>
        <div id="search-results-pagination">

            <xsl:for-each select="/GSP/RES/R">
                <xsl:choose>
                    <xsl:when test="@L='2'">
                        <div class="grouped-search-result">
                            <h4>
                                <a href="{U}">
                                    <xsl:value-of select="T" disable-output-escaping="yes"/>
                                </a>
                            </h4>
                            <p class="search-result-body">
                                <xsl:value-of select="S" disable-output-escaping="yes"/>
                            </p>
                            <p class="gray95">
                                <span class="green">
                                    <xsl:choose>
                                        <xsl:when test="string-length(U) &gt; 88">
                                            <xsl:value-of select="substring(U, 0, 88)"/>...
                                        </xsl:when>
                                        <xsl:otherwise>
                                            <xsl:value-of select="U"/>
                                        </xsl:otherwise>

                                    </xsl:choose>
                                </span>
                            </p>

                            <p>
                                <a href="?as_sitesearch={HN/@U}&amp;q={$QUERY}&amp;site={$SITE_CATALOG}" class="more-results-link">
                                    [ <span>
                                        More results from <xsl:value-of select="HN/@U"/>
                                    </span> ]
                                </a>
                            </p>
                        </div>
                    </xsl:when>
                    <xsl:otherwise>
                        <div class="pagination-element search-result">
                            <h4><a href="{U}">

                                    <xsl:call-template name="WriteMimeTypeIndicator">
                                        <xsl:with-param name="RESULT" select="."/>
                                    </xsl:call-template>
                                    <xsl:value-of select="T" disable-output-escaping="yes"/>

                            </a></h4>
                            <p class="search-result-body">
                                <xsl:value-of select="S" disable-output-escaping="yes"/>
                            </p>
                            <p>
                                <span class="green">
                                    <xsl:choose>
                                        <xsl:when test="string-length(U) &gt; 92">
                                            <xsl:value-of select="substring(U, 0, 92)"/>...
                                        </xsl:when>
                                        <xsl:otherwise>
                                            <xsl:value-of select="U"/>
                                        </xsl:otherwise>

                                    </xsl:choose>

                                </span> - <xsl:value-of select="HAS/C/@SZ"/>
                            </p>
                        </div>
                    </xsl:otherwise>
                </xsl:choose>
            </xsl:for-each>
        </div>
        <hr class="dashed" />

<xsl:call-template name="WritePageNavigation"/>
        <!--<div id="pagination-controls" class="pagination-controls float-rt"></div>-->

        <!-- end pagination-controls -->



        <div class="results-footer-notes">

            <p class="small-gray95">Note: This search service may return results that are not approved by Yale University, or results that may not reflect the official views of Yale University.</p>

        </div>



        <div class="clear"></div>

        <div class="google-search-form bordered-box shaded-f5 padded-20 big-margin-top">
            <xsl:call-template name="WriteSearchForm"/>
        </div>
        <!-- end search results -->
    </xsl:template>
    <xsl:template name="WritePageNavigation">
        <xsl:variable name="RESULTS_ON_THIS_PAGE" select="count(/GSP/RES/R)"/>
        <xsl:variable name="TOTAL_RESULT_COUNT" select="/GSP/RES/M"/>
        <xsl:variable name="TOTAL_PAGES" select="ceiling($TOTAL_RESULT_COUNT div $RESULTS_ON_THIS_PAGE)"/>
        <xsl:variable name="CURRENT_PAGE" select="floor((/GSP/RES/@SN) div $RESULTS_ON_THIS_PAGE) + 1"/>
        <xsl:variable name="START_RESULT" select="/GSP/RES/@SN"/>
        <!--

    Results On This Page: <xsl:value-of select="$RESULTS_ON_THIS_PAGE"/>
        <br/>
    Total Results: <xsl:value-of select="$TOTAL_RESULT_COUNT"/>
        <br/>
    Total Pages: <xsl:value-of select="$TOTAL_PAGES"/>
        <br/>
    Current Page: <xsl:value-of select="$CURRENT_PAGE"/>
        <br/>
    Start Result: <xsl:value-of select="$START_RESULT"/>
        <br/>
    Start Navigation Page: <xsl:value-of select="$CURRENT_PAGE - ($MAX_PAGES_IN_NAVIGATION div 2)"/>
-->
        <xsl:if test="$TOTAL_PAGES &gt; 1">
            <ul class="google-search-pagination">

                <xsl:if test="$CURRENT_PAGE &gt; 1">
                    <li class="pagination-previous">
                        <a href="?q={/GSP/PARAM[@name='q']/@value}&amp;start={($CURRENT_PAGE - 2)*$RESULTS_ON_THIS_PAGE}&amp;site={/GSP/PARAM[@name='site']/@value}">Previous</a>
                    </li>
                </xsl:if>





                <xsl:call-template name="WritePaging">
                    <xsl:with-param name="CURRENT_PAGE" select="$CURRENT_PAGE"/>
                    <xsl:with-param name="NEXT_PAGE_START" select="$RESULTS_ON_THIS_PAGE + 1"/>
                    <xsl:with-param name="TOTAL_RESULTS" select="$TOTAL_RESULT_COUNT"/>
                    <xsl:with-param name="RESULTS_ON_PAGE" select="$RESULTS_ON_THIS_PAGE"/>
                    <xsl:with-param name="START_PAGE">
                        <xsl:choose>
                            <xsl:when test="($CURRENT_PAGE - ($MAX_PAGES_IN_NAVIGATION div 2)) &gt; 0">
                                <xsl:value-of select="$CURRENT_PAGE - ($MAX_PAGES_IN_NAVIGATION div 2)"/>
                            </xsl:when>
                            <xsl:otherwise>1</xsl:otherwise>
                        </xsl:choose>
                    </xsl:with-param>
                    <xsl:with-param name="END_PAGE">
                        <xsl:choose>
                            <xsl:when test="($CURRENT_PAGE - ($MAX_PAGES_IN_NAVIGATION div 2)) &gt; 0">
                                <xsl:value-of select="$MAX_PAGES_IN_NAVIGATION + $CURRENT_PAGE - floor($MAX_PAGES_IN_NAVIGATION div 2) - 1"/>
                            </xsl:when>
                            <xsl:otherwise>
                                <xsl:value-of select="$MAX_PAGES_IN_NAVIGATION"/>
                            </xsl:otherwise>
                        </xsl:choose>
                    </xsl:with-param>
                </xsl:call-template>

                <li class="pagination-next">
                    <a href="?q={/GSP/PARAM[@name='q']/@value}&amp;start={($CURRENT_PAGE)*$RESULTS_ON_THIS_PAGE}&amp;site={/GSP/PARAM[@name='site']/@value}">Next</a>
                </li>

            </ul>
        </xsl:if>
    </xsl:template>
    <xsl:template name="WritePaging">
        <xsl:param name="NEXT_PAGE_START"/>
        <xsl:param name="RESULTS_ON_PAGE"/>
        <xsl:param name="TOTAL_RESULTS"/>
        <xsl:param name="CURRENT_PAGE"/>
        <xsl:param name="START_PAGE"/>
        <xsl:param name="END_PAGE"/>
<!--
        NEXT_PAGE_START: <xsl:value-of select="$NEXT_PAGE_START"/><br/>
        RESULTS_ON_PAGE: <xsl:value-of select="$RESULTS_ON_PAGE"/><br/>
        TOTAL_RESULTS: <xsl:value-of select="$TOTAL_RESULTS"/><br/>
        CURRENT_PAGE: <xsl:value-of select="$CURRENT_PAGE"/><br/>
        START_PAGE: <xsl:value-of select="$START_PAGE"/><br/>
        END_PAGE: <xsl:value-of select="$END_PAGE"/><br/>
-->


        <li>
            <xsl:if test="$CURRENT_PAGE = $START_PAGE">
                <xsl:attribute name="class">selected</xsl:attribute>
                <a href="#">
                    <xsl:value-of select="$START_PAGE"/>
                </a>
            </xsl:if>
            <xsl:if test="$CURRENT_PAGE != $START_PAGE">
                <a href="?q={/GSP/PARAM[@name='q']/@value}&amp;start={($START_PAGE - 1)*$RESULTS_ON_PAGE}&amp;site={/GSP/PARAM[@name='site']/@value}">
                    <xsl:value-of select="$START_PAGE"/>
                </a>
            </xsl:if>
        </li>



        <xsl:if test="$START_PAGE &lt; $END_PAGE">
            <xsl:if test="$NEXT_PAGE_START &lt; $TOTAL_RESULTS">
                <xsl:call-template name="WritePaging">
                    <xsl:with-param name="NEXT_PAGE_START" select="$NEXT_PAGE_START + $RESULTS_ON_PAGE"/>
                    <xsl:with-param name="TOTAL_RESULTS" select="$TOTAL_RESULTS"/>
                    <xsl:with-param name="RESULTS_ON_PAGE" select="$RESULTS_ON_PAGE"/>
                    <xsl:with-param name="START_PAGE" select="$START_PAGE + 1"/>
                    <xsl:with-param name="CURRENT_PAGE" select="$CURRENT_PAGE"/>
                    <xsl:with-param name="END_PAGE" select="$END_PAGE"/>
                </xsl:call-template>
            </xsl:if>
        </xsl:if>
    </xsl:template>
    <xsl:template name="WriteSearchForm">
        <form name="gs" method="GET" action="#">
            <p class="wrapper">
                <input type="text" name="q" maxlength="256" value="{$QUERY}" class="google-search-keywords"/>
                <select name="site" class="google-search-site">
                    <option value="{$SITE_CATALOG}">
                        <xsl:if test="$SEARCHED_SITE_CATALOG = $SITE_CATALOG">
                            <xsl:attribute name="selected">true</xsl:attribute>
                        </xsl:if>
                        <xsl:value-of select="$SITE_NAME" disable-output-escaping="yes"/>
                    </option>
                    <option value="Yale_University">---------------</option>
                    <option value="YSM_School_of_Medicine">
                        <xsl:if test="$SEARCHED_SITE_CATALOG = 'YSM_School_of_Medicine'">
                            <xsl:attribute name="selected">true</xsl:attribute>
                        </xsl:if>
                        School of Medicine
                    </option>
                    <option value="Yale_Medical_Group">
                        <xsl:if test="$SEARCHED_SITE_CATALOG = 'Yale_Medical_Group'">
                            <xsl:attribute name="selected">true</xsl:attribute>
                        </xsl:if>
                        Yale Medical Group
                    </option>
                    <option value="Yale_New_Haven_Hospital">
                        <xsl:if test="$SEARCHED_SITE_CATALOG = 'Yale_New_Haven_Hospital'">
                            <xsl:attribute name="selected">true</xsl:attribute>
                        </xsl:if>
                        Yale-New Haven Hospital
                    </option>
                    <option value="Medical_Center">
                        <xsl:if test="$SEARCHED_SITE_CATALOG = 'Medical_Center'">
                            <xsl:attribute name="selected">true</xsl:attribute>
                        </xsl:if>
                        Medical Center (all)
                    </option>
                    <option value="Medical_Library">
                        <xsl:if test="$SEARCHED_SITE_CATALOG = 'Medical_Library'">
                            <xsl:attribute name="selected">true</xsl:attribute>
                        </xsl:if>
                        Medical Library
                    </option>
                    <option value="Yale_University">---------------</option>
                    <option value="Yale_Libraries">
                        <xsl:if test="$SEARCHED_SITE_CATALOG = 'Yale_Libraries'">
                            <xsl:attribute name="selected">true</xsl:attribute>
                        </xsl:if>
                        Yale Libraries
                    </option>
                    <option value="Finance_and_Administration">
                        <xsl:if test="$SEARCHED_SITE_CATALOG = 'Finance_and_Administration'">
                            <xsl:attribute name="selected">true</xsl:attribute>
                        </xsl:if>
                        Finance &amp; Admin
                    </option>
                    <option value="Human_Resources">
                        <xsl:if test="$SEARCHED_SITE_CATALOG = 'Human_Resources'">
                            <xsl:attribute name="selected">true</xsl:attribute>
                        </xsl:if>
                        Human Resources
                    </option>
                    <option value="ITS">
                        <xsl:if test="$SEARCHED_SITE_CATALOG = 'ITS'">
                            <xsl:attribute name="selected">true</xsl:attribute>
                        </xsl:if>
                        Information Technology
                    </option>
                    <option value="Yale_University">
                        <xsl:if test="$SEARCHED_SITE_CATALOG = 'Yale_University'">
                            <xsl:attribute name="selected">true</xsl:attribute>
                        </xsl:if>
                        Yale University
                    </option>
                </select>
                <button type="submit" value="submit" class="google-search-button theme-background">
                    <img src="/files/images/button_search_icon_translucent_sm.png" />Google Search
                </button>
            </p>
            <p class="no-space-bottom float-rt" style="margin-right:50px;">
                <a href="http://www.yale.edu/its/web/search/tips.html" class="search-tips">
                    <img src="/files/images/icon_question.gif" alt="" style="vertical-align:middle" />&#160;Search Tips
                </a>
            </p>

            <p class="no-space-bottom gray95">
                Results <span class="green">
                    <xsl:value-of select="/GSP/RES/@SN"/>
                </span> - <span class="green">
                    <xsl:value-of select="/GSP/RES/@EN"/>
                </span> of about <span class="green"><xsl:value-of select="$TOTALNUMBER"/></span> for <strong><xsl:value-of select="$QUERY"/></strong>
            </p>


        </form>
    </xsl:template>
    <xsl:template name="WriteMimeTypeIndicator">
        <xsl:param name="RESULT"/>
        <xsl:choose>
            <xsl:when test="not($RESULT/@MIME)"></xsl:when>
            <xsl:when test="$RESULT/@MIME = 'application/msword'">[DOC] </xsl:when>
            <xsl:when test="$RESULT/@MIME = 'application/octet-stream'">TEST OPTIONS</xsl:when>
            <xsl:when test="$RESULT/@MIME = 'application/pdf'">[PDF] </xsl:when>
            <xsl:otherwise>TODO:<xsl:value-of select="$RESULT/@MIME"/></xsl:otherwise>
        </xsl:choose>


    </xsl:template>
</xsl:stylesheet>
于 2012-06-17T14:39:00.700 回答