gpt4 book ai didi

search - 如何使用 Verity 在 ColdFusion 9 中索引和搜索数据库内容?

转载 作者:行者123 更新时间:2023-12-04 12:25:42 25 4
gpt4 key购买 nike

我曾尝试使用 ColdFusion 9 在我的网站中构建搜索引擎。关键是 Verity,我读到它是在我的数据库内容中进行索引和搜索的最佳工具。

但是我四处搜索,没有任何教程告诉我如何做到这一点,甚至缺少教程,或者我想我没有找到它。

我在 MySQL 服务器上使用 ColdFusion 9。你能建议我怎么做吗?也欢迎任何教程、文章或电子书。

最佳答案

实际上,您有两个很棒的 CF9 引擎:Verity (经典)和 Solr (现代的)。

它们都实现了集合的思想。集合的创建和维护非常明显,可以在手册中找到(参见前面的链接)。

您可以在 cfindex 上找到主要提示。标签手册页:您可以使用查询数据填充(更新)集合。设置类型自定义,输入查询名称和您需要的所有列(组合可能会有所不同)。

之后您只需要使用 cfsearch .

此外,我可以建议设置由调度程序执行的脚本以定期刷新您的集合。

编辑

示例代码( 注: 代码未经测试,只是我旧组件的简化版)。这是 CFC 的两种方法。

<cffunction name="index" access="public" returntype="any" output="true" hint="Rebuild search index">
<cfargument name="collection" type="string" required="true" hint="Target collection name">
<cfset var local = {} />
<cftry>


<!--- pull the content --->
<cfquery datasource="#variables.dsn#" name="local.getContent">
SELECT C.id, C.title, C.content, P.name AS page
FROM #variables.tableContent# C
INNER JOIN #variables.tablePages# P
ON C.id_page = P.id
</cfquery>


<!--- update collection --->
<cflock name="cfindex_lock" type="exclusive" timeout="30">

<cfindex collection="#arguments.collection#"
action="refresh"
type="custom"
query="local.getContent"
key="id"
custom1="page"
title="title"
body="title,content"
>

</cflock>

<cfreturn true />

<cfcatch type="any">
<!--- custom error handler here --->
<cfreturn false />
</cfcatch>
</cftry>
</cffunction>



<cffunction name="search" access="public" returntype="any" output="true" hint="Perform search through the collection">
<cfargument name="collection" type="string" required="true" hint="Target collection name">
<cfargument name="type" type="string" required="true" hint="Search type">
<cfargument name="criteria" type="string" required="true" hint="Search criteria">
<cfargument name="startrow" type="numeric" required="false" default="1" hint="Select offset">
<cfargument name="maxrows" type="numeric" required="false" default="50" hint="Select items count">
<cfset var local = {} />
<cftry>

<!--- pull the data from collection --->
<cfsearch collection="#arguments.collection#"
name="local.searchResults"
type="#arguments.type#"
criteria="#LCase(arguments.criteria)#"
startrow="#arguments.startrow#"
maxrows="#arguments.maxrows#"
>


<cfset local.resultsArray = [] />

<!--- convert data into the array --->
<cfloop query="local.searchResults">
<cfscript>
local.res = StructNew();
local.res["id"] = local.searchResults.key;
local.res["summary"] = Left(local.searchResults.summary, 500) & "...";
// highlight the search phrase
local.res["summary"] = ReplaceNoCase(local.res["summary"], arguments.criteria, "<strong>" & arguments.criteria & "</strong>", "ALL");
local.res["page"] = local.searchResults.custom1;
local.res["title"] = local.searchResults.title;
ArrayAppend(local.resultsArray, local.res);
</cfscript>
</cfloop>

<cfreturn local.resultsArray />

<cfcatch type="any">
<!--- custom error handler here --->
<cfreturn false />
</cfcatch>
</cftry>
</cffunction>

关于search - 如何使用 Verity 在 ColdFusion 9 中索引和搜索数据库内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1998468/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com