Skip to content

Commit

Permalink
Merge branch 'danny' into 6.x
Browse files Browse the repository at this point in the history
  • Loading branch information
DannyJoris committed Jan 16, 2012
2 parents d92e47b + edb38c0 commit 870c0da
Show file tree
Hide file tree
Showing 10 changed files with 104 additions and 42 deletions.
17 changes: 13 additions & 4 deletions IslandoraSolrQueryProcessor.inc
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class IslandoraSolrQueryProcessor {
* @param type $dismax
* @return type
*/
function buildAndExecuteQuery($query, $fq=NULL, $dismax=NULL) {
function buildAndExecuteQuery($query, $fq=NULL, $dismax=NULL, $params = NULL) {

if (variable_get('islandora_solr_search_block_request_handler', NULL) == 'standard') {
$namespace = trim(variable_get('solr_namespace_restriction', NULL));
Expand All @@ -61,19 +61,21 @@ class IslandoraSolrQueryProcessor {
}
}
}
$this->buildQuery($query, $fq, $dismax);
$this->buildQuery($query, $fq, $dismax, $params);

return $this->executeQuery();
}

/**
* Default implementation for solr search. You can configure others in the block config settings
* @todo Get rid of the global $facetArray? It is the only global yet relied upon.
*/
function buildQuery($query, $fq=NULL, $dismax=NULL) {
function buildQuery($query, $fq=NULL, $dismax=NULL, $params = array()) {
// Get pager variable
$startPage = isset($_GET['page']) ? $_GET['page'] : 0;
$this->solrLimit = variable_get('islandora_solr_search_num_of_results', 20);
global $base_url, $facetArray; //used by facet block as well

// -- cut here --
// Get display profile
$islandora_solr_primary_display = variable_get('islandora_solr_primary_display', 'default');
Expand All @@ -83,7 +85,11 @@ class IslandoraSolrQueryProcessor {
return "";
}
$profile = $profiles[$islandora_solr_primary_display];

if ($profile['params']) {
foreach ($profile['params'] as $param) {
$params[] = $param;
}
}
// Include the file for the display profile
require_once(drupal_get_path('module', $profile['module']) . '/' . $profile['file']);

Expand Down Expand Up @@ -126,6 +132,9 @@ class IslandoraSolrQueryProcessor {
);


if (is_array($params)) {
$this->solrParams = array_merge($this->solrParams, $params);
}
$debugQuery = (variable_get('islandora_solr_search_debug_mode', 0) ? "TRUE" : NULL ); //any val incl. 'FALSE' is treated as TRUE by Solr

if ($fq != NULL && $fq != '-') {
Expand Down
49 changes: 33 additions & 16 deletions IslandoraSolrResults.inc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class IslandoraSolrResults {
* @param type $solrQueryProcessor
* @param type $title
* @param type $output
* @return string
* @return string
*/
function displayResults($solrQueryProcessor, $title = "Search Results", $output = '') {

Expand Down Expand Up @@ -80,7 +80,7 @@ class IslandoraSolrResults {
}

// if number of elements is the same as the number of disabled displays,
// this means that there are no displays enabled.
// this means that there are no displays enabled.
if ($array_count != $i) {

$output .= "<div id='islandora_solr_secondary_display_profiles'>";
Expand Down Expand Up @@ -140,7 +140,13 @@ class IslandoraSolrResults {
$title = NULL;
$recordStart = $results->response->start;
$limitResults = variable_get('islandora_solr_search_limit_result_fields', 0);
$rawResponse = $results->getRawResponse();
$responseArray = json_decode($rawResponse, true);
$docs = $responseArray['response']['docs'];
//retrieve 'highlighing' from resultset.
$highlightResults = $responseArray['highlighting'];
$highlights = $results->highlighting;

foreach ($highlights as $highlight) {
$fields = get_object_vars($highlight);
$keys = array_keys($fields);
Expand All @@ -160,7 +166,7 @@ class IslandoraSolrResults {
foreach ($results->response->docs as $doc) {
$rows = array();
$row = 0;

$snippet = null;
foreach ($doc as $field => $value) {

if ($limitResults && empty($this->resultFieldArray[$field])) {
Expand All @@ -177,14 +183,25 @@ class IslandoraSolrResults {
}

if ($field == 'PID') {
$pid = $value;
$l = l($value, 'fedora/repository/' . htmlspecialchars($value, ENT_QUOTES, 'utf-8'));
$rows[$row][] = $l;
if (is_array($keys)) {
$snippet = $highlightResults[$value][$keys[0]];
}
}
else {
$rows[$row][] = $value;
}
$row++;
}
if ($snippet) {
$rows[$row][] = array(
'data' => 'Full Text',
'header' => TRUE,
);
$rows[$row][] = $snippet[0];
}
$items[] = theme_table(NULL, $rows, array('class' => 'islandora_solr_search_results_object'));
}
$output = theme_item_list($items, $title, $type, array('class' => 'stuff', 'start' => ($recordStart + 1)));
Expand Down Expand Up @@ -339,10 +356,10 @@ class IslandoraSolrResults {
if (empty($islandora_facets)) {
return $output; //no facets to show
}

// set counter to include javascript later
$i = 0;

foreach ($islandora_facets as $key => $field) {
$list_items = array();
$list_type = "ul";
Expand Down Expand Up @@ -400,30 +417,30 @@ class IslandoraSolrResults {
$facet_count++;
}
}
if ($facet_count >= 2) {
if ($facet_count >= 1) {
$facet_output .='<div class="islandora_solr_search_facet">';

// shown limit
$shown_limit = variable_get('islandora_solr_search_block_facet_shown_limit', 0);
$facetlimit = variable_get('islandora_solr_search_block_facet_limit', '12');
$facetMinCount = variable_get('islandora_solr_search_block_facet_min_count', '2');

$list_title = $this->facetFieldArray[$key];
$list_type = "ul";
$list_attributes = array('class' => 'islandora_solr_search_facet_list facet_list');

// set show more variable
$show_more = FALSE;

// split the array if shown_limit is between the min and max limits and if the total is larger than the shown_limit.
if ($facet_count > $shown_limit AND $shown_limit < $facetlimit AND $shown_limit > $facetMinCount) {
$list_items_hidden = array_slice($list_items, $shown_limit);
$list_items = array_slice($list_items, 0, $shown_limit);
$show_more = TRUE;
}

$facet_output .= theme_item_list($list_items, $list_title, $list_type, $list_attributes);

// set counter
if ($show_more == TRUE) {
$i++;
Expand All @@ -433,7 +450,7 @@ class IslandoraSolrResults {
$facet_output .= theme_item_list($list_items_hidden, NULL, $list_type, $list_attributes);
$facet_output .= '</div>';
}

$facet_output .='</div>';
}
}
Expand Down Expand Up @@ -464,7 +481,7 @@ class IslandoraSolrResults {
* @param type $repeat
* @param type $pathToSearchTerms
* @param type $query
* @return string
* @return string
*/
function build_solr_search_form($repeat = NULL, $pathToSearchTerms = NULL, $query = NULL) {

Expand Down Expand Up @@ -550,7 +567,7 @@ class IslandoraSolrResults {
/**
* Build simple solr form
* @global type $islandora_query
* @return type
* @return type
*/
function build_simple_solr_form() {
$required = FALSE;
Expand Down Expand Up @@ -579,7 +596,7 @@ class IslandoraSolrResults {
/**
* Theme solr search form
* @param type $form
* @return type
* @return type
*/
function theme_solr_search_form($form) {
if (!isset($repeat)) {
Expand Down
19 changes: 13 additions & 6 deletions islandora_solr_config/IslandoraSolrResultsTable.inc
Original file line number Diff line number Diff line change
Expand Up @@ -112,19 +112,26 @@ class IslandoraSolrResultsTable extends IslandoraSolrResults {
foreach ($values as $num => $val_array) {
unset($rowclass);
$result_num = $recordStart + $num + 1;
$rows[$row][] = array(
$rows[$row]['data'][] = array(
'data' => (isset($val_array['PID']) ? l($result_num,'fedora/repository/'.$val_array['PID']) : $result_num),
'header' => TRUE,
'class' => 'col-first'

);
foreach ($fields as $field) {
if (isset ($val_array[$field])) {
$rows[$row][] = $val_array[$field];
} else {
$rows[$row][] = '';
$field_count = count($fields);
foreach ($fields as $fieldnum => $field) {
if (!isset ($val_array[$field])) {
$val_array['field'] = " ";
}
$cell_data = array('data' => $val_array[$field]);
$rows[$row]['data'][] = $cell_data;

}
$rows[$row]['data'][$field_count]['class'] = 'col-last';
$row++;
}
$rows[0]['class'] = 'row-first';
$rows[$row -1]['class'] = 'row-last';

$output .= theme_table($header,$rows,array('class'=>'islandora_solr_search_results_table'));

Expand Down
2 changes: 1 addition & 1 deletion islandora_solr_config/islandora_solr_config.info
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ description = Example Code for Implementation of Islandora Solr Search Configura
dependencies[] = islandora_solr_search
description = Customizes Islandora solr search
package = Islandora Search
version = 11.3beta3
version = 11.3.1
core = 6.x
5 changes: 1 addition & 4 deletions islandora_solr_config/islandora_solr_config.module
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
* Configuration module for islandora_solr_search.module
*/


/**
* Implements hook_islandora_solr_primary_display()
*/
Expand Down Expand Up @@ -38,6 +37,7 @@ function islandora_solr_config_islandora_solr_primary_display() {
'function' => "displayResults",
'description' => t('A tabular output for maps. Depends upon the existence of a TN datastream in fedora objects returned as results.')
),

);
}

Expand All @@ -61,7 +61,6 @@ function islandora_solr_config_islandora_solr_secondary_display() {
/**
* Implementation of hook_help()
*/

function islandora_solr_config_help($path, $arg) {

switch ($path) {
Expand All @@ -75,8 +74,6 @@ function islandora_solr_config_help($path, $arg) {
<li>Method - displayResults</l1>
</ul>
", array('!page' => l("Islandora_solr_search configuration page", 'admin/settings/islandora_solr_search'),)


);
}
}
Expand Down
45 changes: 37 additions & 8 deletions islandora_solr_search.admin.inc
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ function islandora_solr_admin_settings(&$form_state) {
'#description' => t("Enter a namespace ie 'demo' to restrict results to PIDs within that namespace <br /><em>note: this setting may only be used with 'standard' request handler.</em>"),
);
}




$profiles = module_invoke_all("islandora_solr_primary_display");
uksort($profiles, "sort_default_first");
foreach ($profiles as $machine_name => $profile) {
Expand Down Expand Up @@ -136,6 +140,25 @@ function islandora_solr_admin_settings(&$form_state) {
'#default_value' => variable_get('islandora_solr_search_block_repeat', '3'),
);

$form['sort_fields'] = array(
'#type' => 'fieldset',
'#collapsible' => TRUE,
);

$form['sort_fields']['islandora_solr_search_sort_field'] = array(
'#type' => 'textfield', '#title' => t('Sort field'),
'#size' => 20,
'#description' => t('Results will be sorted on this field. If left blank will default to <em>score</em> '),
'#default_value' => variable_get('islandora_solr_search_sort_field', ''),
);

$form['sort_fields']['islandora_solr_search_sort_order'] = array(
'#type' => 'radios',
'#title' => t('Sort Order'),
'#options' => array('asc' => t('Accending'), 'desc' => t('Decending')),
'#default_value' => 'desc',
);

$form['islandora_solr_searchterms'] = array(
'#type' => 'textarea',
'#title' => t('Search Terms'),
Expand All @@ -155,9 +178,11 @@ function islandora_solr_admin_settings(&$form_state) {
<strong>Note:</strong><em> This feature is not supported by all display profiles.</em> "),
'#wysiwyg' => FALSE,
);

$form['islandora_solr_search_block_facets'] = array(
'#type' => 'textarea',
'#title' => t('Facet Fields'),
'#default_value' => variable_get('islandora_solr_search_block_facets', ''),
'#description' => t("Indicate which fields will appear in the <strong>Islandora Facet Block</strong>.<br />
Enter terms on separate lines using the following pattern: field [tilde] preferred label. ie <strong>dc.title ~ Title</strong> "),
'#default_value' => variable_get('islandora_solr_search_block_facets', 'dc.subject ~ Subject,dc.type ~ Type'),
Expand Down Expand Up @@ -239,15 +264,18 @@ function islandora_solr_admin_settings(&$form_state) {
* Checks availability of Solr installation
*
*/

function solr_available($solr_url) {
// path from url is parsed to allow graceful inclusion or exclusion of 'http://'
$pathParts = parse_url($solr_url);
$path = 'http://' . $pathParts['host'] . ':' . $pathParts['port'] . $pathParts['path'] . '/admin/file';
$test = @fopen($path, "r");
if ($test) {
return TRUE;
$handle = curl_init($solr_url);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, TRUE);
$response = curl_exec($handle);
$httpCode = curl_getinfo($handle, CURLINFO_HTTP_CODE);
$retval = TRUE;
if ($httpCode % 100 == 4) {
$retval = FALSE;
}
return FALSE;
curl_close($handle);
return $retval;
}

/**
Expand Down Expand Up @@ -286,7 +314,8 @@ function check_dismax($solr_url, $selected_handler) {
foreach ($handler->lst as $first) {
foreach ($first->str as $str) {
if ($str['name'] == 'qf') {
$dismax= TRUE;
$dismax = TRUE;

}
}
}
Expand Down
2 changes: 1 addition & 1 deletion islandora_solr_search.info
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ name = Islandora Solr Search
dependencies[] = fedora_repository
description = searches a solr index
package = Islandora Search
version = 11.3beta3
version = 11.3.1
core = 6.x
2 changes: 1 addition & 1 deletion islandora_solr_search.install
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function islandora_solr_search_requirements($phase) {
if ($phase == 'install') {


if (!class_exists(Apache_Solr_Service)) {
if (!class_exists('Apache_Solr_Service')) {
$requirements['islandora_solr_search'] = array(
'title' => $t('Missing Apache Client'),
'description' => $t('This module requires the ' . l('Apache Solr php client', 'http://code.google.com/p/solr-php-client') . '. Please install the client directory in the root directory of this module before continuing.'),
Expand Down
Loading

0 comments on commit 870c0da

Please sign in to comment.