<commit_before><?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */

/**
 * SolrSearch Omeka Plugin setup file.
 *
 * This file will set up the SolrSearch plugin.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by
 * applicable law or agreed to in writing, software distributed under the
 * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
 * OF ANY KIND, either express or implied. See the License for the specific
 * language governing permissions and limitations under the License.
 *
 * @package    omeka
 * @subpackage SolrSearch
 * @author     "<NAME>"
 * @copyright  2010 The Board and Visitors of the University of Virginia
 * @license    http://www.apache.org/licenses/LICENSE-2.0 Apache 2.0
 * @version    $Id$
 * @link       http://www.scholarslab.org
 *
 * PHP version 5
 *
 */
 
// {{{ constants
define('SOLR_SEARCH_PLUGIN_VERSION', get_plugin_ini('SolrSearch', 'version'));
define('SOLR_SERVER', get_option('solr_search_server'));
define('SOLR_PORT', get_option('solr_search_port'));
define('SOLR_CORE', get_option('solr_search_core'));
define('SOLR_ROWS', get_option('solr_search_rows'));
define('SOLR_FACET_LIMIT', get_option('solr_search_facet_limit'));
// }}}

// Solr PHP Client library
require_once 'lib/Document.php';
require_once 'lib/Response.php';
require_once 'lib/Service.php';

// {{{ pluginHooks
add_plugin_hook('install', 'solr_search_install');
add_plugin_hook('uninstall', 'solr_search_uninstall');
add_plugin_hook('before_delete_item', 'solr_search_before_delete_item');
add_plugin_hook('after_save_item', 'solr_search_after_save_item');
add_plugin_hook('define_routes', 'solr_search_define_routes');
add_plugin_hook('define_acl', 'solr_search_define_acl');
add_plugin_hook('admin_theme_header', 'solr_search_admin_header');
add_plugin_hook('public_theme_header', 'solr_search_public_header');
add_plugin_hook('config_form', 'solr_search_config_form');
add_plugin_hook('config', 'solr_search_config');
//}}}

// {{{ filters
add_filter('admin_navigation_main', 'solr_search_admin_navigation');
// }}}

function solr_search_install()
{
	$db = get_db();
	    
	// create for facet mapping
	$db->exec("CREATE TABLE IF NOT EXISTS `{$db->prefix}solr_search_facets` (
			`id` int(10) unsigned NOT NULL auto_increment,
			`element_id` int(10) unsigned,
			`name` tinytext collate utf8_unicode_ci NOT NULL,	      
			`element_set_id` int(10) unsigned,
			`is_facet` tinyint unsigned,
			`is_displayed` tinyint unsigned,			
			`is_sortable` tinyint unsigned,
	       PRIMARY KEY  (`id`)
	       ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;");
	
	$elements = $db->getTable('Element')->findAll();
	
	//add all element names to facet table for selection
	foreach ($elements as $element){
		$data = array(	'element_id' => $element['id'],
						'name' => $element['name'],
						'element_set_id' => $element['element_set_id'],
						'is_facet' => 0,
						'is_displayed' => 0,
						'is_sortable'=>0);
		$db->insert('solr_search_facets', $data);
	}
	//tag
	$db->insert('solr_search_facets', array('name'=>'tag',
											'is_facet'=>0,
											'is_displayed'=>0,
											'is_sortable'=>0));
	
	//collection
	$db->insert('solr_search_facets', array('name'=>'collection',
											'is_facet'=>0,
											'is_displayed'=>0,
											'is_sortable'=>0));
	
	//item type
	$db->insert('solr_search_facets', array('name'=>'itemtype',
											'is_facet'=>0,
											'is_displayed'=>0,
											'is_sortable'=>0));
	
	//images
	$db->insert('solr_search_facets', array('name'=>'image', 'is_displayed'=>0));
	
	//set solr options
	set_option('solr_search_server', 'localhost');
	set_option('solr_search_port', '8080');
	set_option('solr_search_core', '/solr/');
	set_option('solr_search_rows', '10');
	set_option('solr_search_facet_limit', '25');
	set_option('solr_search_hl', 'false');
	set_option('solr_search_snippets', '1');
	set_option('solr_search_fragsize', '100');
	set_option('solr_search_facet_sort', 'count');
	
	//add public items to Solr index - moved to config form submission
	//ProcessDispatcher::startProcess('SolrSearch_IndexAll', null, $args);
}

function solr_search_uninstall()
{
	// Drop the table.
	$db = get_db();
	$sql = "DROP TABLE IF EXISTS `{$db->prefix}solr_search_facets`";<commit_msg>Refactored data population by using default values<commit_after><?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */

/**
 * SolrSearch Omeka Plugin setup file.
 *
 * This file will set up the SolrSearch plugin.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by
 * applicable law or agreed to in writing, software distributed under the
 * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
 * OF ANY KIND, either express or implied. See the License for the specific
 * language governing permissions and limitations under the License.
 *
 * @package    omeka
 * @subpackage SolrSearch
 * @author     "<NAME>"
 * @copyright  2010 The Board and Visitors of the University of Virginia
 * @license    http://www.apache.org/licenses/LICENSE-2.0 Apache 2.0
 * @version    $Id$
 * @link       http://www.scholarslab.org
 *
 * PHP version 5
 *
 */
 
// {{{ constants
define('SOLR_SEARCH_PLUGIN_VERSION', get_plugin_ini('SolrSearch', 'version'));
define('SOLR_SERVER', get_option('solr_search_server'));
define('SOLR_PORT', get_option('solr_search_port'));
define('SOLR_CORE', get_option('solr_search_core'));
define('SOLR_ROWS', get_option('solr_search_rows'));
define('SOLR_FACET_LIMIT', get_option('solr_search_facet_limit'));
// }}}

// Solr PHP Client library
require_once 'lib/Document.php';
require_once 'lib/Response.php';
require_once 'lib/Service.php';

// {{{ pluginHooks
add_plugin_hook('install', 'solr_search_install');
add_plugin_hook('uninstall', 'solr_search_uninstall');
add_plugin_hook('before_delete_item', 'solr_search_before_delete_item');
add_plugin_hook('after_save_item', 'solr_search_after_save_item');
add_plugin_hook('define_routes', 'solr_search_define_routes');
add_plugin_hook('define_acl', 'solr_search_define_acl');
add_plugin_hook('admin_theme_header', 'solr_search_admin_header');
add_plugin_hook('public_theme_header', 'solr_search_public_header');
add_plugin_hook('config_form', 'solr_search_config_form');
add_plugin_hook('config', 'solr_search_config');
//}}}

// {{{ filters
add_filter('admin_navigation_main', 'solr_search_admin_navigation');
// }}}

/**
 * Install the SolrSearch plugin; set up facet table and autopopulate from
 * items in the database.
 * 
 * @return void
 */
function solr_search_install()
{
	$db = get_db();
	    
	// create for facet mapping
	$db->exec("CREATE TABLE IF NOT EXISTS `{$db->prefix}solr_search_facets` (
        `id` int(10) unsigned NOT NULL auto_increment,
        `element_id` int(10) unsigned,
        `name` tinytext collate utf8_unicode_ci NOT NULL,	      
        `element_set_id` int(10) unsigned,
        `is_facet` tinyint unsigned DEFAULT 0,
        `is_displayed` tinyint unsigned DEFAULT 0,			
        `is_sortable` tinyint unsigned DEFAULT 0,
        PRIMARY KEY  (`id`)
    ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;");
	
	$elements = $db->getTable('Element')->findAll();
	
	// add all the element names to facet table 
	foreach ($elements as $element) {
		
		$data = array(	
		    'element_id' => $element['id'],
            'name' => $element['name'],
            'element_set_id' => $element['element_set_id'],
        );
        
		$db->insert('solr_search_facets', $data);
	}
	
	solr_search_add_facets('tag');
	solr_search_add_facets('collection');
	solr_search_add_facets('itemtype');
	solr_search_add_facets('image');
	
	// add images; special case as it can only be displayed
	//$db->insert('solr_search_facets', array('name'=>'image', 'is_displayed'=>0));
	
	// set solr options for Omeka
	set_option('solr_search_server', 'localhost');
	set_option('solr_search_port', '8080');
	set_option('solr_search_core', '/solr/');
	set_option('solr_search_rows', '10');
	set_option('solr_search_facet_limit', '25');
	set_option('solr_search_hl', 'false');
	set_option('solr_search_snippets', '1');
	set_option('solr_search_fragsize', '100');
	set_option('solr_search_facet_sort', 'count');
	
	//add public items to Solr index - moved to config form submission
	//ProcessDispatcher::startProcess('SolrSearch_IndexAll', null, $args);
}

function solr_search_add_facets($field)
{
    $db = get_db();
    
    $db->insert('solr_search_facets', array('name' => $field));
    
    return;
}

function solr_search_uninstall()
{
	// Drop the table.
	$db = get_db();
	$sql = "DROP TABLE IF EXISTS `{$db->prefix}solr_search_facets`";
{'fraction_non_alphanumeric': 0.1435670900055218, 'fraction_numerical': 0.010049696300386527, 'mean_word_length': 5.001325381047051, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, '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': '851751', 'n_tokens_mistral': 3269, 'n_tokens_neox': 3032, 'n_words': 672}