Example #1
0
    /**
     * Obtain the query needed to obtain our file listing via webservices
     * NOTE: This is currently implemented as a Lucene query
     *
     * @param string $search_text The search text entered, which contains tokens
     *                            representing either file name or file content
     * @param int $categories An array of category ids to filter on (i.e. results
     *                        must be in one or more to be included), or NULL to not filter
     *                        by category
     * @return string The complete search query
     */
    private function get_search_query($search_text, $categories = NULL) {
        global $DB;

        $query_fragments = array();

        // The text-based search component
        if ($search_text != '') {
            $text_query_tokens = array();

            // Valid as long as the file a name or contents match one text token
            $tokens = explode(' ', $search_text);
            foreach ($tokens as $token) {
                $text_query_tokens[] = '@cm\:name:"*'.$token.'*"';
                $text_query_tokens[] = 'TEXT:\"'.$token.'\"';
            }

            $query_fragments[] = implode(' OR ', $text_query_tokens);
        }

        // The category-based search component
        if (is_array($categories)) {
            $category_query_tokens = array();

            // Valid as long as the file is in at least one of the categories
            foreach ($categories as $category) {
                //TODO: search based on UUID rather than title
                // current side-effect is that duplicate titles will be matched
                if ($categorytitle = $DB->get_field('repository_elisfiles_cats', 'title', array('id' => $category))) {
                    $cattitle = elis_files_ISO_9075_map($categorytitle);
                    $category_query_tokens[] = 'PATH:"/cm:generalclassifiable//cm:'.$cattitle.'//member"';
                }
            }

            $query_fragments[] = implode(' OR ', $category_query_tokens);
        }

        // File must satisfy both the text-based and category-based conditions
        $query = '('.implode(') AND (', $query_fragments).')';

        return $query;
    }
Example #2
0
/**
 * Perform a search for all content within a specific category.
 *
 * @param array $categories An array of category database records.
 * @return object An object containing an array of folders and file node references.
 */
function elis_files_category_search($categories) {
    $return   = new stdClass;
    $return->folders = array();
    $return->files   = array();

    $nodes = array();

    foreach ($categories as $category) {
        $cattitle = elis_files_ISO_9075_map($category->title);
        $response = elis_files_utils_invoke_service('/moodle/categorysearch/' . $cattitle);

        $sxml = RLsimpleXMLelement($response);
        if (empty($sxml)) {
            return false;
        }

        foreach ($sxml->node as $node) {
            if (!isset($nodes["$node->uuid"])) {
                $nodes["$node->uuid"] = "$node->title";
            }
        }
    }

    if (!empty($nodes)) {
        foreach ($nodes as $uuid => $title) {
            $node = elis_files_node_properties($uuid);
            $type = elis_files_get_type($node->uuid);

            if ($type == ELIS_files::$type_folder) {
                $return->folders[] = $node;
            } else if ($type == ELIS_files::$type_document) {
                $return->files[] = $node;
            }
        }
    }

    return $return;
}