【问题标题】:How can I use Verity to index and search database content in ColdFusion 9?如何使用 Verity 在 ColdFusion 9 中索引和搜索数据库内容?
【发布时间】:2011-01-01 04:36:35
【问题描述】:

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

但是我四处寻找没有运气的教程来告诉我如何做到这一点,甚至缺少教程,或者我认为我没有找到它。

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

【问题讨论】:

    标签: search coldfusion solr verity cfsearch


    【解决方案1】:

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

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

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

    之后你只需要使用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>
    

    【讨论】:

    • 谢谢!谢尔盖!你给我指路了!但是你能指导我更多关于剧本的信息吗?我可以在 Coldfusion 服务器中完成吗?使用 CFM 还是 CFC?我找到了 vSpider,但我想知道它应该是更简单的方法。
    • 您可以使用 cfcollection 标签管理收藏。您可以将 cfindex 和 cfsearch 包装到 CFC 方法中(推荐方式)。每个标签用法的示例都在手册中,您有链接。
    • 如果您需要索引超过 250,000 个文档/记录,请远离 Verity。它的 CF OEM 许可证限制为 250k 文档。 SOLR 确实是要走的路。
    • 谢谢你们,先生们。
    • Verity 还有其他非常有趣的怪癖。如果可以的话,尽量使用 Solr,如果您从头开始构建集合,那么差异对您来说应该不大。
    猜你喜欢
    • 1970-01-01
    • 2017-05-27
    • 2010-12-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-03
    • 1970-01-01
    • 2014-04-14
    相关资源
    最近更新 更多