Как я могу использовать Verity, чтобы индексировать и искать содержание базы данных в ColdFusion 9?

Я попытался использовать ColdFusion 9 для создания поисковой системы в моем сайте. Ключом является Verity, которую я считал, это - лучший инструмент, чтобы сделать индексацию и поиск в моем содержании базы данных.

Но я ищу вокруг без удачи о любом учебном руководстве, чтобы сказать мне, как к сделанному это, даже учебное руководство отсутствует, или я думаю, что не делаю нашел его.

Я использую ColdFusion 9 с сервером MySQL. Могли Вы совет меня, как сделать это? или любое учебное руководство, статья или электронная книга также приветствуются.

7
задан Peter Boughton 3 June 2010 в 10:35
поделиться

1 ответ

На самом деле, у вас есть два отличных двигателя для CF9: Verity (классический) и Solr (современный).

Оба они реализуют идею коллекций . Создание и поддержка коллекции достаточно очевидна и может быть найдена в руководстве (см. предыдущие ссылки).

Основная подсказка для вас находится на странице руководства тега cfindex: вы можете заполнить (обновить) коллекцию запросом /запросом данных. Установите тип custom, введите имя запроса и все необходимые вам столбцы (комбинации могут отличаться).

Все что вам нужно после этого, это использовать cfsearch.

Также я могу порекомендовать настроить скрипт, выполняемый планировщиком, чтобы периодически обновлять вашу коллекцию.

EDIT

Пример кода (примечание: код не тестировался, просто упрощенный вырез из моего старого компонента). Это два метода 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>
5
ответ дан 7 December 2019 в 12:21
поделиться
Другие вопросы по тегам:

Похожие вопросы: