在Verity结果集中优先考虑CF_TITLE
问题描述:
我有一个客户的请求,他希望能够在搜索结果中优先考虑他们的产品SKU。 SKU在定义的键CF_TITLE中。我的表现不太好,文档也不是很好。我设法修改它以仅查找CF_TITLE,但它影响了其余的结果。我也不确定当前的标准是否正确,因为它没有真正遵循我发现的任何示例语法。在Verity结果集中优先考虑CF_TITLE
那么如何修改标准,以便我们可以在结果中优先匹配“CF_TITLE”,而不会影响其他结果?
这是他们目前的搜索标签:
<cfsearch
collection="company"
name="SearchResults"
criteria="(<NOT> CF_KEY <MATCHES> #SearchKeywords#)
AND (#SearchKeywords#)"
status="Info">
答
由于Verity的决定主要是基于的标准出现的次数相关,以“优先考虑”的结果的一种方式是将SKU多次人为地附加到索引集合时的“正文”。
您可以在原始SQL查询中执行此操作,也可以使用ColdFusion在将结果集传递给Verity之前使用SKU对结果集进行填充。下面是后一种选择的例子:
<!--- Get the product data--->
<cfquery name="qProducts" datasource="blog">
SELECT
ID
,SKU
,title
,description
FROM
products
</cfquery>
<!--- Massage the data to prioritise the SKU by creating a new query from the original --->
<cfset qProductsForIndex = QueryNew("ID,title,body","Integer,VarChar,VarChar")>
<cfloop query="qProducts">
<cfset QueryAddRow(qProductsForIndex)>
<cfset QuerySetCell(qProductsForIndex,"ID",qProducts.ID)>
<cfset QuerySetCell(qProductsForIndex,"title",qProducts.title)>
<!--- Add the SKU 5 times, separated by a semi-colon --->
<cfset QuerySetCell(qProductsForIndex,"body",qProducts.description & ";" & RepeatString(qProducts.SKU & ";",5))>
</cfloop>
<!--- Pass the massaged query to Verity --->
<cfindex action="REFRESH"
collection="products"
type="CUSTOM"
query="qProductsForIndex"
key="ID"
title="title"
body="body">
注意分号分隔额外的SKU,这确保Verity的将匹配它们作为独立出现。
我已经使用了5作为示例编号,但您可以从2开始并向上调整,直到看到所需的结果为止。
答
SKU是否具有可预测的格式?如果是这样,那么如果检测到SKU,则可以更改传递给验证码的标准格式。例如,如果你的SKU都开始用3个字母后跟3个数字:
<cfscript>
// forced example; replace this with actual keywords from the search form
searchKeyWords = "ABC123";
// RegEx to detect SKUs according to their format
if(REFind("^\w{3,3}\d{3,3}$",searchKeyWords))
request.criteria = "CF_TITLE <CONTAINS> #searchKeyWords#";
else
request.criteria = searchKeyWords;
</cfscript>
<cfsearch
collection="company"
name="SearchResults"
criteria="#request.criteria#">
所以如果一个SKU检测真理会仅搜索标题字段。否则,它会对整个索引进行正常搜索。您可能需要根据事情需要匹配的严格程度来变更上述内容,但您明白了。
我会尝试一下,但我希望在标准的解决方案,而不是操作索引。我已阅读文档[http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=Tags_r-s_13.html],但我很难找到我需要做的事情那里。 – cjohansson 2011-05-06 08:40:10