Mercurial > hg > MPIWG-drupal-modules
diff sites/all/modules/custom/solrsearch/solrsearch_terms.inc @ 0:015d06b10d37 default tip
initial
author | dwinter |
---|---|
date | Wed, 31 Jul 2013 13:49:13 +0200 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sites/all/modules/custom/solrsearch/solrsearch_terms.inc Wed Jul 31 13:49:13 2013 +0200 @@ -0,0 +1,106 @@ +<?php + + +function solrsearch_load_data_x($field,$letter){ + #todo cache this! + $env = solrsearch_environment_load('echosearch'); + $searchStr = "/terms?q=doc-type:indexMeta%20and%20access-type:free&json.nl=map&wt=json&terms.fl=" . $field . "&terms.limit=-1&terms.sort=index&term.mincount=1&terms.prefix=" . $letter; + $url = $env['url']; + $result = drupal_http_request($url . $searchStr); + $data = drupal_json_decode($result->data); + $authorsAll=$data['terms'][$field]; + return $authorsAll; +} + +function solrsearch_load_data($field,$letter,$accessType="free"){ + #todo cache this! + $env = solrsearch_environment_load('echosearch'); + $searchStr = "/select?q=". $field. ":". $letter . "*%20and%20doc-type:indexMeta%20&json.nl=map&facet.sort=index&facet.mincount=1&wt=json&facet=true&facet.field=" . $field . "&facet.limit=100000&start=0&rows=9"; + + if ($accessType=="free") + { + $searchStr .="&fq=access-type:free"; + } + + $url = $env['url']; + $result = drupal_http_request($url . $searchStr); + $data = drupal_json_decode($result->data); + #return $data; + + $resultsAll=$data['facet_counts']['facet_fields'][$field]; + + #result list ist zu lang, da hier alle werke gefunden werden, bei denene ein Autor mit dem Buchstaben beginnt. + $res=array(); + foreach ($resultsAll as $author => $val){ + if (drupal_substr($author, 0,1) == $letter){ + $res[$author]=$val; + } + + } + + return $res; +} + +# + +function solrsearch_term_select_field(){ + $query = $_GET; + if (isset($query['browseField'])){ + drupal_goto("solrsearch-terms/" .$query['browseField'] ); + } + +} +function solrsearch_term_list($field="",$letter="A",$numperpage=20){ + + if ($field==""){ + return ''; + } + + + + #field z.b. author_c + + if (!user_access("view restricted content")){ + $accessType="free"; + } else { + $accessType=""; + } + + $authorsAll=solrsearch_load_data($field,$letter,$accessType); + $cnt=count($authorsAll); + + $page = pager_find_page(); + $offset = $numperpage * $page; + $authors = array_slice($authorsAll, $offset,$slice_lenght=$numperpage); + + pager_default_initialize($cnt, 10); + + $rs = theme('solrsearch_term_selection_form',array('field' => $field)); + $rs .=theme('pager', array('tags' => array('<<','<','..','>','>>'),'quantity' => 3)); + + if ($field=='author_c'){ + $rs .= theme('solrsearch_term_list_author',array('authors' => $authors,'cnt' => $cnt,'letter' => $letter)); + } else { + $rs .= theme('solrsearch_term_list_title',array('titles' => $authors,'cnt' => $cnt,'letter' => $letter)); + } + + + $rs .=theme('pager', array('tags' => array('<<','<','..','>','>>'),'quantity' => 3)); + + return $rs; + } + + + function solrsearch_alphapager($field) { + $attributes = array( 'class' => 'alpha-page' ); + $output = ""; + + foreach(range('A', 'Z') as $letter) { + $output .= " + <li>" . l($letter, "solrsearch-terms/" . $field . "/" . $letter, $attributes). " |</li>"; + } + + + + return $output; + } \ No newline at end of file