CGI-Application-Search
view release on metacpan or search on metacpan
lib/CGI/Application/Search/Tutorial.pm view on Meta::CPAN
but just a few will get you started.
# index all HTML files in /path/to/index
IndexDir /path/to/index
IndexOnly .html .htm
IndexContents HTML2 .html .htm
# C::A::Search needs a description, use the first 1,500 characters
# of the body
StoreDescription HTML2 <body> 1500
# remove doc-root path so links will work on the results page
ReplaceRules remove /path/to/index
Put the above in a file called F<swish-e.conf>.
NOTE: The above is a very simple swish-e.conf file. To bask in the
power and flexibility that is swish-e, please see the official documentation.
=head2 Step 3: Run the Indexer
Now that you've got a basic configuration file you can index your site.
The corresponding simple command is:
$ swish-e -v 1 -c swish-e.conf -f /path/to/swishe-index
The last part is the place where Swish-e will write its index. It
should be the name of a file in a directory writable by you and
readable by your CGI scripts.
Later you'll need to setup the indexer to run from cron, but for now
just run it once.
=head2 Step 4: Run a Test Search
Swish-e has a command-line interface to running searches which you can
use to confirm that your index is working. For example, to search for
"foo":
$ swish-e -w foo -f /path/to/swishe-index
If that works you should see some hits (assuming your site contains
"foo").
=head2 Step 5: Setup an Instance Script
Like all CGI::Application modules, CGI::Application::Search requires
an instance script. Create a file called 'search.pl' or 'search.cgi'
in a place where your web server will execute it. Put this in it:
#!/usr/bin/perl -w
use strict;
use CGI::Application::Search;
my $app = CGI::Application::Search->new(
PARAMS => { SWISHE_INDEX => '/path/to/index' }
);
$app->run();
Now make it executable:
$ chmod +x search.pl
=head2 Step 6: Test Your Instance Script
First, test it on the command-line:
$ ./search.pl
That should show you the HTML for the search form with no results.
Now try it in your browser:
http://yoursite.example.com/search.pl
If that doesn't work, check your error log. Do not email me or the
CGI::Application mailing list until you check your error log. Yes, I
mean you. Thanks.
=head2 Step 7: Rejoice
You've just completed the world's easiest search system setup! Now go
setup that indexing cronjob.
=head1 AJAX USAGE
L<CGI::Application::Search> provides 2 features implemented in AJAX
(Asynchronous Javascript And XML). These are:
=over
=item Non-Refresh Search
Only the relevant portions of the page
are changed, not the entire page. This results in a faster search, especially
if the page is surrounded by other dynamic elements (navigation, side bars, etc).
=item Auto-Suggest
As the user types, they are presented with suggestions that match the letters/words
they have entered so far.
=back
Both are configurable and overrideable and can also be turned off completely.
Both make use of the B<Prototype> and B<Scriptaculous> JavaScript libraries
(available at L<http://prototype.conio.net/> and L<http://script.aculo.us>).
Although our example AJAX templates have these libraries included (using
C<< HTML::Prototype->define_javascript_functions() >> we recommend that you
actually download these libraries yourself and put them into your web document
tree and reference them in C<< <script> >> tags. This will allow them to be
cached by the browser instead of reparsed on each page fetch.
<script src="/prototype.js" type="text/javascript"></script>
<script src="/scriptaculous.js" type="text/javascript"></script>
You are encouraged to look at the sample templates included with this distribution
while you are learning how the JavaScript, CSS, C<< <forms> >> and links all work
together.
=head2 SETTING UP NON-REFRESH SEARCH
( run in 1.053 second using v1.01-cache-2.11-cpan-5a3173703d6 )