Schrift
[thread]7412[/thread]

Arge Probleme mit SWISH-E: läuft nicht...



<< >> 2 Einträge, 1 Seite
steinwolf
 2005-10-29 17:57
#59488 #59488
User since
2003-08-04
367 Artikel
BenutzerIn
[default_avatar]
Hallo,

die Homepage von swish-e (www.swish-e.org) hilft mir nicht großartig weiter. Im Prinzip habe ich einfach nur das Problem, dass ich das Programm nicht zum Laufen bekomme.

Da wären einige grundsätzliche Fragen:

1. Läuft SWISH-E als Dienst wie beispielsweise MySQL oder Apache? Oder wird das Programm immer nur bei einer DAtenbankabfrage aufgerufen?

2. Muss ich SWISH-E irgendwie in der Apache Config verankern? Kann ich mir ehrlich gesagt nicht vorstellen, da dies ja für mysql auch nicht nötig ist.

3. Ich habe nun ein Beispielscript:
Und ich denke, an dieser Stelle hakt es:
my $swished = 'http://localhost:8080/swished/'; #'http://peknet.com:8080/swished/'; # URL of server

ich habe swished in derselben Verzeichnisebene installiert wie xampp.
Also
.
..
xampp
swish-ed


Kann mir jemand weiterhelfen?
Ich verzweifle HUAAA!


Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
#!D:/perl/bin/perl -w

use CGI::Carp qw (fatalsToBrowser);

use strict;
use warnings;
use CGI qw/ -newstyle_urls /;
use SWISH::API::Remote;
use HTML::HiLiter;

my $Version = 0.03;
# version history
# =====================
# 0.01 -- initial
# 0.02 -- fixed security hole and pager bug; thanks to [EMAIL=moseley@hank.org]moseley@hank.org[/EMAIL]
# 0.03 -- added comments about sman.conf modifications
#

# some -T sanity
#

$ENV{'PATH'} = '/bin:/usr/bin:/usr/local/bin';
delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};


# this example assumes the Sman index at http://peknet.com:8080/
# if we have no params, print search form
# if we have params, check for mode
#
# Assumes Sman version 0.9.3 or later
# NOTE: sman.conf must be modified from default to include these 3 changes:
# 1. add swishdocpath to the SWISHE_MetaNames line
# 2. add this line: SWISHE_MaxWordLimit 200
# 3. add '/' to SWISHE_WordCharacters
#

my $cgi = CGI->new; # create CGI object

my $def_start = 0; # first result
my $Max = 10; # default num of results per page
my $swished = 'http://localhost:8080/swished/'; #'http://peknet.com:8080/swished/'; # URL of server
my $index = 'DEFAULT'; # which index to search
my $props = "swishrank,swishreccount,swishdocpath,swishtitle,sec,desc"; # properties to return


# always print header and form
print $cgi->header,
$cgi->start_html(-title=>'Suchengine',
-style=>{src=>'http://peknet.com/peknet.css'}),
$cgi->start_form(-method=>'get'),
search_form( $cgi );

# check for params and act
unless ( $cgi->param && $cgi->param('q') ) {

# a little description
print <<EOF;
This SWISHED example CGI script uses SWISH::API::Remote and HTML::HiLiter.
<p>
It searches the Sman SWISH-E index at peknet.com, which includes man pages
for a RedHat Linux 7.2 installation.
<p>
You can see the full description of this example, including the source code,
at <a href='http://swishewiki.org/index.php/SWISHED_Demo'>http://swishewiki.org/index.php/SWISHED_Demo</a>

EOF

exit;
}

my $mode = $cgi->param('mode') || die "need mode to run!\n";

if ( $mode eq 'show' ) {
# if we want to display a search result,

# check for valid file in index
# NOTE that 'swishdocpath' must be added to this line:
# SWISHE_MetaNames
# in Sman config

my $file = $cgi->param('f');
my $debug = $cgi->param('debug') || 0; # default is OFF
my $q = 'swishdocpath=' . $file;
my $remote = SWISH::API::Remote->new( $swished, $index, { DEBUG=>$debug});
my $results = $remote->Execute( $q );

if ($results->Error()) {
print $results->ErrorString();
exit;
} elsif ( ! $results->Hits() ) {
print "No such file in index: $file";
exit;
}


# convert it to HTML and capture in buffer
# then hand it to HTML::HiLiter for highlighting and printing

my $buf = man2html( $file );
my $hiliter = HTML::HiLiter->new;
my $query = $cgi->param('q');
$hiliter->Queries( $query );
$hiliter->CSS;
$hiliter->Run( \$buf );


} elsif ( $mode eq 'search' ) {
# run search and display results

my $q = $cgi->param('q');
my $b = $cgi->param('b') || $def_start; # default is to start at first hit
my $max = $cgi->param('max') || $Max;
my $debug = $cgi->param('debug') || 0; # default is OFF

my $remote = SWISH::API::Remote->new( $swished, $index, { DEBUG=>$debug});
my $results = $remote->Execute( $q , {BEGIN=>$b, PROPERTIES=>$props, MAX=>$max} );

if ($results->Error()) {
print $results->ErrorString();
exit;
}

# Hits are base1
# results are base0
# we want to print base1 and search base0

my $last_hit = $results->Hits();
my $first_range = $b + 1;
my $last_range = $b + $max;
$last_range = $last_hit if $last_range > $last_hit;

printf("Fetched %d - %d of %d hits for search on '%s'\n",
$first_range, $last_range, $last_hit, $q);

print $cgi->br, 'Page: ', pager( $cgi, $b, $last_range - 1, $max, $last_hit );

my $hiliter = HTML::HiLiter->new;
$hiliter->Queries( $q );
$hiliter->Inline;

while ( my $r = $results->NextResult() ) {
print $hiliter->hilite( myresult( $cgi,$r ) );
}


} else {

print "no such mode: $mode\n";

}

# always close up
print $cgi->endform, $cgi->end_html;

exit;


############################
# routines

sub man2html
{

my $f = shift;
# do some taint checking/sanity on file
my $clean;

if ( $f =~ m!^([/\w\.\-\:]+)$! ) {
$clean = $1;
} else {

print "'$f' doesn't look clean\n";
exit;

}

unless ( -r $clean ) {

print "$clean is not readable: $!\n";
exit;

}

# work in /tmp

chdir '/tmp';

# convert and slurp into buffer

my $cmd = $clean =~ m/\.gz$/
? "gunzip -c $clean | groff -Thtml -mandoc -t -e - "
: "groff -Thtml -mandoc -t -e $clean";

local $/;
my $buf = `$cmd`;
unless ( $? ) {

return $buf;

} else {

print "conversion error: $!\n";
exit;

}


}

sub search_form
{
my $cgi = shift;

return $cgi->p(
$cgi->a({-href=>$cgi->url()}, 'Home' ),
$cgi->br,
'Search Linux man pages: ',
$cgi->textfield(

-name=>'q',

-default=>$cgi->param('q') || '',

-override=>1,

-size=>50,

-maxlength=>80),
$cgi->submit(

-name=>'mode',

-value=>'search'

),
$cgi->checkbox(
-name=>'debug',
-value=>1,
-checked=>0
),

$cgi->hr
);

}

sub myresult
{
my ($cgi,$result) = @_;

my $f = $result->Property('swishdocpath');

return $cgi->p(
$cgi->font({-size=>'-1'},
'[' . $result->Property('swishreccount') . ']'
),
'&nbsp;',
$cgi->a({-href=>

$cgi->url.

'?mode=show'.

';f='.$f.

';q='.$cgi->param('q')

},

$result->Property('swishtitle'),

'('.$result->Property('sec').')',

),
'&nbsp;--&nbsp;',
# if we had a swishdescription, we might snip that here too
$result->Property('desc'),

# rank in green
'&nbsp;&»&nbsp;',
$cgi->font({-color=>'green'},
$result->Property('swishrank')
),

);


}

sub pager
{
# this feels a little crude but it works...

my $cgi = shift;
my $start = shift;
my $end = shift;
my $max = shift;
my $hits = shift;

# number of pages is hits / max, rounded up
my $N = $hits / $max;
$N = int($N) + 1 if $N =~ m/\./;

my $baseurl = $cgi->url . '?q=' . $cgi->param('q') . ';mode=search';
# where are we now?
# page 1 = 0 .. ( $max*1 -1 )
# page 2 = $max+1 .. ( $max*2 -1 )
# page 3 = $max*2+1 .. ( $max*3 -1 )
# only show X pages, with ... to indicate more
# we want thispage, plus 4 on either side

my $thispage = int( $end / $max + 1 );
my @links;
my $page = $thispage - 4;
$page = 0 if $page < 0;
my $X = 10;
# always include first page
if ( $thispage > 4 ) {
push(@links,$cgi->a({href=>$baseurl.";max=$max;b=$def_start"},'1'));
push(@links,'...') unless $thispage == 5;
}

while ( scalar(@links) <= $N ) {
$page++;
my $b = $max * ($page - 1);
# print "Thispage: $thispage --- Page: $page <br>\n";
if ( $page == $thispage ) {
push(@links, $cgi->b( $page ));
} else {
push(@links, $cgi->a({href=>$baseurl.";max=$max;b=$b"},$page) );
}
last if $page >= $N;
last if scalar(@links) >= $X;
}

# always include last page
unless ( $page == $N ) {
my $lastpg = $max * ($N - 1);
push(@links,'...') unless $thispage == ($N - 5);
push(@links,$cgi->a({href=>$baseurl.";max=$max;b=$lastpg"},$N) );
}

return join '&nbsp;', @links;

}




mfg
steinwolf
"Did you know? You can use your old motor oil to fertilize your lawn." - Blinkster - Professionelles EDV Forum
sri
 2005-10-30 03:23
#59489 #59489
User since
2004-01-29
828 Artikel
BenutzerIn
[Homepage] [default_avatar]
<< >> 2 Einträge, 1 Seite



View all threads created 2005-10-29 17:57.