diff options
Diffstat (limited to 'khelpcenter/searchhandlers')
-rw-r--r-- | khelpcenter/searchhandlers/Makefile.am | 10 | ||||
-rw-r--r-- | khelpcenter/searchhandlers/README.searchhandlers | 61 | ||||
-rw-r--r-- | khelpcenter/searchhandlers/docbook.desktop | 6 | ||||
-rw-r--r-- | khelpcenter/searchhandlers/htdig.desktop | 6 | ||||
-rw-r--r-- | khelpcenter/searchhandlers/htdig_long.html | 2 | ||||
-rwxr-xr-x | khelpcenter/searchhandlers/khc_docbookdig.pl.in | 221 | ||||
-rwxr-xr-x | khelpcenter/searchhandlers/khc_htdig.pl.in | 148 | ||||
-rwxr-xr-x | khelpcenter/searchhandlers/khc_htsearch.pl | 117 | ||||
-rwxr-xr-x | khelpcenter/searchhandlers/khc_mansearch.pl | 84 | ||||
-rw-r--r-- | khelpcenter/searchhandlers/man.desktop | 5 |
10 files changed, 660 insertions, 0 deletions
diff --git a/khelpcenter/searchhandlers/Makefile.am b/khelpcenter/searchhandlers/Makefile.am new file mode 100644 index 000000000..65f4060b6 --- /dev/null +++ b/khelpcenter/searchhandlers/Makefile.am @@ -0,0 +1,10 @@ +searchhandlers_DATA = htdig.desktop man.desktop docbook.desktop + +searchhandlersdir = $(kde_datadir)/khelpcenter/searchhandlers + +kde_bin_SCRIPTS = khc_htdig.pl khc_htsearch.pl khc_mansearch.pl \ + khc_docbookdig.pl + +htdigdata_DATA = htdig_long.html + +htdigdatadir = $(kde_datadir)/khelpcenter/searchhandlers/htdig diff --git a/khelpcenter/searchhandlers/README.searchhandlers b/khelpcenter/searchhandlers/README.searchhandlers new file mode 100644 index 000000000..cbbfbbbd7 --- /dev/null +++ b/khelpcenter/searchhandlers/README.searchhandlers @@ -0,0 +1,61 @@ +KHelpcenter Search Handlers +=========================== + +Searching documents in KHelpcenter is handled by document-type-specific search +handlers. Each searchable document provides provides a document type in its meta +data and if a corresponding handler is found, it can be searched. + +Search handlers are described by a desktop file which is put in the khelpcenter +app directory in a "searchhandlers" directory. The desktop file contains the +information about which document types the handler covers, how to do a search +query and how to create a search index. + +A search handler has to provide a command line tool based interface. There has +to be a command to do a query and, if previous creation of an index is required, +a command to create a search index. The search commands returns its results as +HTML on stdout. + + +Search Query +------------ + +KHelpcenter reads the command to execute for submitting a search query from the +search handler's desktop file ("SearchCommand"). The search command can contain +some symbols which are replaced by KHelpcenter with the data for the concrete +search request: + +%i Identifier of document (usually the name of the document's desktop file) +%w Words to be searched for +%o Operation for combining multiple search words. Allowed values: "and" and + "or". +%m Maximum number of results +%d Directory containing search indices + +Search Query Result +------------------- + +The result has to be returned as HTML page. The content of the <body> tag will +be extracted and inserted in the search results page. If there is no body tag, +the complete result text will be inserted. + + +Building a Search Index +----------------------- + +KHelpcenter reads the command to build a search index from the search handler's +desktop file ("IndexCommand"). The indexing command can contain some symbols +which are replaced by KHelpcenter with the data for the concrete index creation +call: + +%i Identifier of document (usually the name of the document's desktop file) +%d Directory containing search indices +%p Path to document to be indexed + +Index Creation Result +--------------------- + +As result of the indexing command an index is created in the directory specified +by KHelpcenter. The format and structure of the index is handler-specific. When +index creation is finished the indexing command has to create a special file +with the name "<identifier>.exists", where <identifier> has to have the value +passed by the %i symbol. This file indicates the existance of the index. diff --git a/khelpcenter/searchhandlers/docbook.desktop b/khelpcenter/searchhandlers/docbook.desktop new file mode 100644 index 000000000..08208c187 --- /dev/null +++ b/khelpcenter/searchhandlers/docbook.desktop @@ -0,0 +1,6 @@ +[Desktop Entry] + +DocumentTypes=text/docbook + +SearchCommand=khc_htsearch.pl --docbook --indexdir=%d --config=%i --words=%w --method=%o --maxnum=%m --lang=en +IndexCommand=khc_docbookdig.pl --indexdir=%d --docpath=%p --identifier=%i diff --git a/khelpcenter/searchhandlers/htdig.desktop b/khelpcenter/searchhandlers/htdig.desktop new file mode 100644 index 000000000..08cff6ec2 --- /dev/null +++ b/khelpcenter/searchhandlers/htdig.desktop @@ -0,0 +1,6 @@ +[Desktop Entry] + +DocumentTypes=text/html + +SearchCommand=khc_htsearch.pl --indexdir=%d --config=%i --words=%w --method=%o --maxnum=%m --lang=%l +IndexCommand=khc_htdig.pl --indexdir=%d --docpath=%p --identifier=%i --lang=%l diff --git a/khelpcenter/searchhandlers/htdig_long.html b/khelpcenter/searchhandlers/htdig_long.html new file mode 100644 index 000000000..a2e6e2188 --- /dev/null +++ b/khelpcenter/searchhandlers/htdig_long.html @@ -0,0 +1,2 @@ +$(STARSRIGHT) <a href="$&(URL)">$&(TITLE) ($(MODIFIED))</a><br> +$(EXCERPT)<br> diff --git a/khelpcenter/searchhandlers/khc_docbookdig.pl.in b/khelpcenter/searchhandlers/khc_docbookdig.pl.in new file mode 100755 index 000000000..63f787515 --- /dev/null +++ b/khelpcenter/searchhandlers/khc_docbookdig.pl.in @@ -0,0 +1,221 @@ +#!/usr/bin/perl +# +# Wrapper script for creating search indices for htdig. +# +# This file is part of KHelpcenter. +# +# Copyright (C) 2002 SuSE Linux AG, Nuernberg +# +# Author: Cornelius Schumacher <[email protected]> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +use strict; + +use Getopt::Long; + +my $htdigdata = "/srv/www/htdig/common/"; +my $htdigbin = "/usr/bin"; +my $kdeprefix = "@prefix@"; +chomp $kdeprefix; + +my $dbg = 1; + +my ($indexdir, $docpath, $identifier, $lang, $help ); + +GetOptions ( + 'indexdir=s' => \$indexdir, + 'docpath=s' => \$docpath, + 'identifier=s' => \$identifier, + 'lang=s' => \$lang, + 'help' => \$help, +); + +if ( $help ) { + usage(); +} + +if ( !$indexdir || !$docpath || !$identifier ) { + print STDERR "Missing arguments.\n"; + usage(); +} + +&dbg( "INDEXDIR: $indexdir" ); + +if ( !$lang ) { $lang = "en"; } + +my $tmpdir = "$indexdir/$identifier.tmp"; +if ( ! -e $tmpdir ) { + mkdir $tmpdir; +} + +print "Creating index for <b>'$identifier'</b>\n"; + +my $htdigconf = $indexdir; +my $htdigdb = $indexdir; + +my $conffile = "$htdigconf/$identifier.conf"; + +my $commondir = "$htdigdata/$lang"; +if ( !$lang || !-e $commondir ) { + $commondir = "$htdigdata/en"; +} +if ( !-e $commondir ) { $commondir = $htdigdata; } + +my $locale; +if ( $lang eq "de" ) { $locale = "de_DE"; } +else { $locale = $lang; } + +my $startfile = "$tmpdir/index.html"; + +if ( !open( START, ">$startfile" ) ) { + print STDERR "Unable to open '$startfile' for writing.\n"; + exit 1; +} + +$ENV{ PATH } = '/bin:/usr/bin'; +$ENV{ CDPATH } = ''; +$ENV{ ENV } = ''; + +my $findpath = "$kdeprefix/share/doc/HTML/$lang/"; +my $findcmd = "find $findpath -name index.docbook"; + +print STDERR "FINDCMD: $findcmd\n"; + +if ( !open FIND, "$findcmd|" ) { + print STDERR "Unable to find docs.\n"; + exit 1; +} +while ( <FIND> ) { + chomp; + my $path = $_; + $path =~ /$findpath(.*)\/index.docbook$/; + my $app = $1; + print START "<a href=\"help://$app/index.docbook\">$path</a>\n"; +} +close START; + +my $mimetypefile = "$tmpdir/htdig_mime"; +if ( !open( MIME, ">$mimetypefile" ) ) { + print STDERR "Unable to open '$mimetypefile' for writing.\n"; + exit 1; +} +print MIME << "EOT"; +text/html html +text/docbook docbook +EOT +close MIME; + +my $parserfile = "$tmpdir/docbookparser"; +if ( !open( PARSER, ">$parserfile" ) ) { + print STDERR "Unable to open '$parserfile' for writing.\n"; + exit 1; +} +print PARSER << "EOT"; +#! /bin/sh + +file=\$1 +shift +mime=\$1 +shift + +if test "\$#" -gt 0; then + orig=\${1/file:\\//} + shift +fi + +case "\$orig" in + help:/*) + orig=\${orig/help:\\//} + orig=\${orig/\/index.docbook/} + cd $kdeprefix/share/doc/HTML/en/\$orig + file=index.docbook + ;; + *) + file=\$orig + cd `dirname \$orig` + ;; +esac + +echo "t apptitle" +$kdeprefix/bin/meinproc --htdig "\$file" +EOT +close PARSER; +chmod 0755, $parserfile; + +if ( !open( CONF, ">$conffile" ) ) { + print STDERR "Unable to open '$conffile' for writing.\n"; + exit 1; +} +print CONF << "EOT"; +# htdig configuration for doc '$identifier' +# +# This file has been automatically created by KHelpcenter +common_dir: $commondir +locale: $locale +database_dir: $htdigdb +database_base: \${database_dir}/$identifier +local_urls: help://=$kdeprefix/share/doc/HTML/en/ file://=/ +local_urls_only: true +limit_urls_to: file:// help:/ +ignore_noindex: true +max_hop_count: 4 +robotstxt_name: kdedig +compression_level: 6 +template_map: Long long $kdeprefix/share/apps/khelpcenter/searchhandlers/htdig/htdig_long.html +search_algorithm: exact:1 prefix:0.8 +maximum_pages: 1 +matches_per_page: 10 +start_url: file://$tmpdir/index.html +external_parsers: text/docbook $parserfile +valid_extensions: .docbook .html +mime_types: $mimetypefile +EOT +close CONF; + +my $ret = system( "$htdigbin/htdig", "-v", "-s", "-i", "-c", $conffile ); +if ( $ret != 0 ) { + print STDERR "htdig failed\n"; +} else { + $ret = system( "$htdigbin/htmerge", "-c", $conffile ); + if ( $ret != 0 ) { print STDERR "htmerge failed\n"; } +} + +if ( $ret == 0 ) { + my $existsfile = "$indexdir/$identifier.exists"; + + if ( !open( EXISTS, ">$existsfile" ) ) { + print STDERR "Unable to open '$existsfile' for writing.\n"; + exit 1; + } + print EXISTS "$identifier\n"; + close EXISTS; + + print "Finished successfully.\n"; +} + +exit $ret; + +sub dbg($) +{ + $dbg && print STDERR shift, "\n"; +} + +sub usage() +{ + print "Usage: khc_docbookdig.pl --indexdir <indexdir> --docpath <path> "; + print "--identifier <identifier>\n"; + exit 1; +} diff --git a/khelpcenter/searchhandlers/khc_htdig.pl.in b/khelpcenter/searchhandlers/khc_htdig.pl.in new file mode 100755 index 000000000..909d53fd1 --- /dev/null +++ b/khelpcenter/searchhandlers/khc_htdig.pl.in @@ -0,0 +1,148 @@ +#!/usr/bin/perl +# +# Wrapper script for creating search indices for htdig. +# +# This file is part of the SuSE help system. +# +# Copyright (C) 2002 SuSE Linux AG, Nuernberg +# +# Author: Cornelius Schumacher <[email protected]> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +use strict; + +use Getopt::Long; + +my $htdigdata = "/srv/www/htdig/common/"; +my $htdigbin = "/usr/bin"; +my $kdeprefix = "@prefix@"; +chomp $kdeprefix; + +my $dbg = 1; + +my ($indexdir, $docpath, $identifier, $lang, $help ); + +GetOptions ( + 'indexdir=s' => \$indexdir, + 'docpath=s' => \$docpath, + 'identifier=s' => \$identifier, + 'lang=s' => \$lang, + 'help' => \$help, +); + +if ( $help ) { + usage(); +} + +if ( !$indexdir || !$docpath || !$identifier ) { + print STDERR "Missing arguments.\n"; + usage(); +} + +if ( !$lang ) { $lang = "en"; } + +&dbg( "INDEXDIR: $indexdir" ); + +print "Creating index for <b>'$identifier'</b>\n"; + +my $htdigconf = $indexdir; +my $htdigdb = $indexdir; + +my $conffile = "$htdigconf/$identifier.conf"; + +if ( !open( CONF, ">$conffile" ) ) { + print STDERR "Unable to open '$conffile' for writing.\n"; + exit 1; +} + +my $commondir = "$htdigdata/$lang"; +if ( !$lang || !-e $commondir ) { + $commondir = "$htdigdata/en"; +} +if ( !-e $commondir ) { $commondir = $htdigdata; } + +my $locale; +if ( $lang eq "de" ) { $locale = "de_DE"; } +else { $locale = $lang; } + +print CONF << "EOT"; +# htdig configuration for doc '$identifier' +# +# This file has been automatically created by KHelpcenter + +common_dir: $commondir +locale: $locale +database_dir: $htdigdb +local_urls: http://localhost= +local_urls_only: true +limit_urls_to: http://localhost +ignore_noindex: true +max_hop_count: 4 +robotstxt_name: kdedig +compression_level: 6 +template_map: Long long $kdeprefix/share/apps/khelpcenter/searchhandlers/htdig/htdig_long.html \\ + Short short $htdigdata/short.html +search_algorithm: exact:1 prefix:0.8 +maximum_pages: 1 +matches_per_page: 10 +database_base: \${database_dir}/$identifier +start_url: http://localhost/$docpath +# for pdf-files +max_doc_size: 5000000 +external_parsers: application/pdf /usr/share/doc/packages/htdig/contrib/parse_doc.pl application/postscript /usr/share/doc/packages/htdig/contrib/parse_doc.pl +#external_parsers: text/docbook /build/htdig/parser +EOT + +close CONF; + +$ENV{ PATH } = ''; +$ENV{ CDPATH } = ''; +$ENV{ ENV } = ''; + +my $ret = system( "$htdigbin/htdig", "-s", "-i", "-c", $conffile ); +if ( $ret != 0 ) { + print STDERR "htdig failed\n"; +} else { + $ret = system( "$htdigbin/htmerge", "-c", $conffile ); + if ( $ret != 0 ) { print STDERR "htmerge failed\n"; } +} + +if ( $ret == 0 ) { + my $existsfile = "$indexdir/$identifier.exists"; + + if ( !open( EXISTS, ">$existsfile" ) ) { + print STDERR "Unable to open '$existsfile' for writing.\n"; + exit 1; + } + print EXISTS "$identifier\n"; + close EXISTS; + + print "Finished successfully.\n"; +} + +exit $ret; + +sub dbg($) +{ + $dbg && print STDERR shift, "\n"; +} + +sub usage() +{ + print "Usage: khc_htdig.pl --indexdir <indexdir> --docpath <path> "; + print "--identifier <identifier>\n"; + exit 1; +} diff --git a/khelpcenter/searchhandlers/khc_htsearch.pl b/khelpcenter/searchhandlers/khc_htsearch.pl new file mode 100755 index 000000000..451e858dd --- /dev/null +++ b/khelpcenter/searchhandlers/khc_htsearch.pl @@ -0,0 +1,117 @@ +#!/usr/bin/perl + +use strict; + +use Encode; +use Getopt::Long; + +use open IO => ':utf8'; +use open ':std'; + +my $htsearchpath="/srv/www/cgi-bin/htsearch"; + +my $config; +my $format; +my $method; +my $words; +my $lang; +my $docbook; +my $indexdir; +my $maxnum; + +GetOptions ( + 'config=s' => \$config, + 'format=s' => \$format, + 'method=s' => \$method, + 'words=s' => \$words, + 'lang=s' => \$lang, + 'docbook' => \$docbook, + 'indexdir=s' => \$indexdir, + 'maxnum=s' => \$maxnum +); + +if ( !$indexdir ) { + print STDERR "No index dir given.\n"; + exit 1; +} + +if ( !$lang ) { $lang = "en"; } + +my $charset = langCharset( $lang ); + +$words = encode( $charset, $words ); + +if ( !open( HTSEARCH, "-|", "$htsearchpath", "-c", "$indexdir/$config.conf", + "format=$format&method=$method&words=$words" ) ) +{ + print "Can't execute htsearch at '$htsearchpath'.\n"; + exit 1; +} + +my ($body,$liststart,$ref,$link,$error,$errorOut); + +while( <HTSEARCH> ) { + if ( !$body ) { + print; + if ( /^<body/ ) { $body = 1; } + } + if ( /^<h3>/ ) { + print; + print "<ul>\n"; + $liststart = 1; + } + if ( /^<img src.*<a href="(.*)">(.*)<\/a>/ ) { + $ref = $1; + $link = $2; + + print STDERR "REF: $ref LINK: $link\n"; + + $ref =~ s/file:\/\/localhost//; + + $ref =~ s/http:\/\/localhost\//file:\//; + + if ( $docbook ) { + $ref =~ /help:\/\/(.*)\/index.docbook/; + my $app = $1; + $ref = "help:$app"; + + $link =~ s/apptitle/$app/; + } + + print " <li><a href=\"$ref\">$link</a></li>\n"; + } + if ( /^<h1>ht:\/\/Dig error/ ) { + $error = 1; + print "Htdig error:\n"; + } + if ( $error && /^<pre>/ ) { + $errorOut = 1; + } + if ( $errorOut ) { + print; + if ( /^<\/pre>/ ) { $errorOut = 0; } + } +} + +close HTSEARCH; + +if ( $liststart ) { print "</ul>\n"; } + +print "</body></html>\n"; + +if ( $? != 0 ) { exit $?; } + +1; + +# Return charset used for given language +sub langCharset( $ ) +{ + my $lang = shift; + if ( $lang eq "cz" || $lang eq "hu" ) { + return "latin2"; + } elsif ( $lang eq "kr" ) { + return "utf8"; + } else { + return "latin1"; + } +} diff --git a/khelpcenter/searchhandlers/khc_mansearch.pl b/khelpcenter/searchhandlers/khc_mansearch.pl new file mode 100755 index 000000000..a68fde752 --- /dev/null +++ b/khelpcenter/searchhandlers/khc_mansearch.pl @@ -0,0 +1,84 @@ +#!/usr/bin/perl +# +# Script for searching man pages. The result is generated as HTML. +# +# This file is part of KHelpcenter. +# +# Copyright (C) 2002 SuSE Linux AG, Nuernberg +# +# Author: Cornelius Schumacher <[email protected]> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +use strict; + +use Getopt::Long; + +my ( $words, $maxcount, $lang, $help ); + +GetOptions ( + 'maxcount=s' => \$maxcount, + 'words=s' => \$words, + 'lang=s' => \$lang, + 'help' => \$help +); + +if ( $help ) { + print STDERR "Usage: khc_mansearch.pl --maxcount=n --words=<string> " . + "--lang=<languagecode>\n"; + exit 1; +} + +if ( !$words ) { + print STDERR "No search words given.\n"; + exit; +} + +# Perform search +if ( !open( MAN, "-|", "apropos", $words ) ) { + print "Can't open apropos.\n"; + exit 1; +} +my @results; +while( <MAN> ) { +# print "RAW:$_"; + chop; + /^([^\s]+)\s+\((.*)\)\s+-\s+(.*)$/; + my $page = $1; + my $section = $2; + my $description = $3; + + if ( $page ) { push @results, [ $page, $section, $description ]; } +} +close MAN; + +my $nummatches = @results; + +if ( $nummatches > 0 ) { + print "<ul>\n"; + + my $count = 0; + for my $result ( @results ) { + my ( $page, $section, $description ) = @$result; + my $url = "man:" . $page; + print "<li><a href=\"$url\">"; + print "$page - $description</a></li>\n"; + if ( ++$count == $maxcount ) { last; } + } + + print "</ul>\n"; +} + +1; diff --git a/khelpcenter/searchhandlers/man.desktop b/khelpcenter/searchhandlers/man.desktop new file mode 100644 index 000000000..f9274384e --- /dev/null +++ b/khelpcenter/searchhandlers/man.desktop @@ -0,0 +1,5 @@ +[Desktop Entry] + +DocumentTypes=text/man + +SearchCommand=khc_mansearch.pl --words=%w --maxcount=%m |