callback::search::datasource::impl::forums_message (private)

 callback::search::datasource::impl::forums_message

Defined in packages/forums/tcl/forums-callback-procs.tcl

Author:
dave@thedesignexperience.org
Created:
2005-06-07 Returns a datasource for the search package this is the content that will be indexed by the full text search engine. We expect message_id to be a root message of a thread only, and return the text of all the messages below.
See Also:

Partial Call Graph (max 5 caller/called nodes):
%3 ad_conn ad_conn (public) ad_html_text_convert ad_html_text_convert (public) db_foreach db_foreach (public) forum::get forum::get (public) forum::message::get forum::message::get (public) callback::search::datasource::impl::forums_message callback::search::datasource::impl::forums_message callback::search::datasource::impl::forums_message->ad_conn callback::search::datasource::impl::forums_message->ad_html_text_convert callback::search::datasource::impl::forums_message->db_foreach callback::search::datasource::impl::forums_message->forum::get callback::search::datasource::impl::forums_message->forum::message::get

Testcases:
No testcase defined.
Source code:
    ::callback::search::datasource::contract__arg_parser {*}$args

    set message_id $object_id
    # If there is no connection than this proc is called from the
    # search indexer. In that case we set the locale to the
    # system-wide default locale, since locale is needed for some part
    # of the message formatting.
    if { ![ns_conn isconnected] } {
        ad_conn -set locale [lang::system::site_wide_locale]
    }

    forum::message::get -message_id $message_id -array message

    if { $message(parent_id) ne "" } {
        ns_log debug "forum::message::datasource was called with a message_id that has a parent - skipping: $message_id"
        set empty(object_id) $message_id
        set empty(title) ""
        set empty(content) ""
        set empty(keywords) ""
        set empty(storage_type) "text"
        set empty(mime) "text/plain"
        return [array get empty]
    }
    set relevant_date $message(posting_date)

    set tree_sortkey $message(tree_sortkey)
    set forum_id $message(forum_id)
    set combined_content ""

    array set forum [forum::get -forum_id $message(forum_id) -array forum]
    set package_id $forum(package_id)

    # We only render the content of approved messages.
    db_foreach messages {
        with recursive thread(message_id, parent_id, subject, content, format) as (
            select message_id, parent_id, subject, content, format
            from forums_messages
            where message_id = :message_id
              and state = 'approved'

            union all

            select m.message_id, m.parent_id, m.subject, m.content, m.format
            from forums_messages m,
                 thread t
            where m.parent_id = t.message_id
              and m.state = 'approved'
        ) select subject, content, format from thread
    } {

        # include the subject in the text if it is different from the thread's subject
        set root_subject $message(subject)
        regexp {^(?:Re: )+(.*)$} $subject match subject

        if { $subject ne $root_subject  } {
            # different subject
            append combined_content "$subject\n\n"
        }

        #
        # GN: The standard conversion from "text/enhanced" to
        # "text/plain" converts first from "text/enhanced" to
        # "text/html" and then from "text/html" to "text/plain". This
        # can take for large forums posting a long time (e.g. a few
        # minutes on openacs.org). Since this function is used just
        # for the summarizer (when listing a short paragraph in the
        # context of the search result), we can live here with a much
        # simpler version, which computes the same in less than one
        # ms.
        #
        if {$message(format) eq "text/enhanced"} {
            regsub -all -- {<p>} $content "\n\n" content
            regsub -all -- {(<?/[^>]*>)} $content "" content
        } else {
            set content [ad_html_text_convert -from $format -to text/plain -- $content]
        }
        append combined_content $content

        # In case this text is not only used for indexing but also for display, beautify it
        append combined_content "\n\n"
        set relevant_date $message(posting_date)
    }

    return [list object_id $message(message_id)  title $message(subject)  content $combined_content  relevant_date $relevant_date  community_id ""  keywords {}  storage_type text  mime text/plain  package_id $package_id]
XQL Not present:
PostgreSQL, Oracle
Generic XQL file:
packages/forums/tcl/forums-callback-procs.xql

[ hide source ] | [ make this the default ]
Show another procedure: