Index: trunk/extensions/SolrStore/SolrSearchTemplateLoader.php |
— | — | @@ -1,35 +1,35 @@ |
2 | | -<?php
|
3 | | -/**
|
4 | | - * Dynamic TemplateLoader
|
5 | | - *
|
6 | | - * @ingroup SolrStore
|
7 | | - * @file
|
8 | | - * @author Sascha Schueller
|
9 | | - */
|
10 | | -
|
11 | | -/**
|
12 | | - * TODO: Insert class description
|
13 | | - *
|
14 | | - * @ingroup SolrStore
|
15 | | - */
|
16 | | -class SolrSearchTemplateLoader {
|
17 | | -
|
18 | | - public function applyTemplate( $xml ) {
|
19 | | - global $wgSolrTemplate;
|
20 | | -
|
21 | | - $dir = dirname( __FILE__ );
|
22 | | - $file = $dir . '/templates/SolrSearchTemplate' . $wgSolrTemplate . '.php';
|
23 | | - $classname = 'SolrSearchTemplate' . $wgSolrTemplate;
|
24 | | -
|
25 | | - if ( file_exists( $file ) ) {
|
26 | | - if ( !class_exists( $classname ) ) {
|
27 | | - include($dir . '/templates/SolrSearchTemplate' . $wgSolrTemplate . '.php');
|
28 | | - }
|
29 | | - $classname = new $classname();
|
30 | | - return $classname->applyTemplate( $xml );
|
31 | | - }
|
32 | | - die( "SolrSearch Template Problem: File not exists !! " . $file );
|
33 | | - }
|
34 | | -
|
35 | | -}
|
36 | | -?>
|
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Dynamic TemplateLoader |
| 5 | + * |
| 6 | + * @ingroup SolrStore |
| 7 | + * @file |
| 8 | + * @author Sascha Schueller |
| 9 | + */ |
| 10 | + |
| 11 | +/** |
| 12 | + * TODO: Insert class description |
| 13 | + * |
| 14 | + * @ingroup SolrStore |
| 15 | + */ |
| 16 | +class SolrSearchTemplateLoader { |
| 17 | + |
| 18 | + public function applyTemplate( $xml ) { |
| 19 | + global $wgSolrTemplate; |
| 20 | + |
| 21 | + $dir = dirname( __FILE__ ); |
| 22 | + $file = $dir . '/templates/SolrSearchTemplate' . $wgSolrTemplate . '.php'; |
| 23 | + $classname = 'SolrSearchTemplate' . $wgSolrTemplate; |
| 24 | + |
| 25 | + if ( file_exists( $file ) ) { |
| 26 | + if ( !class_exists( $classname ) ) { |
| 27 | + include($dir . '/templates/SolrSearchTemplate' . $wgSolrTemplate . '.php'); |
| 28 | + } |
| 29 | + $classname = new $classname(); |
| 30 | + return $classname->applyTemplate( $xml ); |
| 31 | + } |
| 32 | + die( "SolrSearch Template Problem: File not exists !! " . $file ); |
| 33 | + } |
| 34 | + |
| 35 | +} |
| 36 | +?> |
Property changes on: trunk/extensions/SolrStore/SolrSearchTemplateLoader.php |
___________________________________________________________________ |
Added: svn:eol-style |
37 | 37 | + native |
Index: trunk/extensions/SolrStore/templates/SolrSearchTemplate_Standart.php |
— | — | @@ -1,116 +1,116 @@ |
2 | | -<?php
|
3 | | -/**
|
4 | | - * Dynamic Template 'Standart' -> Example
|
5 | | - *
|
6 | | - * Conditions to use:
|
7 | | - * Please name the class: SolrSearchTemplate_NAME
|
8 | | - * Filename: SolrSearchTemplate_NAME.php
|
9 | | - * dont touch the function name: applyTemplate( $xml )
|
10 | | - *
|
11 | | - * @ingroup SolrStore
|
12 | | - * @path templates
|
13 | | - * @author Sascha Schueller
|
14 | | - */
|
15 | | -class SolrSearchTemplate_Standart {
|
16 | | -
|
17 | | - var $mTitle = null;
|
18 | | - var $mRedirectTitle = null;
|
19 | | - var $mHighlightSection = null;
|
20 | | - var $mSectionTitle = null;
|
21 | | - var $mDate = null;
|
22 | | - var $mScore = null;
|
23 | | - var $mSize = null;
|
24 | | - var $mHighlightText = null;
|
25 | | - var $mHighlightTitle = null;
|
26 | | - var $mWordCount = null;
|
27 | | -
|
28 | | - public function applyTemplate( $xml ) { // DONT TOUCH
|
29 | | - $snipmax = 50;
|
30 | | - $textlenght = 250;
|
31 | | -
|
32 | | - // get Size, Namespace, Wordcound, Date from XML:
|
33 | | - foreach ( $xml->arr as $doc ) {
|
34 | | - switch ( $doc[ 'name' ] ) {
|
35 | | - case 'text':
|
36 | | - $nsText = $doc->str;
|
37 | | - $this->mSize = '';
|
38 | | - $this->mWordCount = count( $doc->str );
|
39 | | - $textsnip = '';
|
40 | | - $textsnipvar = 0;
|
41 | | - foreach ( $doc->str as $inner ) {
|
42 | | - $textsnipvar++;
|
43 | | - if ( $textsnipvar >= 4 && $textsnipvar <= $snipmax ) {
|
44 | | - $textsnip .= ' ' . $inner;
|
45 | | - }
|
46 | | - $textsnip = substr( $textsnip, 0, $textlenght );
|
47 | | - $this->mSize = $this->mSize + strlen( $inner );
|
48 | | - }
|
49 | | - $this->mSize = ( $this->mSize / 3 );
|
50 | | - $this->mDate = $doc->date;
|
51 | | - break;
|
52 | | - }
|
53 | | - }
|
54 | | -
|
55 | | - // get Title, Interwiki from XML:
|
56 | | - foreach ( $xml->str as $docs ) {
|
57 | | - switch ( $docs[ 'name' ] ) {
|
58 | | - case 'pagetitle':
|
59 | | - $this->mTitle = $doc->str;
|
60 | | - break;
|
61 | | - case 'dbkey':
|
62 | | - $title = $doc->str;
|
63 | | - break;
|
64 | | - case 'interwiki':
|
65 | | - $this->mInterwiki = $doc->str;
|
66 | | - break;
|
67 | | - }
|
68 | | - }
|
69 | | -
|
70 | | - //get namespace from XML:
|
71 | | - foreach ( $xml->int as $doci ) {
|
72 | | - switch ( $doci[ 'name' ] ) {
|
73 | | - case 'namespace':
|
74 | | - $namespace = $doc->str;
|
75 | | - break;
|
76 | | - }
|
77 | | - }
|
78 | | -
|
79 | | - if ( !isset( $nsText ) ) {
|
80 | | - $nsText = $wgContLang->getNsText( $namespace );
|
81 | | - } else {
|
82 | | - $nsText = urldecode( $nsText );
|
83 | | - }
|
84 | | -
|
85 | | - // make score / relevance
|
86 | | - $this->mScore = $xml->float;
|
87 | | -
|
88 | | - // make Title
|
89 | | - $title = urldecode( $title );
|
90 | | - $this->mTitle = Title::makeTitle( $namespace, $title );
|
91 | | -
|
92 | | - // make Highlight - Title
|
93 | | - if ( $xml->highlight->title != '' ) {
|
94 | | - $this->mHighlightTitle = $xml->highlight->title;
|
95 | | - } else {
|
96 | | - $this->mHighlightTitle = '';
|
97 | | - }
|
98 | | -
|
99 | | - // make Highlight - Text
|
100 | | - if ( $xml->highlight->Inhalt != '' ) {
|
101 | | - $this->mHighlightText = str_replace( '<em>', '<b>', $xml->highlight->Inhalt );
|
102 | | - $this->mHighlightText = str_replace( '</em>', '</b>', $this->mHighlightText );
|
103 | | - $this->mHighlightText .= '...';
|
104 | | - } else {
|
105 | | - $this->mHighlightText = "NO HIGHLIGHTING TEXT FROM SOLR !";
|
106 | | -
|
107 | | - // if nothing define itself !
|
108 | | - // 4 example with
|
109 | | - // $this->mHighlightText = $textsnip;
|
110 | | - }
|
111 | | -
|
112 | | - return $this;
|
113 | | - }
|
114 | | -
|
115 | | -}
|
116 | | -
|
117 | | -?>
|
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Dynamic Template 'Standart' -> Example |
| 5 | + * |
| 6 | + * Conditions to use: |
| 7 | + * Please name the class: SolrSearchTemplate_NAME |
| 8 | + * Filename: SolrSearchTemplate_NAME.php |
| 9 | + * dont touch the function name: applyTemplate( $xml ) |
| 10 | + * |
| 11 | + * @ingroup SolrStore |
| 12 | + * @path templates |
| 13 | + * @author Sascha Schueller |
| 14 | + */ |
| 15 | +class SolrSearchTemplate_Standart { |
| 16 | + |
| 17 | + var $mTitle = null; |
| 18 | + var $mRedirectTitle = null; |
| 19 | + var $mHighlightSection = null; |
| 20 | + var $mSectionTitle = null; |
| 21 | + var $mDate = null; |
| 22 | + var $mScore = null; |
| 23 | + var $mSize = null; |
| 24 | + var $mHighlightText = null; |
| 25 | + var $mHighlightTitle = null; |
| 26 | + var $mWordCount = null; |
| 27 | + |
| 28 | + public function applyTemplate( $xml ) { // DONT TOUCH |
| 29 | + $snipmax = 50; |
| 30 | + $textlenght = 250; |
| 31 | + |
| 32 | + // get Size, Namespace, Wordcound, Date from XML: |
| 33 | + foreach ( $xml->arr as $doc ) { |
| 34 | + switch ( $doc[ 'name' ] ) { |
| 35 | + case 'text': |
| 36 | + $nsText = $doc->str; |
| 37 | + $this->mSize = ''; |
| 38 | + $this->mWordCount = count( $doc->str ); |
| 39 | + $textsnip = ''; |
| 40 | + $textsnipvar = 0; |
| 41 | + foreach ( $doc->str as $inner ) { |
| 42 | + $textsnipvar++; |
| 43 | + if ( $textsnipvar >= 4 && $textsnipvar <= $snipmax ) { |
| 44 | + $textsnip .= ' ' . $inner; |
| 45 | + } |
| 46 | + $textsnip = substr( $textsnip, 0, $textlenght ); |
| 47 | + $this->mSize = $this->mSize + strlen( $inner ); |
| 48 | + } |
| 49 | + $this->mSize = ( $this->mSize / 3 ); |
| 50 | + $this->mDate = $doc->date; |
| 51 | + break; |
| 52 | + } |
| 53 | + } |
| 54 | + |
| 55 | + // get Title, Interwiki from XML: |
| 56 | + foreach ( $xml->str as $docs ) { |
| 57 | + switch ( $docs[ 'name' ] ) { |
| 58 | + case 'pagetitle': |
| 59 | + $this->mTitle = $doc->str; |
| 60 | + break; |
| 61 | + case 'dbkey': |
| 62 | + $title = $doc->str; |
| 63 | + break; |
| 64 | + case 'interwiki': |
| 65 | + $this->mInterwiki = $doc->str; |
| 66 | + break; |
| 67 | + } |
| 68 | + } |
| 69 | + |
| 70 | + //get namespace from XML: |
| 71 | + foreach ( $xml->int as $doci ) { |
| 72 | + switch ( $doci[ 'name' ] ) { |
| 73 | + case 'namespace': |
| 74 | + $namespace = $doc->str; |
| 75 | + break; |
| 76 | + } |
| 77 | + } |
| 78 | + |
| 79 | + if ( !isset( $nsText ) ) { |
| 80 | + $nsText = $wgContLang->getNsText( $namespace ); |
| 81 | + } else { |
| 82 | + $nsText = urldecode( $nsText ); |
| 83 | + } |
| 84 | + |
| 85 | + // make score / relevance |
| 86 | + $this->mScore = $xml->float; |
| 87 | + |
| 88 | + // make Title |
| 89 | + $title = urldecode( $title ); |
| 90 | + $this->mTitle = Title::makeTitle( $namespace, $title ); |
| 91 | + |
| 92 | + // make Highlight - Title |
| 93 | + if ( $xml->highlight->title != '' ) { |
| 94 | + $this->mHighlightTitle = $xml->highlight->title; |
| 95 | + } else { |
| 96 | + $this->mHighlightTitle = ''; |
| 97 | + } |
| 98 | + |
| 99 | + // make Highlight - Text |
| 100 | + if ( $xml->highlight->Inhalt != '' ) { |
| 101 | + $this->mHighlightText = str_replace( '<em>', '<b>', $xml->highlight->Inhalt ); |
| 102 | + $this->mHighlightText = str_replace( '</em>', '</b>', $this->mHighlightText ); |
| 103 | + $this->mHighlightText .= '...'; |
| 104 | + } else { |
| 105 | + $this->mHighlightText = "NO HIGHLIGHTING TEXT FROM SOLR !"; |
| 106 | + |
| 107 | + // if nothing define itself ! |
| 108 | + // 4 example with |
| 109 | + // $this->mHighlightText = $textsnip; |
| 110 | + } |
| 111 | + |
| 112 | + return $this; |
| 113 | + } |
| 114 | + |
| 115 | +} |
| 116 | + |
| 117 | +?> |
Property changes on: trunk/extensions/SolrStore/templates/SolrSearchTemplate_Standart.php |
___________________________________________________________________ |
Added: svn:eol-style |
118 | 118 | + native |
Index: trunk/extensions/SolrStore/templates/SolrSearchTemplate_FIS.php |
— | — | @@ -1,336 +1,336 @@ |
2 | | -<?php
|
3 | | -/**
|
4 | | - * Dynamic Template 'FIS' -> Example
|
5 | | - *
|
6 | | - * Example Template
|
7 | | - * with : makeHighlightText and makeHighlightTitle functions
|
8 | | - *
|
9 | | - * to use this template add this peace of code to LocalSettings.php
|
10 | | - *
|
11 | | - * # define Template
|
12 | | - * $wgSolrTemplate = "_FIS";
|
13 | | - *
|
14 | | - *
|
15 | | - * @ingroup SolrStore
|
16 | | - * @path templates
|
17 | | - * @author Sascha Schueller
|
18 | | - */
|
19 | | -class SolrSearchTemplate_FIS {
|
20 | | -
|
21 | | - var $mTitle = null;
|
22 | | - var $mRedirectTitle = null;
|
23 | | - var $mHighlightSection = null;
|
24 | | - var $mSectionTitle = null;
|
25 | | - var $mDate = null;
|
26 | | - var $mScore = null;
|
27 | | - var $mSize = null;
|
28 | | - var $Inhalt_de_t = null;
|
29 | | - var $mHighlightText = null;
|
30 | | - var $mHighlightTitle = null;
|
31 | | - var $mWordCount = null;
|
32 | | -
|
33 | | - public function applyTemplate( $xml ) {
|
34 | | - global $wgSolrFields;
|
35 | | -
|
36 | | - $snipmax = 50;
|
37 | | - $textlenght = 1000;
|
38 | | - $textlenghteffective = 315;
|
39 | | -
|
40 | | - // Bugfix: clear the var!
|
41 | | - unset( $this->Inhalt_de_t );
|
42 | | -
|
43 | | - // get Size, Wordcound, Date, Inhalt_de_t from XML:
|
44 | | - foreach ( $xml->arr as $doc ) {
|
45 | | - switch ( $doc[ 'name' ] ) {
|
46 | | - case 'text':
|
47 | | - $nsText = $doc->str;
|
48 | | - $this->mSize = '';
|
49 | | - $this->mWordCount = count( $doc->str );
|
50 | | - $snipmax = 50;
|
51 | | - $textsnip = '';
|
52 | | - $textsnipvar = 0;
|
53 | | - foreach ( $doc->str as $inner ) {
|
54 | | - $textsnipvar++;
|
55 | | - if ( $textsnipvar >= 4 && $textsnipvar <= $snipmax ) {
|
56 | | - $textsnip .= ' ' . $inner;
|
57 | | - }
|
58 | | - $textsnip = substr( $textsnip, 0, $textlenght );
|
59 | | - $this->mSize = $this->mSize + strlen( $inner );
|
60 | | - }
|
61 | | - $this->mSize = ( $this->mSize / 3 );
|
62 | | - break;
|
63 | | -
|
64 | | - case 'Zuletzt geändert_dt':
|
65 | | - $this->mDate = $doc->date;
|
66 | | - break;
|
67 | | -
|
68 | | - case 'Inhalt de_t':
|
69 | | - $this->Inhalt_de_t[ ] = $doc->str;
|
70 | | - break;
|
71 | | - }
|
72 | | - }
|
73 | | -
|
74 | | - // get Title, Interwiki from XML:
|
75 | | - foreach ( $xml->str as $docs ) {
|
76 | | - switch ( $docs[ 'name' ] ) {
|
77 | | - case 'pagetitle':
|
78 | | - $this->mTitle = $doc->str;
|
79 | | - break;
|
80 | | - case 'dbkey':
|
81 | | - $title = $doc->str;
|
82 | | - break;
|
83 | | - case 'interwiki':
|
84 | | - $this->mInterwiki = $doc->str;
|
85 | | - break;
|
86 | | - }
|
87 | | - }
|
88 | | -
|
89 | | - //get namespace from XML:
|
90 | | - foreach ( $xml->int as $doci ) {
|
91 | | - switch ( $doci[ 'name' ] ) {
|
92 | | - case 'namespace':
|
93 | | - $namespace = $doc->str;
|
94 | | - break;
|
95 | | - }
|
96 | | - }
|
97 | | -
|
98 | | - if ( !isset( $nsText ) ) {
|
99 | | - $nsText = $wgContLang->getNsText( $namespace );
|
100 | | - } else {
|
101 | | - $nsText = urldecode( $nsText );
|
102 | | - }
|
103 | | -
|
104 | | - // make score / relevance
|
105 | | - $this->mScore = $xml->float;
|
106 | | -
|
107 | | - // make Title
|
108 | | - $title = urldecode( $title );
|
109 | | - $this->mTitle = Title::makeTitle( $namespace, $title );
|
110 | | -
|
111 | | - // make Highlight - Title
|
112 | | - $this->mHighlightTitle = $title;
|
113 | | - $this->makeHighlightTitle( $wgSolrFields, $title );
|
114 | | -
|
115 | | - $firstw = false;
|
116 | | -
|
117 | | - if ( isset( $this->Inhalt_de_t[ 0 ] ) != '' ) {
|
118 | | - $firstw = substr( $this->Inhalt_de_t[ 0 ], 0, strpos( $this->Inhalt_de_t[ 0 ], " " ) ); // test CUT textsnip:
|
119 | | - if ( $firstw != false ) {
|
120 | | - $textsnip = substr( $textsnip, strpos( $textsnip, $firstw ) );
|
121 | | - } else {
|
122 | | - if ( isset( $xml->highlight->Inhalt ) != '' ) {
|
123 | | - $firstw = substr( $xml->highlight->Inhalt, 0, strpos( $xml->highlight->Inhalt, " " ) ); // test CUT textsnip:
|
124 | | - if ( $firstw != false ) {
|
125 | | - $textsnip = substr( $textsnip, strpos( $textsnip, $firstw ) );
|
126 | | - }
|
127 | | - } else {
|
128 | | -
|
129 | | - }
|
130 | | - }
|
131 | | -
|
132 | | - // make Highlight - Text
|
133 | | - $this->mHighlightText = substr( $textsnip, 0, $textlenghteffective ) . "..."; // MAX LENG [INHALT]
|
134 | | - $this->makeHighlightText( $wgSolrFields, $textsnip ); // TEXTSNIP: Highlight the searching stuff:
|
135 | | - } else {
|
136 | | - $this->mHighlightText = "";
|
137 | | - }
|
138 | | -
|
139 | | - return $this;
|
140 | | - }
|
141 | | -
|
142 | | - private function cleanword( $w ) { // Bugfix 4 the highlighting system
|
143 | | - $str = array( "*", ">", "<", "/", '"' );
|
144 | | - $w = str_replace( $str, "", $w );
|
145 | | - return $w;
|
146 | | - }
|
147 | | -
|
148 | | - private function makeHighlightTitle( $wgSolrFields, $textsnipcut ) {
|
149 | | - for ( $tfields = 0; $tfields <= count( $wgSolrFields ) - 1; $tfields++ ) {
|
150 | | - foreach ( $wgSolrFields[ $tfields ] as $fieldcollection=>$inhalt ) {
|
151 | | - if ( $fieldcollection == 'mLable' ) { // get Solrfields
|
152 | | - foreach ( $inhalt as $feldname=>$lablename ) {
|
153 | | - $pos = false;
|
154 | | - $pos = strpos( $feldname, "solr" );
|
155 | | - if ( $pos !== false ) {
|
156 | | -
|
157 | | - if ( isset( $_REQUEST[ $feldname ] ) != '' && isset( $textsnipcut ) != '' ) {
|
158 | | - $wcount = substr_count( $_REQUEST[ $feldname ], " " ) + 1;
|
159 | | - unset( $leerat );
|
160 | | - for ( $wlpos = 0; $wlpos <= strlen( $_REQUEST[ $feldname ] ); $wlpos++ ) { // wo sind die leerzeichen ?
|
161 | | - if ( substr( $_REQUEST[ $feldname ], $wlpos, 1 ) == " " ) {
|
162 | | - $leerat[ ].=$wlpos;
|
163 | | - }
|
164 | | - }
|
165 | | - for ( $wpos = 1; $wpos <= $wcount; $wpos++ ) {
|
166 | | - $isschon = false;
|
167 | | - $pos1 = false;
|
168 | | - $tempc = false;
|
169 | | -
|
170 | | - if ( isset( $_REQUEST[ $feldname ] ) && $_REQUEST[ $feldname ] != '' ) {
|
171 | | - if ( $wpos == 1 ) { // First word: [OK]
|
172 | | - if ( $wcount > 1 ) { // more than 1 highlighting word:
|
173 | | - $highlighword = substr( $_REQUEST[ $feldname ], 0, $leerat[ $wpos - 1 ] );
|
174 | | - } else { // Only 1 word: [OK]
|
175 | | - $highlighword = substr( $_REQUEST[ $feldname ], 0 );
|
176 | | - }
|
177 | | - } elseif ( $wpos == $wcount ) { // Last word: [OK]
|
178 | | - $highlighword = substr( $_REQUEST[ $feldname ], $leerat[ $wpos - 2 ] + 1 );
|
179 | | - } elseif ( $wpos != $wcount && $wpos != 1 ) { // all words betwen first and last [OK]
|
180 | | - $highlighword = substr( $_REQUEST[ $feldname ], $leerat[ $wpos - 2 ] + 1, (($leerat[ $wpos - 1 ] - $leerat[ $wpos - 2 ]) - 1 ) );
|
181 | | - }
|
182 | | - $highlighword = $this->cleanword( $highlighword );
|
183 | | -
|
184 | | - if ( $highlighword != "" ) {
|
185 | | - if ( $highlighword == "b" || $highlighword == "B" ) {
|
186 | | - $this->mHighlightTitle = preg_replace( "#" . strtolower( $highlighword ) . "#", "<em><b>" . $highlighword . "</b></em>", $this->mHighlightTitle );
|
187 | | - } else {
|
188 | | -
|
189 | | - if ( strpos( strtolower( $this->mHighlightTitle ), strtolower( $highlighword ) ) > 0 ) { // Highlightwort nicht am anfang:
|
190 | | - $tempc = strlen( $highlighword );
|
191 | | - $pos1 = strpos( strtolower( $this->mHighlightTitle ), strtolower( $highlighword ) );
|
192 | | -
|
193 | | - if ( $pos1 != false && (substr_count( strtolower( $this->mHighlightTitle ), strtolower( $highlighword ) ) == 1) ) { // wenn Wort nur 1x vorhanden ist normal Highlighten:
|
194 | | - $tmpa = substr( $this->mHighlightTitle, 0, $pos1 );
|
195 | | - $tmpb = substr( $this->mHighlightTitle, ( $pos1 + $tempc ) );
|
196 | | -
|
197 | | - $this->mHighlightTitle = $tmpa . '<em><b>' . substr( $this->mHighlightTitle, $pos1, $tempc ) . '</b></em>' . $tmpb;
|
198 | | - }
|
199 | | - if ( $pos1 != false && (substr_count( strtolower( $this->mHighlightTitle ), strtolower( $highlighword ) ) >= 2) ) { // Wenn Wort mehrmals vorkommt, dann mehrmals highlighten:
|
200 | | - $highcount = substr_count( strtolower( $this->mHighlightTitle ), strtolower( $highlighword ) );
|
201 | | - unset( $offset );
|
202 | | - $offset[ 0 ] = 0;
|
203 | | - for ( $hc = 1; $hc <= $highcount; $hc++ ) {
|
204 | | - $tempc = strlen( $highlighword );
|
205 | | -
|
206 | | - if ( $hc == 1 ) {
|
207 | | - $pos1 = strpos( strtolower( $this->mHighlightTitle ), strtolower( $highlighword ) );
|
208 | | - } else {
|
209 | | - $pos1 = strpos( strtolower( $this->mHighlightTitle ), strtolower( $highlighword ), $offset[ $hc - 1 ] + 7 + $tempc );
|
210 | | - }
|
211 | | -
|
212 | | - $offset[ $hc ] = $pos1;
|
213 | | - $tmpa = substr( $this->mHighlightTitle, 0, $pos1 );
|
214 | | - $tmpb = substr( $this->mHighlightTitle, ( $pos1 + $tempc ) );
|
215 | | - $this->mHighlightTitle = $tmpa . '<em><b>' . substr( $this->mHighlightTitle, $pos1, $tempc ) . '</b></em>' . $tmpb;
|
216 | | - }
|
217 | | - }
|
218 | | - } else { // Erstes Wort im Satz:
|
219 | | - $tempc = strlen( $highlighword );
|
220 | | - $pos1 = strpos( strtolower( $this->mHighlightTitle ), strtolower( $highlighword ) );
|
221 | | -
|
222 | | - if ( $isschon == false && $pos1 == 0 && (strtolower( $highlighword ) == substr( strtolower( $this->mHighlightTitle ), 0, $tempc ) ) ) {
|
223 | | -//
|
224 | | - $tmpb = substr( $this->mHighlightTitle, $tempc );
|
225 | | -
|
226 | | - if ( strtolower( $highlighword ) == substr( strtolower( $this->mHighlightTitle ), 0, $tempc ) ) {
|
227 | | - $this->mHighlightTitle = '<em><b> ' . substr( $this->mHighlightTitle, 0, $tempc ) . '</b></em>' . $tmpb;
|
228 | | - $isschon = true;
|
229 | | - }
|
230 | | - }
|
231 | | - }
|
232 | | - }
|
233 | | - }
|
234 | | - }
|
235 | | - }
|
236 | | - }
|
237 | | - }
|
238 | | - }
|
239 | | - }
|
240 | | - }
|
241 | | - }
|
242 | | - }
|
243 | | -
|
244 | | - private function makeHighlightText( $wgSolrFields, $textsnipcut ) {
|
245 | | - for ( $tfields = 0; $tfields <= count( $wgSolrFields ) - 1; $tfields++ ) {
|
246 | | - foreach ( $wgSolrFields[ $tfields ] as $fieldcollection=>$inhalt ) {
|
247 | | - if ( $fieldcollection == 'mLable' ) { // get Solrfields
|
248 | | - foreach ( $inhalt as $feldname=>$lablename ) {
|
249 | | - $pos = false;
|
250 | | -
|
251 | | - $pos = strpos( $feldname, "solr" );
|
252 | | - if ( $pos !== false ) {
|
253 | | -
|
254 | | - if ( isset( $_REQUEST[ $feldname ] ) != '' && isset( $textsnipcut ) != '' ) {
|
255 | | - $wcount = substr_count( $_REQUEST[ $feldname ], " " ) + 1;
|
256 | | - unset( $leerat );
|
257 | | - for ( $wlpos = 0; $wlpos <= strlen( $_REQUEST[ $feldname ] ); $wlpos++ ) { // wo sind die leerzeichen ?
|
258 | | - if ( substr( $_REQUEST[ $feldname ], $wlpos, 1 ) == " " ) {
|
259 | | - $leerat[ ].=$wlpos;
|
260 | | - }
|
261 | | - }
|
262 | | - for ( $wpos = 1; $wpos <= $wcount; $wpos++ ) {
|
263 | | - $isschon = false;
|
264 | | - $pos1 = false;
|
265 | | - if ( isset( $_REQUEST[ $feldname ] ) && $_REQUEST[ $feldname ] != '' ) {
|
266 | | - if ( $wpos == 1 ) { // First word: [OK]
|
267 | | - if ( $wcount > 1 ) { // more than 1 highlighting word:
|
268 | | - $highlighword = substr( $_REQUEST[ $feldname ], 0, $leerat[ $wpos - 1 ] );
|
269 | | - } else { // Only 1 word: [OK]
|
270 | | - $highlighword = substr( $_REQUEST[ $feldname ], 0 );
|
271 | | - }
|
272 | | - } elseif ( $wpos == $wcount ) { // Last word: [OK]
|
273 | | - $highlighword = substr( $_REQUEST[ $feldname ], $leerat[ $wpos - 2 ] + 1 );
|
274 | | - } elseif ( $wpos != $wcount && $wpos != 1 ) { // all words betwen first and last [OK]
|
275 | | - $highlighword = substr( $_REQUEST[ $feldname ], $leerat[ $wpos - 2 ] + 1, (($leerat[ $wpos - 1 ] - $leerat[ $wpos - 2 ]) - 1 ) );
|
276 | | - }
|
277 | | -
|
278 | | - $highlighword = $this->cleanword( $highlighword );
|
279 | | -
|
280 | | - if ( $highlighword != "" ) {
|
281 | | - if ( $highlighword == "b" || $highlighword == "B" ) {
|
282 | | - $this->mHighlightText = preg_replace( "#" . strtolower( $highlighword ) . "#", "<em><b>" . $highlighword . "</b></em>", $this->mHighlightText );
|
283 | | - } else {
|
284 | | -
|
285 | | - if ( strpos( strtolower( $this->mHighlightText ), strtolower( $highlighword ) ) > 0 ) {
|
286 | | -
|
287 | | - $tempc = strlen( $highlighword );
|
288 | | - $pos1 = strpos( strtolower( $this->mHighlightText ), strtolower( $highlighword ) );
|
289 | | -
|
290 | | - if ( $pos1 != false && (substr_count( strtolower( $this->mHighlightText ), strtolower( $highlighword ) ) == 1) ) { // wenn Wort nur 1x vorhanden ist normal Highlighten:
|
291 | | - $tmpa = substr( $this->mHighlightText, 0, $pos1 );
|
292 | | - $tmpb = substr( $this->mHighlightText, ( $pos1 + $tempc ) );
|
293 | | -
|
294 | | - $this->mHighlightText = $tmpa . '<em><b>' . substr( $this->mHighlightText, $pos1, $tempc ) . '</b></em>' . $tmpb;
|
295 | | - }
|
296 | | - if ( $pos1 != false && (substr_count( strtolower( $this->mHighlightText ), strtolower( $highlighword ) ) >= 2) ) { // Wenn Wort mehrmals vorkommt, dann mehrmals highlighten:
|
297 | | - $highcount = substr_count( strtolower( $this->mHighlightText ), strtolower( $highlighword ) );
|
298 | | - unset( $offset );
|
299 | | - $offset[ 0 ] = 0;
|
300 | | - for ( $hc = 1; $hc <= $highcount; $hc++ ) {
|
301 | | - $tempc = strlen( $highlighword );
|
302 | | - if ( $hc == 1 ) {
|
303 | | - $pos1 = strpos( strtolower( $this->mHighlightText ), strtolower( $highlighword ) );
|
304 | | - } else {
|
305 | | - $pos1 = strpos( strtolower( $this->mHighlightText ), strtolower( $highlighword ), $offset[ $hc - 1 ] + 7 + $tempc );
|
306 | | - }
|
307 | | - $offset[ $hc ] = $pos1;
|
308 | | - $tmpa = substr( $this->mHighlightText, 0, $pos1 );
|
309 | | - $tmpb = substr( $this->mHighlightText, ( $pos1 + $tempc ) );
|
310 | | - $this->mHighlightText = $tmpa . '<em><b>' . substr( $this->mHighlightText, $pos1, $tempc ) . '</b></em>' . $tmpb;
|
311 | | - }
|
312 | | - }
|
313 | | - } else {
|
314 | | - $tempc = strlen( $highlighword );
|
315 | | - $pos1 = strpos( strtolower( $this->mHighlightText ), strtolower( $highlighword ) );
|
316 | | -
|
317 | | - if ( $isschon == false && $pos1 == 0 && (strtolower( $highlighword ) == substr( strtolower( $this->mHighlightText ), 0, $tempc ) ) ) {
|
318 | | - $tmpb = substr( $this->mHighlightText, $tempc );
|
319 | | - $this->mHighlightText = '<em><b> ' . substr( $this->mHighlightText, 0, $tempc ) . '</b></em>' . $tmpb;
|
320 | | - $isschon = true;
|
321 | | - }
|
322 | | - }
|
323 | | - }
|
324 | | - }
|
325 | | - }
|
326 | | - }
|
327 | | - }
|
328 | | - }
|
329 | | - }
|
330 | | - }
|
331 | | - }
|
332 | | - }
|
333 | | - }
|
334 | | -
|
335 | | -}
|
336 | | -
|
337 | | -?>
|
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Dynamic Template 'FIS' -> Example |
| 5 | + * |
| 6 | + * Example Template |
| 7 | + * with : makeHighlightText and makeHighlightTitle functions |
| 8 | + * |
| 9 | + * to use this template add this peace of code to LocalSettings.php |
| 10 | + * |
| 11 | + * # define Template |
| 12 | + * $wgSolrTemplate = "_FIS"; |
| 13 | + * |
| 14 | + * |
| 15 | + * @ingroup SolrStore |
| 16 | + * @path templates |
| 17 | + * @author Sascha Schueller |
| 18 | + */ |
| 19 | +class SolrSearchTemplate_FIS { |
| 20 | + |
| 21 | + var $mTitle = null; |
| 22 | + var $mRedirectTitle = null; |
| 23 | + var $mHighlightSection = null; |
| 24 | + var $mSectionTitle = null; |
| 25 | + var $mDate = null; |
| 26 | + var $mScore = null; |
| 27 | + var $mSize = null; |
| 28 | + var $Inhalt_de_t = null; |
| 29 | + var $mHighlightText = null; |
| 30 | + var $mHighlightTitle = null; |
| 31 | + var $mWordCount = null; |
| 32 | + |
| 33 | + public function applyTemplate( $xml ) { |
| 34 | + global $wgSolrFields; |
| 35 | + |
| 36 | + $snipmax = 50; |
| 37 | + $textlenght = 1000; |
| 38 | + $textlenghteffective = 315; |
| 39 | + |
| 40 | + // Bugfix: clear the var! |
| 41 | + unset( $this->Inhalt_de_t ); |
| 42 | + |
| 43 | + // get Size, Wordcound, Date, Inhalt_de_t from XML: |
| 44 | + foreach ( $xml->arr as $doc ) { |
| 45 | + switch ( $doc[ 'name' ] ) { |
| 46 | + case 'text': |
| 47 | + $nsText = $doc->str; |
| 48 | + $this->mSize = ''; |
| 49 | + $this->mWordCount = count( $doc->str ); |
| 50 | + $snipmax = 50; |
| 51 | + $textsnip = ''; |
| 52 | + $textsnipvar = 0; |
| 53 | + foreach ( $doc->str as $inner ) { |
| 54 | + $textsnipvar++; |
| 55 | + if ( $textsnipvar >= 4 && $textsnipvar <= $snipmax ) { |
| 56 | + $textsnip .= ' ' . $inner; |
| 57 | + } |
| 58 | + $textsnip = substr( $textsnip, 0, $textlenght ); |
| 59 | + $this->mSize = $this->mSize + strlen( $inner ); |
| 60 | + } |
| 61 | + $this->mSize = ( $this->mSize / 3 ); |
| 62 | + break; |
| 63 | + |
| 64 | + case 'Zuletzt geändert_dt': |
| 65 | + $this->mDate = $doc->date; |
| 66 | + break; |
| 67 | + |
| 68 | + case 'Inhalt de_t': |
| 69 | + $this->Inhalt_de_t[ ] = $doc->str; |
| 70 | + break; |
| 71 | + } |
| 72 | + } |
| 73 | + |
| 74 | + // get Title, Interwiki from XML: |
| 75 | + foreach ( $xml->str as $docs ) { |
| 76 | + switch ( $docs[ 'name' ] ) { |
| 77 | + case 'pagetitle': |
| 78 | + $this->mTitle = $doc->str; |
| 79 | + break; |
| 80 | + case 'dbkey': |
| 81 | + $title = $doc->str; |
| 82 | + break; |
| 83 | + case 'interwiki': |
| 84 | + $this->mInterwiki = $doc->str; |
| 85 | + break; |
| 86 | + } |
| 87 | + } |
| 88 | + |
| 89 | + //get namespace from XML: |
| 90 | + foreach ( $xml->int as $doci ) { |
| 91 | + switch ( $doci[ 'name' ] ) { |
| 92 | + case 'namespace': |
| 93 | + $namespace = $doc->str; |
| 94 | + break; |
| 95 | + } |
| 96 | + } |
| 97 | + |
| 98 | + if ( !isset( $nsText ) ) { |
| 99 | + $nsText = $wgContLang->getNsText( $namespace ); |
| 100 | + } else { |
| 101 | + $nsText = urldecode( $nsText ); |
| 102 | + } |
| 103 | + |
| 104 | + // make score / relevance |
| 105 | + $this->mScore = $xml->float; |
| 106 | + |
| 107 | + // make Title |
| 108 | + $title = urldecode( $title ); |
| 109 | + $this->mTitle = Title::makeTitle( $namespace, $title ); |
| 110 | + |
| 111 | + // make Highlight - Title |
| 112 | + $this->mHighlightTitle = $title; |
| 113 | + $this->makeHighlightTitle( $wgSolrFields, $title ); |
| 114 | + |
| 115 | + $firstw = false; |
| 116 | + |
| 117 | + if ( isset( $this->Inhalt_de_t[ 0 ] ) != '' ) { |
| 118 | + $firstw = substr( $this->Inhalt_de_t[ 0 ], 0, strpos( $this->Inhalt_de_t[ 0 ], " " ) ); // test CUT textsnip: |
| 119 | + if ( $firstw != false ) { |
| 120 | + $textsnip = substr( $textsnip, strpos( $textsnip, $firstw ) ); |
| 121 | + } else { |
| 122 | + if ( isset( $xml->highlight->Inhalt ) != '' ) { |
| 123 | + $firstw = substr( $xml->highlight->Inhalt, 0, strpos( $xml->highlight->Inhalt, " " ) ); // test CUT textsnip: |
| 124 | + if ( $firstw != false ) { |
| 125 | + $textsnip = substr( $textsnip, strpos( $textsnip, $firstw ) ); |
| 126 | + } |
| 127 | + } else { |
| 128 | + |
| 129 | + } |
| 130 | + } |
| 131 | + |
| 132 | + // make Highlight - Text |
| 133 | + $this->mHighlightText = substr( $textsnip, 0, $textlenghteffective ) . "..."; // MAX LENG [INHALT] |
| 134 | + $this->makeHighlightText( $wgSolrFields, $textsnip ); // TEXTSNIP: Highlight the searching stuff: |
| 135 | + } else { |
| 136 | + $this->mHighlightText = ""; |
| 137 | + } |
| 138 | + |
| 139 | + return $this; |
| 140 | + } |
| 141 | + |
| 142 | + private function cleanword( $w ) { // Bugfix 4 the highlighting system |
| 143 | + $str = array( "*", ">", "<", "/", '"' ); |
| 144 | + $w = str_replace( $str, "", $w ); |
| 145 | + return $w; |
| 146 | + } |
| 147 | + |
| 148 | + private function makeHighlightTitle( $wgSolrFields, $textsnipcut ) { |
| 149 | + for ( $tfields = 0; $tfields <= count( $wgSolrFields ) - 1; $tfields++ ) { |
| 150 | + foreach ( $wgSolrFields[ $tfields ] as $fieldcollection=>$inhalt ) { |
| 151 | + if ( $fieldcollection == 'mLable' ) { // get Solrfields |
| 152 | + foreach ( $inhalt as $feldname=>$lablename ) { |
| 153 | + $pos = false; |
| 154 | + $pos = strpos( $feldname, "solr" ); |
| 155 | + if ( $pos !== false ) { |
| 156 | + |
| 157 | + if ( isset( $_REQUEST[ $feldname ] ) != '' && isset( $textsnipcut ) != '' ) { |
| 158 | + $wcount = substr_count( $_REQUEST[ $feldname ], " " ) + 1; |
| 159 | + unset( $leerat ); |
| 160 | + for ( $wlpos = 0; $wlpos <= strlen( $_REQUEST[ $feldname ] ); $wlpos++ ) { // wo sind die leerzeichen ? |
| 161 | + if ( substr( $_REQUEST[ $feldname ], $wlpos, 1 ) == " " ) { |
| 162 | + $leerat[ ].=$wlpos; |
| 163 | + } |
| 164 | + } |
| 165 | + for ( $wpos = 1; $wpos <= $wcount; $wpos++ ) { |
| 166 | + $isschon = false; |
| 167 | + $pos1 = false; |
| 168 | + $tempc = false; |
| 169 | + |
| 170 | + if ( isset( $_REQUEST[ $feldname ] ) && $_REQUEST[ $feldname ] != '' ) { |
| 171 | + if ( $wpos == 1 ) { // First word: [OK] |
| 172 | + if ( $wcount > 1 ) { // more than 1 highlighting word: |
| 173 | + $highlighword = substr( $_REQUEST[ $feldname ], 0, $leerat[ $wpos - 1 ] ); |
| 174 | + } else { // Only 1 word: [OK] |
| 175 | + $highlighword = substr( $_REQUEST[ $feldname ], 0 ); |
| 176 | + } |
| 177 | + } elseif ( $wpos == $wcount ) { // Last word: [OK] |
| 178 | + $highlighword = substr( $_REQUEST[ $feldname ], $leerat[ $wpos - 2 ] + 1 ); |
| 179 | + } elseif ( $wpos != $wcount && $wpos != 1 ) { // all words betwen first and last [OK] |
| 180 | + $highlighword = substr( $_REQUEST[ $feldname ], $leerat[ $wpos - 2 ] + 1, (($leerat[ $wpos - 1 ] - $leerat[ $wpos - 2 ]) - 1 ) ); |
| 181 | + } |
| 182 | + $highlighword = $this->cleanword( $highlighword ); |
| 183 | + |
| 184 | + if ( $highlighword != "" ) { |
| 185 | + if ( $highlighword == "b" || $highlighword == "B" ) { |
| 186 | + $this->mHighlightTitle = preg_replace( "#" . strtolower( $highlighword ) . "#", "<em><b>" . $highlighword . "</b></em>", $this->mHighlightTitle ); |
| 187 | + } else { |
| 188 | + |
| 189 | + if ( strpos( strtolower( $this->mHighlightTitle ), strtolower( $highlighword ) ) > 0 ) { // Highlightwort nicht am anfang: |
| 190 | + $tempc = strlen( $highlighword ); |
| 191 | + $pos1 = strpos( strtolower( $this->mHighlightTitle ), strtolower( $highlighword ) ); |
| 192 | + |
| 193 | + if ( $pos1 != false && (substr_count( strtolower( $this->mHighlightTitle ), strtolower( $highlighword ) ) == 1) ) { // wenn Wort nur 1x vorhanden ist normal Highlighten: |
| 194 | + $tmpa = substr( $this->mHighlightTitle, 0, $pos1 ); |
| 195 | + $tmpb = substr( $this->mHighlightTitle, ( $pos1 + $tempc ) ); |
| 196 | + |
| 197 | + $this->mHighlightTitle = $tmpa . '<em><b>' . substr( $this->mHighlightTitle, $pos1, $tempc ) . '</b></em>' . $tmpb; |
| 198 | + } |
| 199 | + if ( $pos1 != false && (substr_count( strtolower( $this->mHighlightTitle ), strtolower( $highlighword ) ) >= 2) ) { // Wenn Wort mehrmals vorkommt, dann mehrmals highlighten: |
| 200 | + $highcount = substr_count( strtolower( $this->mHighlightTitle ), strtolower( $highlighword ) ); |
| 201 | + unset( $offset ); |
| 202 | + $offset[ 0 ] = 0; |
| 203 | + for ( $hc = 1; $hc <= $highcount; $hc++ ) { |
| 204 | + $tempc = strlen( $highlighword ); |
| 205 | + |
| 206 | + if ( $hc == 1 ) { |
| 207 | + $pos1 = strpos( strtolower( $this->mHighlightTitle ), strtolower( $highlighword ) ); |
| 208 | + } else { |
| 209 | + $pos1 = strpos( strtolower( $this->mHighlightTitle ), strtolower( $highlighword ), $offset[ $hc - 1 ] + 7 + $tempc ); |
| 210 | + } |
| 211 | + |
| 212 | + $offset[ $hc ] = $pos1; |
| 213 | + $tmpa = substr( $this->mHighlightTitle, 0, $pos1 ); |
| 214 | + $tmpb = substr( $this->mHighlightTitle, ( $pos1 + $tempc ) ); |
| 215 | + $this->mHighlightTitle = $tmpa . '<em><b>' . substr( $this->mHighlightTitle, $pos1, $tempc ) . '</b></em>' . $tmpb; |
| 216 | + } |
| 217 | + } |
| 218 | + } else { // Erstes Wort im Satz: |
| 219 | + $tempc = strlen( $highlighword ); |
| 220 | + $pos1 = strpos( strtolower( $this->mHighlightTitle ), strtolower( $highlighword ) ); |
| 221 | + |
| 222 | + if ( $isschon == false && $pos1 == 0 && (strtolower( $highlighword ) == substr( strtolower( $this->mHighlightTitle ), 0, $tempc ) ) ) { |
| 223 | +// |
| 224 | + $tmpb = substr( $this->mHighlightTitle, $tempc ); |
| 225 | + |
| 226 | + if ( strtolower( $highlighword ) == substr( strtolower( $this->mHighlightTitle ), 0, $tempc ) ) { |
| 227 | + $this->mHighlightTitle = '<em><b> ' . substr( $this->mHighlightTitle, 0, $tempc ) . '</b></em>' . $tmpb; |
| 228 | + $isschon = true; |
| 229 | + } |
| 230 | + } |
| 231 | + } |
| 232 | + } |
| 233 | + } |
| 234 | + } |
| 235 | + } |
| 236 | + } |
| 237 | + } |
| 238 | + } |
| 239 | + } |
| 240 | + } |
| 241 | + } |
| 242 | + } |
| 243 | + |
| 244 | + private function makeHighlightText( $wgSolrFields, $textsnipcut ) { |
| 245 | + for ( $tfields = 0; $tfields <= count( $wgSolrFields ) - 1; $tfields++ ) { |
| 246 | + foreach ( $wgSolrFields[ $tfields ] as $fieldcollection=>$inhalt ) { |
| 247 | + if ( $fieldcollection == 'mLable' ) { // get Solrfields |
| 248 | + foreach ( $inhalt as $feldname=>$lablename ) { |
| 249 | + $pos = false; |
| 250 | + |
| 251 | + $pos = strpos( $feldname, "solr" ); |
| 252 | + if ( $pos !== false ) { |
| 253 | + |
| 254 | + if ( isset( $_REQUEST[ $feldname ] ) != '' && isset( $textsnipcut ) != '' ) { |
| 255 | + $wcount = substr_count( $_REQUEST[ $feldname ], " " ) + 1; |
| 256 | + unset( $leerat ); |
| 257 | + for ( $wlpos = 0; $wlpos <= strlen( $_REQUEST[ $feldname ] ); $wlpos++ ) { // wo sind die leerzeichen ? |
| 258 | + if ( substr( $_REQUEST[ $feldname ], $wlpos, 1 ) == " " ) { |
| 259 | + $leerat[ ].=$wlpos; |
| 260 | + } |
| 261 | + } |
| 262 | + for ( $wpos = 1; $wpos <= $wcount; $wpos++ ) { |
| 263 | + $isschon = false; |
| 264 | + $pos1 = false; |
| 265 | + if ( isset( $_REQUEST[ $feldname ] ) && $_REQUEST[ $feldname ] != '' ) { |
| 266 | + if ( $wpos == 1 ) { // First word: [OK] |
| 267 | + if ( $wcount > 1 ) { // more than 1 highlighting word: |
| 268 | + $highlighword = substr( $_REQUEST[ $feldname ], 0, $leerat[ $wpos - 1 ] ); |
| 269 | + } else { // Only 1 word: [OK] |
| 270 | + $highlighword = substr( $_REQUEST[ $feldname ], 0 ); |
| 271 | + } |
| 272 | + } elseif ( $wpos == $wcount ) { // Last word: [OK] |
| 273 | + $highlighword = substr( $_REQUEST[ $feldname ], $leerat[ $wpos - 2 ] + 1 ); |
| 274 | + } elseif ( $wpos != $wcount && $wpos != 1 ) { // all words betwen first and last [OK] |
| 275 | + $highlighword = substr( $_REQUEST[ $feldname ], $leerat[ $wpos - 2 ] + 1, (($leerat[ $wpos - 1 ] - $leerat[ $wpos - 2 ]) - 1 ) ); |
| 276 | + } |
| 277 | + |
| 278 | + $highlighword = $this->cleanword( $highlighword ); |
| 279 | + |
| 280 | + if ( $highlighword != "" ) { |
| 281 | + if ( $highlighword == "b" || $highlighword == "B" ) { |
| 282 | + $this->mHighlightText = preg_replace( "#" . strtolower( $highlighword ) . "#", "<em><b>" . $highlighword . "</b></em>", $this->mHighlightText ); |
| 283 | + } else { |
| 284 | + |
| 285 | + if ( strpos( strtolower( $this->mHighlightText ), strtolower( $highlighword ) ) > 0 ) { |
| 286 | + |
| 287 | + $tempc = strlen( $highlighword ); |
| 288 | + $pos1 = strpos( strtolower( $this->mHighlightText ), strtolower( $highlighword ) ); |
| 289 | + |
| 290 | + if ( $pos1 != false && (substr_count( strtolower( $this->mHighlightText ), strtolower( $highlighword ) ) == 1) ) { // wenn Wort nur 1x vorhanden ist normal Highlighten: |
| 291 | + $tmpa = substr( $this->mHighlightText, 0, $pos1 ); |
| 292 | + $tmpb = substr( $this->mHighlightText, ( $pos1 + $tempc ) ); |
| 293 | + |
| 294 | + $this->mHighlightText = $tmpa . '<em><b>' . substr( $this->mHighlightText, $pos1, $tempc ) . '</b></em>' . $tmpb; |
| 295 | + } |
| 296 | + if ( $pos1 != false && (substr_count( strtolower( $this->mHighlightText ), strtolower( $highlighword ) ) >= 2) ) { // Wenn Wort mehrmals vorkommt, dann mehrmals highlighten: |
| 297 | + $highcount = substr_count( strtolower( $this->mHighlightText ), strtolower( $highlighword ) ); |
| 298 | + unset( $offset ); |
| 299 | + $offset[ 0 ] = 0; |
| 300 | + for ( $hc = 1; $hc <= $highcount; $hc++ ) { |
| 301 | + $tempc = strlen( $highlighword ); |
| 302 | + if ( $hc == 1 ) { |
| 303 | + $pos1 = strpos( strtolower( $this->mHighlightText ), strtolower( $highlighword ) ); |
| 304 | + } else { |
| 305 | + $pos1 = strpos( strtolower( $this->mHighlightText ), strtolower( $highlighword ), $offset[ $hc - 1 ] + 7 + $tempc ); |
| 306 | + } |
| 307 | + $offset[ $hc ] = $pos1; |
| 308 | + $tmpa = substr( $this->mHighlightText, 0, $pos1 ); |
| 309 | + $tmpb = substr( $this->mHighlightText, ( $pos1 + $tempc ) ); |
| 310 | + $this->mHighlightText = $tmpa . '<em><b>' . substr( $this->mHighlightText, $pos1, $tempc ) . '</b></em>' . $tmpb; |
| 311 | + } |
| 312 | + } |
| 313 | + } else { |
| 314 | + $tempc = strlen( $highlighword ); |
| 315 | + $pos1 = strpos( strtolower( $this->mHighlightText ), strtolower( $highlighword ) ); |
| 316 | + |
| 317 | + if ( $isschon == false && $pos1 == 0 && (strtolower( $highlighword ) == substr( strtolower( $this->mHighlightText ), 0, $tempc ) ) ) { |
| 318 | + $tmpb = substr( $this->mHighlightText, $tempc ); |
| 319 | + $this->mHighlightText = '<em><b> ' . substr( $this->mHighlightText, 0, $tempc ) . '</b></em>' . $tmpb; |
| 320 | + $isschon = true; |
| 321 | + } |
| 322 | + } |
| 323 | + } |
| 324 | + } |
| 325 | + } |
| 326 | + } |
| 327 | + } |
| 328 | + } |
| 329 | + } |
| 330 | + } |
| 331 | + } |
| 332 | + } |
| 333 | + } |
| 334 | + |
| 335 | +} |
| 336 | + |
| 337 | +?> |
Property changes on: trunk/extensions/SolrStore/templates/SolrSearchTemplate_FIS.php |
___________________________________________________________________ |
Added: svn:eol-style |
338 | 338 | + native |