Skip to content

Commit

Permalink
Merge branch 'release/2.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric Rochester committed Jan 27, 2015
2 parents 9fdb60f + ac214d8 commit ca18d91
Show file tree
Hide file tree
Showing 15 changed files with 151 additions and 46 deletions.
5 changes: 4 additions & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,10 @@ module.exports = function(grunt) {
'!pkg/**',

// TESTS
'!tests/**'
'!tests/**',

// Editor settings
'!*.vim'

]
}
Expand Down
29 changes: 11 additions & 18 deletions SolrSearchPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ public function hookUninstall()
$this->_db->query(<<<SQL
DROP TABLE IF EXISTS {$this->_db->prefix}solr_search_fields
SQL
);
);
$this->_db->query(<<<SQL
DROP TABLE IF EXISTS {$this->_db->prefix}solr_search_excludes
SQL
);
);

try {
$solr = SolrSearch_Helpers_Index::connect();
Expand Down Expand Up @@ -189,20 +189,11 @@ public function hookAfterSaveItem($args)

$solr = SolrSearch_Helpers_Index::connect();

// If the item is public, add/update the Solr document.
if ($item['public'] == true) {
$doc = SolrSearch_Helpers_Index::itemToDocument($item);
$solr->addDocuments(array($doc));
$solr->commit();
$solr->optimize();
}

// If the item's is being set private, remove it from Solr.
else {
$solr->deleteById('Item_' . $item['id']);
$solr->commit();
$solr->optimize();
}
// Both public and private items will be indexed
$doc = SolrSearch_Helpers_Index::itemToDocument($item);
$solr->addDocuments(array($doc));
$solr->commit();
$solr->optimize();

}

Expand Down Expand Up @@ -323,7 +314,7 @@ protected function _createSolrTables()
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
SQL
);
);

$this->_db->query(<<<SQL
CREATE TABLE IF NOT EXISTS {$this->_db->prefix}solr_search_excludes (
Expand All @@ -332,7 +323,7 @@ protected function _createSolrTables()
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
SQL
);
);
}


Expand Down Expand Up @@ -395,6 +386,7 @@ protected function _setOptions()
set_option('solr_search_hl', '1');
set_option('solr_search_hl_snippets', '1');
set_option('solr_search_hl_fragsize', '250');
set_option('solr_search_display_private_items', '1');
}


Expand All @@ -411,6 +403,7 @@ protected function _clearOptions()
delete_option('solr_search_hl');
delete_option('solr_search_hl_snippets');
delete_option('solr_search_hl_fragsize');
delete_option('solr_search_display_private_items');
}


Expand Down
30 changes: 26 additions & 4 deletions controllers/ResultsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,25 @@ public function indexAction()
$page = $this->_request->page ? $this->_request->page : 1;
$start = ($page-1) * $limit;


// determine whether to display private items or not
// items will only be displayed if:
// solr_search_display_private_items has been enabled in the Solr Search admin panel
// user is logged in
// user_role has sufficient permissions

$user = current_user();
if(get_option('solr_search_display_private_items')
&& $user
&& is_allowed('Items','showNotPublic')) {
// limit to public items
$limitToPublicItems = false;
} else {
$limitToPublicItems = true;
}

// Execute the query.
$results = $this->_search($start, $limit);
$results = $this->_search($start, $limit, $limitToPublicItems);

// Set the pagination.
Zend_Registry::set('pagination', array(
Expand All @@ -67,7 +84,7 @@ public function indexAction()
* @param int $limit Limit per page
* @return SolrResultDoc Solr results
*/
protected function _search($offset, $limit)
protected function _search($offset, $limit, $limitToPublicItems = true)
{

// Connect to Solr.
Expand All @@ -77,7 +94,7 @@ protected function _search($offset, $limit)
$params = $this->_getParameters();

// Construct the query.
$query = $this->_getQuery();
$query = $this->_getQuery($limitToPublicItems);

// Execute the query.
return $solr->search($query, $offset, $limit, $params);
Expand All @@ -90,7 +107,7 @@ protected function _search($offset, $limit)
*
* @return string The Solr query.
*/
protected function _getQuery()
protected function _getQuery($limitToPublicItems = true)
{

// Get the `q` GET parameter.
Expand All @@ -106,6 +123,11 @@ protected function _getQuery()
// Form the composite Solr query.
if (!empty($facet)) $query .= " AND {$facet}";

// Limit the query to public items if required
if($limitToPublicItems) {
$query .= ' AND public:"true"';
}

return $query;

}
Expand Down
11 changes: 10 additions & 1 deletion forms/SolrSearch_Form_Results.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,14 @@ public function init()
)
));

// Display Private Items:
$this->addElement('checkbox', 'solr_search_display_private_items', array(
'label' => __('Display private items'),
'description' => __('Display private items for all user roles with sufficient permission to view them.'),
'value' => get_option('solr_search_display_private_items')
));


// Submit:
$this->addElement('submit', 'submit', array(
'label' => __('Save Settings')
Expand All @@ -99,7 +107,8 @@ public function init()
'solr_search_hl_snippets',
'solr_search_hl_fragsize',
'solr_search_facet_sort',
'solr_search_facet_limit'
'solr_search_facet_limit',
'solr_search_display_private_items'
), 'fields');

$this->addDisplayGroup(array(
Expand Down
2 changes: 1 addition & 1 deletion helpers/SolrSearch_Helpers_Facet.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public static function makeUrl($facets)
}

// Implode on ` AND `.
$fParam = implode(' AND ', $fParam);
$fParam = urlencode(implode(' AND ', $fParam));

// Get the `q` parameter, reverting to ''.
$qParam = array_key_exists('q', $_GET) ? $_GET['q'] : '';
Expand Down
7 changes: 6 additions & 1 deletion helpers/SolrSearch_Helpers_Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ public static function itemToDocument($item)
$doc->setField('model', 'Item');
$doc->setField('modelid', $item->id);

// extend $doc to to include and items public / private status
$doc->setField('public', $item->public);

// Title:
$title = metadata($item, array('Dublin Core', 'Title'));
$doc->setField('title', $title);
Expand Down Expand Up @@ -222,7 +225,9 @@ public static function indexAll($options=array())
$table = $db->getTable('Item');
$select = $table->getSelect();

$table->filterByPublic($select, true);
// Removed in order to index both public and private items
// $table->filterByPublic($select, true);

$table->applySorting($select, 'id', 'ASC');

$excTable = $db->getTable('SolrSearchExclude');
Expand Down
4 changes: 4 additions & 0 deletions lib/SolrSearch/Addon/Indexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ public function indexRecord($record, $addon)
$doc->addField('model', $addon->table);
$doc->addField('modelid', $record->id);

// extend $doc to include public / private records
// not sure if required
//$doc->addField('public', $record->public);

$titleField = $addon->getTitleField();
foreach ($addon->fields as $field) {
$solrName = $this->makeSolrName($addon, $field->name);
Expand Down
17 changes: 16 additions & 1 deletion lib/SolrSearch/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class SolrSearch_Utils
* This tests whether the view is available or not.
*
* @return Omeka_View
* @author Eric Rochester
* @author Eric Rochester <erochest@virginia.edu>
**/
public static function ensureView()
{
Expand All @@ -30,5 +30,20 @@ public static function ensureView()
return Zend_Registry::get('view');
}

/**
* This creates an `li` element for the navigation list. Primarily, it adds
* the `current` class for the link to the current page.
*
* @return void
* @author Eric Rochester <erochest@virginia.edu>
**/
public static function nav_li($tab, $key, $url, $label)
{
echo "<li";
if ($tab == $key) {
echo " class='current'";
}
echo "><a href='$url'>$label</a></li>\n";
}

}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "SolrSearch",
"version": "2.1.1",
"version": "2.2.0",
"devDependencies" : {
"grunt": ">= 0.4.0"
, "grunt-contrib-concat": ">= 0.1.3"
Expand Down
2 changes: 1 addition & 1 deletion plugin.ini
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ support_link="https://github.com/scholarslab/SolrSearch/issues"
omeka_minimum_version="2.0"
omeka_tested_up_to="2.1"
omeka_target_version="2.1"
version="2.1.1"
version="2.2.0"
tags="solr, search"
license="Apache 2.0"
1 change: 1 addition & 0 deletions solr-core/omeka/conf/schema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
<field name="title" type="text_en" indexed="true" stored="true" multiValued="true" />
<field name="tag" type="string" indexed="true" stored="true" multiValued="true" />
<field name="collection" type="string" indexed="true" stored="true" />
<field name="public" type="string" indexed="true" stored="true" />
<field name="featured" type="boolean" indexed="true" stored="true" />
<field name="itemtype" type="string" indexed="true" stored="true" />
<field name="resulttype" type="string" indexed="true" stored="true" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,40 @@ public function testPopulateSearchBoxWithEmptyQuery()
}


/**
* When a new private item is added, it should not be indexed in Solr.
*/
public function testNoDisplayPrivate()
{
$opt = get_option('solr_search_display_private_items');
set_option('solr_search_display_private_items', '0');

try {
$item = insert_item(
array('public' => false),
array(
'Dublin Core' => array(
'Title' => array(
array('text' => 'testNoDisplayPrivate', 'html' => false)
)
)
)
);
$this->_assertRecordInSolr($item);

$_GET['q'] = 'testNoDisplayPrivate';
$this->dispatch('solr-search');
$this->assertNotQueryContentContains('.result-title', 'testNoDisplayPrivate');

} catch (Exception $e) {
throw $e;

} finally {
set_option('solr_search_display_private_items', $opt);
}


}


}
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ public function testIndexItemWhenSetPublic()
/**
* When a new private item is added, it should not be indexed in Solr.
*/
public function testDontIndexNewPrivateItem()
public function testIndexNewPrivateItem()
{

// Insert private item.
$item = insert_item(array('public' => false));

// Should not add a Solr document.
$this->_assertNotRecordInSolr($item);
$this->_assertRecordInSolr($item);

}

Expand All @@ -64,7 +64,7 @@ public function testDontIndexNewPrivateItem()
* When an existing item is switched from public to private, it should be
* removed from Solr.
*/
public function testRemoveItemWhenSetPrivate()
public function testDontRemoveItemWhenSetPrivate()
{

// Insert public item.
Expand All @@ -74,7 +74,7 @@ public function testRemoveItemWhenSetPrivate()
update_item($item, array('public' => false));

// Should remove the Solr document.
$this->_assertNotRecordInSolr($item);
$this->_assertRecordInSolr($item);

}

Expand Down
25 changes: 25 additions & 0 deletions tests/phpunit/tests/unit/SolrSearch_Helpers/FacetTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

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

class SolrSearch_Helpers_Facet_Test extends SolrSearch_Case_Default
{

public function testMakeUrlEncode()
{
$facets = array(
array('49_s', 'Buildings, Cities & towns, Streets')
);
$this->assertEquals(
'/solr-search?q=&amp;facet=' .
'49_s%3A%22Buildings%2C+Cities+%26+towns%2C+Streets%22',
SolrSearch_Helpers_Facet::makeUrl($facets)
);
}
}

Loading

0 comments on commit ca18d91

Please sign in to comment.