Skip to content

Commit

Permalink
Merge branch 'release/2.3.0'
Browse files Browse the repository at this point in the history
* Allow the option to index private items;
* Make sure we only delete facets that are set;
* Expanded the number of characters to scan for hit highlighting in
  results (#114);
* Escape URLs (#115);
* Include large thumbnails in search results (#116);
* Sanitize search queries (#119);
* "Load New Elements" button (#120); and
* Exclude items from private collections (#122).

Thanks to @anuragji for your help on this release!
  • Loading branch information
Eric Rochester committed Aug 19, 2015
2 parents 15ec227 + 1a04a07 commit 394754a
Show file tree
Hide file tree
Showing 22 changed files with 426 additions and 566 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Gemfile.lock
node_modules/
vendor
pkg
.DS_Store

tests/phpunit/solr.ini
solr-core/collection1/data
6 changes: 4 additions & 2 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ module.exports = function(grunt) {
dist: {
options: {
sassDir: 'views/shared/css/sass',
cssDir: 'views/shared/css'
cssDir: 'views/shared/css',
outputStyle: 'compressed',
sourcemap: true
}
}

Expand All @@ -54,7 +56,7 @@ module.exports = function(grunt) {

payload: {
files: 'views/shared/css/sass/*.scss',
tasks: 'compile:min'
tasks: 'build'
}

},
Expand Down
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,13 @@ can select collections to *exclude* from indexing.
This form makes it possible to configure (a) which metadata elements and Omeka
categories ("fields") are stored as searchable content in Solr and (b) which
fields should be used as "facets", groupings of records that can be used to
iteratively narrow down the set of results. For each element, there are three
options:
iteratively narrow down the set of results.

> If you've installed any new metadata elements and they're missing from this
> form, click the "Load New Elements" button at the bottom of the page. The
> page will reload, and hopefully the new elements will be listed.
For each element, there are three options:

- **Facet Label**: The label used as the heading for the facet corresponding
to the field. In most cases, it probably just makes sense to use the
Expand Down Expand Up @@ -124,6 +129,11 @@ honing in on specific categories.
- **Enable Highlighting**: Set whether highlighting snippets should be
displayed.

- **Extent of Document Highlightable**: Set the amount of the document to
scan when highlighting. By default, to save time, this is limited to 51200
characters. If you have documents in the results that don't have snippets,
you can make this larger.

- **Number of Snippets**: The maximum number of snippets to display for a
result.

Expand Down
46 changes: 17 additions & 29 deletions SolrSearchPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ public function hookUpgrade($args)
if (is_null($featured) || empty($featured)) {
$this->_installGenericFacet('featured', __('Featured'));
}

if (version_compare($args['old_version'], '2.2.1', '<=')) {
set_option('solr_search_hl_max_analyzed_chars', '51200');
}
}


Expand Down Expand Up @@ -265,7 +269,10 @@ public function hookBeforeDeleteElement($args)
{
$table = $this->_db->getTable('SolrSearchField');
$facet = $table->findByElement($args['record']);
$facet->delete();

if(!empty($facet)) {
$facet->delete();
}
}


Expand Down Expand Up @@ -332,27 +339,9 @@ protected function _createSolrTables()
*/
protected function _installFacetMappings()
{

$facets = $this->_db->getTable('SolrSearchField');
$elements = $this->_db->getTable('Element');

// Generic facets:
$this->_installGenericFacet('tag', __('Tag'));
$this->_installGenericFacet('collection', __('Collection'));
$this->_installGenericFacet('itemtype', __('Item Type'));
$this->_installGenericFacet('resulttype', __('Result Type'));
$this->_installGenericFacet('featured', __('Featured'));

// Element-backed facets:
foreach ($elements->findAll() as $element) {
$facet = new SolrSearchField($element);
$facet->save();
}

// By default, index DC Title/Description.
$facets->setElementIndexed('Dublin Core', 'Title');
$facets->setElementIndexed('Dublin Core', 'Description');

$this->_db
->getTable('SolrSearchField')
->installFacetMappings();
}


Expand All @@ -364,12 +353,9 @@ protected function _installFacetMappings()
*/
protected function _installGenericFacet($slug, $label)
{
$facet = new SolrSearchField();
$facet->slug = $slug;
$facet->label = $label;
$facet->is_indexed = 1;
$facet->is_facet = 1;
$facet->save();
$this->_db
->getTable('SolrSearchField')
->installGenericFacet($slub, $label);
}


Expand All @@ -386,7 +372,8 @@ 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');
set_option('solr_search_hl_max_analyzed_chars', '51200');
set_option('solr_search_display_private_items', '1');
}


Expand All @@ -403,6 +390,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_hl_max_analyzed_chars');
delete_option('solr_search_display_private_items');
}

Expand Down
20 changes: 19 additions & 1 deletion controllers/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,13 @@ protected function _updateCollections($post)
protected function _collectionsForm()
{
$ctable = $this->_helper->db->getTable('Collection');
$collections = $ctable->findBy(array('public' => 1));
$private = (int)get_option('solr_search_display_private_items');

if ($private) {
$collections = $ctable->findAll();
} else {
$collections = $ctable->findBy(array('public' => 1));
}

$form = new Zend_Form();
$form->setAction(url('solr-search/collections'))->setMethod('post');
Expand All @@ -122,6 +128,18 @@ protected function _collectionsForm()
return $form;
}

/**
* Update the set of fields in the facet set.
*
* @author Eric Rochester <erochest@virginia.edu>
*/
public function updatefacetAction()
{
$fieldTable = $this->_helper->db->getTable('SolrSearchField');
$fieldTable->updateFacetMappings();
$this->redirect('solr-search/fields');
}

/**
* Display the "Field Configuration" form.
*/
Expand Down
33 changes: 21 additions & 12 deletions controllers/ResultsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,17 @@ protected function _getQuery($limitToPublicItems = true)
// Get the `q` GET parameter.
$query = $this->_request->q;

// If defined, replace `:`; otherwise, revert to `*:*`
if (!empty($query)) $query = str_replace(':', ' ', $query);
else $query = '*:*';
// If defined, replace `:`; otherwise, revert to `*:*`.
// Also, clean it up some.
if (!empty($query)) {
$query = str_replace(':', ' ', $query);
$to_remove = array('[', ']');
foreach ($to_remove as $c) {
$query = str_replace($c, '', $query);
}
} else {
$query = '*:*';
}

// Get the `facet` GET parameter
$facet = $this->_request->facet;
Expand Down Expand Up @@ -146,15 +154,16 @@ protected function _getParameters()

return array(

'facet' => 'true',
'facet.field' => $facets,
'facet.mincount' => 1,
'facet.limit' => get_option('solr_search_facet_limit'),
'facet.sort' => get_option('solr_search_facet_sort'),
'hl' => get_option('solr_search_hl')?'true':'false',
'hl.snippets' => get_option('solr_search_hl_snippets'),
'hl.fragsize' => get_option('solr_search_hl_fragsize'),
'hl.fl' => '*_t'
'facet' => 'true',
'facet.field' => $facets,
'facet.mincount' => 1,
'facet.limit' => get_option('solr_search_facet_limit'),
'facet.sort' => get_option('solr_search_facet_sort'),
'hl' => get_option('solr_search_hl')?'true':'false',
'hl.snippets' => get_option('solr_search_hl_snippets'),
'hl.fragsize' => get_option('solr_search_hl_fragsize'),
'hl.maxAnalyzedChars' => get_option('solr_search_hl_max_analyzed_chars'),
'hl.fl' => '*_t'

);

Expand Down
20 changes: 20 additions & 0 deletions forms/SolrSearch_Form_Results.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,26 @@ public function init()
)
));

// Max Analyzed Chars
$this->addElement('text', 'solr_search_hl_max_analyzed_chars', array(
'label' => __('Extent of Document Highlightable'),
'description' => __('How much of the document can be highlighted, in characters. Occurrences past this point will not be returned in the results highlighting.'),
'value' => get_option('solr_search_hl_max_analyzed_chars'),
'required' => true,
'size' => 10,
'validators' => array(
array(
'validator' => 'Int',
'breakChainOnFailure' => true,
'options' => array(
'messages' => array(
Zend_Validate_Int::NOT_INT => __('Must be an integer.')
)
)
)
)
));

// Facet Ordering:
$this->addElement('select', 'solr_search_facet_sort', array(
'label' => __('Facet Ordering'),
Expand Down
1 change: 0 additions & 1 deletion helpers/SolrSearch_Helpers_Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,6 @@ public static function indexAll($options=array())

// 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
72 changes: 71 additions & 1 deletion models/SolrSearchFieldTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function findByElementName($set, $element)
);

// Find the element's field.
return $this->findByElement($element);
return is_null($element) ? null : $this->findByElement($element);

}

Expand Down Expand Up @@ -162,4 +162,74 @@ public function groupByElementSet()
}


/**
* Installs the current set of elements as facets.
*/
public function installFacetMappings()
{
$elements = $this->_db->getTable('Element');

// Generic facets:
$this->installGenericFacet('tag', __('Tag'));
$this->installGenericFacet('collection', __('Collection'));
$this->installGenericFacet('itemtype', __('Item Type'));
$this->installGenericFacet('resulttype', __('Result Type'));
$this->installGenericFacet('featured', __('Featured'));

// Element-backed facets:
foreach ($elements->findAll() as $element) {
$facet = new SolrSearchField($element);
$facet->save();
}

// By default, index DC Title/Description.
$this->setElementIndexed('Dublin Core', 'Title');
$this->setElementIndexed('Dublin Core', 'Description');
}

/**
* Install a default facet mapping.
*
* @param string $slug The facet `slug`.
* @param string $label The facet `label`.
*/
public function installGenericFacet($slug, $label)
{
$facet = new SolrSearchField();
$facet->slug = $slug;
$facet->label = $label;
$facet->is_indexed = 1;
$facet->is_facet = 1;
$facet->save();
}

/**
* Updates the facets with elements that have been added since
* `installFacets` was called.
*/
public function updateFacetMappings()
{
$facetSet = array();
foreach ($this->findAll() as $facet) {
$facetSet[$facet->element_id] = $facet;
}

$elementTable = $this->_db->getTable('Element');
$elementSet = array();
foreach ($elementTable->findAll() as $element) {
if (! array_key_exists($element->id, $facetSet)) {
$facet = new SolrSearchField($element);
$facet->save();
} else {
$elementSet[$element->id] = TRUE;
}
}

foreach ($facetSet as $facetId => $facet) {
if (! array_key_exists($facetId, $elementSet)) {
$facet->delete();
}
}
}

}
20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"name": "SolrSearch",
"version": "2.2.1",
"devDependencies" : {
"grunt": ">= 0.4.0"
, "grunt-contrib-concat": ">= 0.1.3"
, "grunt-contrib-uglify": ">= 0.1.1"
, "grunt-contrib-compass": ">= 0.7.1"
, "grunt-contrib-compress": ">= 0.4.0"
, "grunt-contrib-clean": ">= 0.4.0"
, "grunt-contrib-watch": ">= 0.2.0"
, "grunt-phpunit": ">= 0.3.1"
"version": "2.3.0",
"devDependencies": {
"grunt": ">= 0.4.0",
"grunt-contrib-clean": ">= 0.4.0",
"grunt-contrib-compass": ">= 0.7.1",
"grunt-contrib-compress": ">= 0.4.0",
"grunt-contrib-concat": ">= 0.1.3",
"grunt-contrib-uglify": ">= 0.1.1",
"grunt-contrib-watch": ">= 0.2.0",
"grunt-phpunit": ">= 0.3.1"
}
}
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.2.1"
version="2.3.0"
tags="solr, search"
license="Apache 2.0"
3 changes: 3 additions & 0 deletions tests/phpunit/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@

// Base test case.
require_once 'cases/SolrSearch_Case_Default.php';

// Load other files.
require_once SOLR_DIR . '/helpers/SolrSearch_Helpers_Index.php';
Loading

0 comments on commit 394754a

Please sign in to comment.