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

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

但我搜索任何教程都没有运气,告诉我如何做到这一点,即使教程缺失,或者我认为我没有找到它.

我正在使用ColdFusion 9和MySQL服务器.你能建议我怎么做吗?或者欢迎任何教程,文章或电子书.

解决方法

实际上,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>

相关文章

SELECT a.*,b.dp_name,c.pa_name,fm_name=(CASE WHEN a.fm_n...
if not exists(select name from syscolumns where name=&am...
select a.*,pano=a.pa_no,b.pa_name,f.dp_name,e.fw_state_n...
要在 SQL Server 2019 中设置定时自动重启,可以使用 Window...
您收到的错误消息表明数据库 &#39;EastRiver&#39; 的...
首先我需要查询出需要使用SQL Server Profiler跟踪的数据库标...