仿“文章高级搜索”标签在主页中搜索自定义内容模型中的字段

(感谢小贝的两次细致操作,为防止还有第四次,做了如下笔记,望共享!)

首先添加你所需要的内容模型(字段名随便定义)。

下面就是相关文件的修改:

1.在主页搜索的相应位置添加一段JS代码(这是应引用ArticleSearchForm1.js的相关内容,这个页面是根据ArticleSearchForm.js复制修改得来的

 <script type="text/javascript" src="{PE.SiteConfig.ApplicationPath/}{PE.SiteConfig.IncludeFilePath/}/ArticleSearchForm1.js"></script>

2.修改ArticleSearchForm1.js中的内容(这个页面就是我们所要搜索的选项了)

对比两个JS可知,这里我定义了三个选框,然后提交相关搜索数据。

重点说明的是倒数第二句话:

document.write("window.location = \"/mjzz/search.aspx?searchtype=2&showtype=1&ModelId=103&nodeId=19&intro=\" + escape(adress) + \"&source=\" + escape(diqu) + \"&author=\" + escape(xiangxileixing)  ;\r\n  ") 

这里的searchtype=2&showtype=1 会找到我接下来要说的自定义搜索标签和自定义搜索显示页面,为什么会这样呢?我没想明白。

ModelId=103&nodeId=19 这个就不解释了。

&intro=\" + escape(adress) 这里的intro对应自定义搜索标签增加的参数 address 就是select里面的id咯。

3.这是关键的一步——自定义搜索标签,这个标签是仿照“文章高级搜索”做的。

标签名称分类随便,数据设置:系统数据库SQL查询;参数的话,前面六个好像是必须得,后面几个就是我们需要自定搜索的了。需要几个就加几个。名称要和文章高级搜索一样,不一样好像会出问题哦。

SQL语句一样就行了。

接下来,标签内容有几个地方需要修改:

  (1)PE_U_Article 改成你自定义内容模型的表名,比如我的是PE_U_Unit

  (2)这里有几组内容需要修改,简而言之 都是将文章内容模型里的字段名改成自定义的字段名。好像一共有三组要改。要注意一一对应,比如下面那个,Own_Area对应intro,就要一直这样对应

<xsl:if test="$intro != ''">

   AND UT.Own_Area LIKE '%<xsl:value-of select="$intro"/>%'

  </xsl:if>

4。终于快完了,这一步就是你的自定义显示页面了。主要就是下面这句话了。

{PE.Label id="自定义搜索" titleLength="60" contentLength="0" outputQty="20" parentId="19"   bindStyle="普通式"   intro="@Request_intro" source="@Request_source" /}

具体怎么做的呢,参照:文章高级搜索页模板.html

不明白的看看代码,对比一下

ArticleSearchForm1.js

document.write("<div id=\"main_search\">\r\n <select name=\"adress\" id=\"adress\" size=\"1\">")

document.write("<option value=\"\">请选择地区</option>")

document.write("<option value=\"常德市市本级社会组织\">常德市市本级社会组织</option>")

document.write("<option value=\"武陵区\">武陵区</option>")

document.write("<option value=\"鼎城区\">鼎城区</option>")

document.write("<option value=\"桃源县\">桃源县</option>")

document.write("<option value=\"桃源县\">桃源县</option>")

document.write("<option value=\"汉寿县\">汉寿县</option>")

document.write("<option value=\"临澧县\">临澧县</option>")

document.write("<option value=\"石门县\">石门县</option>")

document.write("<option value=\"澧县\">澧县</option>")

document.write("<option value=\"津市市\">津市市</option>")

document.write("<option value=\"德山开发区\">德山开发区</option>")

document.write("<option value=\"西湖管理区\">西湖管理区</option>")

document.write("<option value=\"柳叶湖旅游区\">柳叶湖旅游区</option>")

document.write("<option value=\"西洞庭管理区\">西洞庭管理区</option></select>\r")

document.write("<select name=\"diqu\" id=\"diqu\" size=\"1\">")

document.write("<option value=\"\">请选择社会组织类别</option>")

document.write("<option value=\"社会团体\">社会团体</option>")

document.write("<option value=\"民办非企业单位\">民办非企业单位</option>")

document.write("<option value=\"基金会\">基金会</option>")

document.write("<option value=\"境外基金会代表机构\">境外基金会代表机构</option></select>\r  ")

document.write("<select name=\"xiangxileixing\" id=\"xiangxileixing\" size=\"1\">")

document.write("<option value=\"\">请选择社会详细分类</option>")

document.write("<option value=\"经济类\">经济类</option>")

document.write("<option value=\"科学研究类\">科学研究类</option>")

document.write("<option value=\"社会事业类\">社会事业类</option>")

document.write("<option value=\"综合类\">综合类</option>")

document.write("<option value=\"慈善类\">慈善类</option></select>\r  ")

document.write("<input id=\"Submit\" style=\"margin:0 0 0 5px;border: 0px; width: 65px; height: 21px;\" type=\"image\" src=\"/mjzz/Skin/OceanStar/Images/search_b.gif\" name=\"Submit\" onclick=\"OnSearchCheckAndSubmit();\" />\r\n ")

document.write("<script language=\"javascript\" type=\"text/javascript\">\r\n \r\n")

document.write(" function OnSearchCheckAndSubmit() {\r\n  ")

document.write("var adressSel=document.getElementById(\"adress\");\r\n")

document.write("var adress=adressSel.options[adressSel.options.selectedIndex].value;\r\n")

document.write("var diquSel=document.getElementById(\"diqu\");\r\n")

document.write("var diqu=diquSel.options[diquSel.options.selectedIndex].value;\r\n")

document.write("window.location = \"/mjzz/search.aspx?searchtype=2&showtype=1&ModelId=103&nodeId=19&intro=\" + escape(adress) + \"&source=\" + escape(diqu) + \"&author=\" + escape(xiangxileixing)  ;\r\n  ")

document.write("}\r\n  </script>\r\n </div>")

自定义标签内容代码:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ms="urn:schemas-microsoft-com:xslt" xmlns:lewi="http://www.powereasy.net" xmlns:pe="labelproc" exclude-result-prefixes="pe ms lewi">
 <xsl:output method="html" version="1.0" encoding="UTF-8" indent="yes"/>
 <xsl:param name="titleLength" />
 <xsl:param name="contentLength" />
 <xsl:param name="linkOpenType" />
 <xsl:param name="bindStyle" />
 <xsl:param name="outputQty" />
 <xsl:param name="parentId" />
 <xsl:param name="intro" />
 <xsl:param name="source" />
 <xsl:param name="author" />
 <xsl:param name="oEA" />
 <xsl:param name="oEB" />
 <xsl:param name="oEC" />
 <xsl:param name="oED" />
 <xsl:param name="oEE" />
 <xsl:param name="oEF" />
 <xsl:template match="/">
  {PE.Label id="文章高级搜索_<xsl:value-of select="$bindStyle"/>" oEA="<xsl:value-of select="$oEA"/>" oEB="<xsl:value-of select="$oEB"/>" oEC="<xsl:value-of select="$oEC"/>" oED="<xsl:value-of select="$oED"/>" oEE="<xsl:value-of select="$oEE"/>" oEF="<xsl:value-of select="$oEF"/>" titleLength="<xsl:value-of select="$titleLength"/>" contentLength="<xsl:value-of select="$contentLength"/>" linkOpenType="<xsl:value-of select="$linkOpenType"/>" queryCond="SELECT TOP @pagesize *
  FROM PE_CommonModel CM
  INNER JOIN PE_U_Unit UT ON (CM.ItemID=UT.ID)
  WHERE CM.Status = 99 AND CM.SigninType!=2 AND CM.NodeID IN(<xsl:value-of select="/NewDataSet/Table/arrChildID" />)
  <xsl:if test="$intro != ''">
   AND UT.Own_Area LIKE '%<xsl:value-of select="$intro"/>%'
  </xsl:if>
  <xsl:if test="$source !=''">
   AND UT.Sort LIKE '%<xsl:value-of select="$source"/>%'
  </xsl:if>
  <xsl:if test="$author !=''">
   AND UT.detail LIKE '%<xsl:value-of select="$author"/>%'
  </xsl:if>
  AND CM.GeneralID NOT IN (
  SELECT TOP @startrow ICM.GeneralID
  FROM PE_CommonModel ICM
  INNER JOIN PE_U_Unit IUT ON (ICM.ItemID=IUT.ID)
  WHERE ICM.Status = 99 AND ICM.SigninType!=2 AND ICM.NodeID IN(<xsl:value-of select="/NewDataSet/Table/arrChildID" />)
  <xsl:if test="$intro != ''">
   AND IUT.Own_Area LIKE '%<xsl:value-of select="$intro"/>%'
  </xsl:if>
  <xsl:if test="$source !=''">
   AND IUT.Sort LIKE '%<xsl:value-of select="$source"/>%'
  </xsl:if>
  <xsl:if test="$author !=''">
   AND UT.detail LIKE '%<xsl:value-of select="$author"/>%'
  </xsl:if>
  ORDER BY ICM.UpdateTime DESC)
  ORDER BY CM.UpdateTime DESC" queryCount="SELECT COUNT (ICM.GeneralID)
  FROM PE_CommonModel ICM
  INNER JOIN PE_U_Unit IUT ON (ICM.ItemID=IUT.ID)
  WHERE ICM.Status = 99 AND ICM.SigninType!=2 AND ICM.NodeID IN(<xsl:value-of select="/NewDataSet/Table/arrChildID" />)
  <xsl:if test="$source !=''">
   AND IUT.Sort LIKE '%<xsl:value-of select="$source"/>%'
  </xsl:if>
  <xsl:if test="$author !=''">
   AND UT.detail LIKE '%<xsl:value-of select="$author"/>%'
  </xsl:if>
  <xsl:if test="$intro !=''">
   AND IUT.Own_Area LIKE '%<xsl:value-of select="$intro"/>%'
  </xsl:if>" page="true" pagesize="<xsl:value-of select="$outputQty"/>" urlpage="true" /}
 </xsl:template>
</xsl:stylesheet>
posted @ 2011-08-23 17:04  happysha  阅读(537)  评论(0编辑  收藏  举报