<commit_before><?php

/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 cc=80; */

/**
 * @package     omeka
 * @subpackage  solr-search
 * @copyright   2012 Rector and Board of Visitors, University of Virginia
 * @license     http://www.apache.org/licenses/LICENSE-2.0.html
 */


class SolrSearch_AdminController
    extends Omeka_Controller_AbstractActionController
{


    /**
     * Display the "Solr Configuration" form.
     */
    public function serverAction()
    {

        $form = new SolrSearch_Form_Server();

        // If a valid form was submitted.
        if ($this->_request->isPost() && $form->isValid($_POST)) {

            // Set the options.
            foreach ($form->getValues() as $option => $value) {
                set_option($option, $value);
            }

        }

        // Are the current parameters valid?
        if (SolrSearch_Helpers_Index::pingSolrServer()) {

            // Notify valid connection.
            $this->_helper->flashMessenger(
                __('Solr connection is valid.'), 'success'
            );

        }

        // Notify invalid connection.
        else $this->_helper->flashMessenger(
            __('Solr connection is invalid.'), 'error'
        );

        $this->view->form = $form;

    }


    /**
     * Display the "Field Configuration" form.
     */
    public function fieldsAction()
    {

        // Get the facet mapping table.
        $facetTable = $this->_helper->db->getTable('SolrSearchField');

        // If the form was submitted.
        if ($this->_request->isPost()) {

            // Gather the POST arguments.
            $post = $this->_request->getPost();

            // Save the facets.
            foreach ($post['facets'] as $name => $data) {

                // Were "Is Indexed?" and "Is Facet?" checked?
                $indexed = array_key_exists('is_indexed', $data) ? 1 : 0;
                $faceted = array_key_exists('is_facet', $data) ? 1 : 0;

                // Load the facet mapping.
                $facet = $facetTable->findByName($name);

                // Apply the updated values.
                $facet->label       = $data['label'];
                $facet->is_indexed  = $indexed;
                $facet->is_facet    = $faceted;
                $facet->save();

            }

            // Flash success.
            $this->_helper->flashMessenger(
                __('Fields successfully updated! Be sure to reindex.'),
                'success'
            );

        }

        // Assign the facet groups.
        $this->view->groups = $facetTable->groupByElementSet();

    }


    /**
     * Display the "Hit Highlighting Options" form.
     */
    public function highlightAction()
    {

        $form = new SolrSearch_Form_Highlight();

        // If a valid form was submitted.
        if ($this->_request->isPost() && $form->isValid($_POST)) {

            // Set the options.
            foreach ($form->getValues() as $option => $value) {
                set_option($option, $value);
            }

            // Flash success.
            $this->_helper->flashMessenger(
                __('Highlighting options successfully saved!'), 'success'
            );

        }	

        $this->view->form = $form;

    }


    /**
     * Display the "Index Items" form.
     */
    public function reindexAction()
    {

        $form = new SolrSearch_Form_Reindex();

        if ($this->_request->isPost()) {
            try {

                // Clear and reindex.
                SolrSearch_Helpers_Index::deleteAll();
                SolrSearch_Helpers_Index::indexAll();

                // Flash success.
                $this->_helper->flashMessenger(
                    __('Reindexing started.'), 'success'<commit_msg>In the reindex controller action, use set_time_limit(0) to make it possible to index really large collections.<commit_after><?php

/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 cc=80; */

/**
 * @package     omeka
 * @subpackage  solr-search
 * @copyright   2012 Rector and Board of Visitors, University of Virginia
 * @license     http://www.apache.org/licenses/LICENSE-2.0.html
 */


class SolrSearch_AdminController
    extends Omeka_Controller_AbstractActionController
{


    /**
     * Display the "Solr Configuration" form.
     */
    public function serverAction()
    {

        $form = new SolrSearch_Form_Server();

        // If a valid form was submitted.
        if ($this->_request->isPost() && $form->isValid($_POST)) {

            // Set the options.
            foreach ($form->getValues() as $option => $value) {
                set_option($option, $value);
            }

        }

        // Are the current parameters valid?
        if (SolrSearch_Helpers_Index::pingSolrServer()) {

            // Notify valid connection.
            $this->_helper->flashMessenger(
                __('Solr connection is valid.'), 'success'
            );

        }

        // Notify invalid connection.
        else $this->_helper->flashMessenger(
            __('Solr connection is invalid.'), 'error'
        );

        $this->view->form = $form;

    }


    /**
     * Display the "Field Configuration" form.
     */
    public function fieldsAction()
    {

        // Get the facet mapping table.
        $facetTable = $this->_helper->db->getTable('SolrSearchField');

        // If the form was submitted.
        if ($this->_request->isPost()) {

            // Gather the POST arguments.
            $post = $this->_request->getPost();

            // Save the facets.
            foreach ($post['facets'] as $name => $data) {

                // Were "Is Indexed?" and "Is Facet?" checked?
                $indexed = array_key_exists('is_indexed', $data) ? 1 : 0;
                $faceted = array_key_exists('is_facet', $data) ? 1 : 0;

                // Load the facet mapping.
                $facet = $facetTable->findByName($name);

                // Apply the updated values.
                $facet->label       = $data['label'];
                $facet->is_indexed  = $indexed;
                $facet->is_facet    = $faceted;
                $facet->save();

            }

            // Flash success.
            $this->_helper->flashMessenger(
                __('Fields successfully updated! Be sure to reindex.'),
                'success'
            );

        }

        // Assign the facet groups.
        $this->view->groups = $facetTable->groupByElementSet();

    }


    /**
     * Display the "Hit Highlighting Options" form.
     */
    public function highlightAction()
    {

        $form = new SolrSearch_Form_Highlight();

        // If a valid form was submitted.
        if ($this->_request->isPost() && $form->isValid($_POST)) {

            // Set the options.
            foreach ($form->getValues() as $option => $value) {
                set_option($option, $value);
            }

            // Flash success.
            $this->_helper->flashMessenger(
                __('Highlighting options successfully saved!'), 'success'
            );

        }	

        $this->view->form = $form;

    }


    /**
     * Display the "Index Items" form.
     */
    public function reindexAction()
    {

        // Since we can't reindex in a background process because Omeka is
        // unable to form record URLs for the Solr documents outside of a web
        // container, allow this request to run indefinitely, which makes it
        // possible to index sites with many tens of thousands of documents,
        // which otherwise would exceed the default 30-second limit.
        set_time_limit(0); // ** facepalm **

        $form = new SolrSearch_Form_Reindex();

        if ($this->_request->isPost()) {
            try {

                // Clear and reindex.
                SolrSearch_Helpers_Index::deleteAll();
                SolrSearch_Helpers_Index::indexAll();

                // Flash success.
                $this->_helper->flashMessenger(
                    __('Reindexing started.'), 'success'
{'fraction_non_alphanumeric': 0.12492246619526114, 'fraction_numerical': 0.004217838977794318, 'mean_word_length': 1.6528463310299442, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 87, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6414827', 'n_tokens_mistral': 2299, 'n_tokens_neox': 2129, 'n_words': 547}