Mercurial > hg > solrsearch
comparison solrsearch_terms.inc @ 0:a2b4f67e73dc default tip
initial
author | Dirk Wintergruen <dwinter@mpiwg-berlin.mpg.de> |
---|---|
date | Mon, 08 Jun 2015 10:21:54 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:a2b4f67e73dc |
---|---|
1 <?php | |
2 | |
3 | |
4 function solrsearch_load_data_x($field,$letter){ | |
5 #todo cache this! | |
6 $env = solrsearch_environment_load('echosearch'); | |
7 //$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; | |
8 $searchStr = "/terms?q=access-type:free&json.nl=map&wt=json&terms.fl=" . $field . "&terms.limit=-1&terms.sort=index&term.mincount=1&terms.prefix=" . $letter; | |
9 | |
10 | |
11 $url = $env['url']; | |
12 $result = drupal_http_request($url . $searchStr); | |
13 $data = drupal_json_decode($result->data); | |
14 $authorsAll=$data['terms'][$field]; | |
15 return $authorsAll; | |
16 } | |
17 | |
18 function solrsearch_load_data($field,$letter,$accessType="free"){ | |
19 #todo cache this! | |
20 $env = solrsearch_environment_load('echosearch'); | |
21 // $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"; | |
22 $searchStr = "/select?q=". $field. ":". $letter . "*&json.nl=map&facet.sort=index&facet.mincount=1&wt=json&facet=true&facet.field=" . $field . "&facet.limit=100000&start=0&rows=9"; | |
23 | |
24 | |
25 if ($accessType=="free") | |
26 { | |
27 $searchStr .="&fq=access-type:free"; | |
28 } | |
29 | |
30 $url = $env['url']; | |
31 $result = drupal_http_request($url . $searchStr); | |
32 $data = drupal_json_decode($result->data); | |
33 #return $data; | |
34 | |
35 $resultsAll=$data['facet_counts']['facet_fields'][$field]; | |
36 | |
37 #result list ist zu lang, da hier alle werke gefunden werden, bei denene ein Autor mit dem Buchstaben beginnt. | |
38 $res=array(); | |
39 foreach ($resultsAll as $author => $val){ | |
40 if (drupal_substr($author, 0,1) == $letter){ | |
41 $res[$author]=$val; | |
42 } | |
43 | |
44 } | |
45 | |
46 return $res; | |
47 } | |
48 | |
49 # | |
50 | |
51 function solrsearch_term_select_field(){ | |
52 $query = $_GET; | |
53 if (isset($query['browseField'])){ | |
54 drupal_goto("solrsearch-terms/" .$query['browseField'] ); | |
55 } | |
56 | |
57 } | |
58 function solrsearch_term_list($field="",$letter="A",$numperpage=20){ | |
59 | |
60 if ($field==""){ | |
61 return ''; | |
62 } | |
63 | |
64 | |
65 | |
66 #field z.b. author_c | |
67 | |
68 if (!user_access("view restricted content")){ | |
69 $accessType="free"; | |
70 } else { | |
71 $accessType=""; | |
72 } | |
73 | |
74 $authorsAll=solrsearch_load_data($field,$letter,$accessType); | |
75 $cnt=count($authorsAll); | |
76 | |
77 $page = pager_find_page(); | |
78 $offset = $numperpage * $page; | |
79 $authors = array_slice($authorsAll, $offset,$slice_lenght=$numperpage); | |
80 | |
81 pager_default_initialize($cnt, 10); | |
82 | |
83 $rs = theme('solrsearch_term_selection_form',array('field' => $field)); | |
84 $rs .=theme('pager', array('tags' => array('<<','<','..','>','>>'),'quantity' => 3)); | |
85 | |
86 if ($field=='author_c'){ | |
87 $rs .= theme('solrsearch_term_list_author',array('authors' => $authors,'cnt' => $cnt,'letter' => $letter)); | |
88 } else { | |
89 $rs .= theme('solrsearch_term_list_title',array('titles' => $authors,'cnt' => $cnt,'letter' => $letter)); | |
90 } | |
91 | |
92 | |
93 $rs .=theme('pager', array('tags' => array('<<','<','..','>','>>'),'quantity' => 3)); | |
94 | |
95 return $rs; | |
96 } | |
97 | |
98 | |
99 function solrsearch_alphapager($field) { | |
100 $attributes = array( 'class' => 'alpha-page' ); | |
101 $output = ""; | |
102 | |
103 foreach(range('A', 'Z') as $letter) { | |
104 $output .= " | |
105 <li>" . l($letter, "solrsearch-terms/" . $field . "/" . $letter, $attributes). "</li>"; | |
106 } | |
107 | |
108 | |
109 | |
110 return $output; | |
111 } |