File: api.html

package info (click to toggle)
swish-e 2.4.5-5
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 7,044 kB
  • ctags: 7,630
  • sloc: ansic: 47,771; sh: 8,968; perl: 3,170; makefile: 587; xml: 9
file content (928 lines) | stat: -rw-r--r-- 34,045 bytes parent folder | download
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
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<!-- 
    ***** GENERATED FILE *** DO NOT EDIT DIRECTLY - any changes will be LOST ******

    swish-e.org mockup based on http://www.oswd.org/design/1773/prosimii/index2.html 
-->


<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en-US">
  <head>
    <meta http-equiv="content-type" content="application/xhtml+xml; charset=iso-8859-1" />
    <meta name="author" content="haran" />
    <meta name="generator" content="haran" />


    <link rel="stylesheet" type="text/css" href="./swish.css" media="screen" title="swish css" />

    
        <link rel="Last" href="./filter.html" />
    
        <link rel="Prev" href="./swish-library.html" />
    
        <link rel="Up" href="./index.html" />
    
        <link rel="Next" href="./swish.cgi.html" />
    
        <link rel="Start" href="./index.html" />
    
        <link rel="First" href="./readme.html" />
    

    <title>Swish-e :: SWISH::API - Perl interface to the Swish-e C Library</title>
  </head>


<body>
    

    <!-- noindex -->

    <!-- For non-visual user agents: -->
      <div id="top"><a href="#main-copy" class="doNotDisplay doNotPrint">Skip to main content.</a></div>

    <!-- ##### Header ##### -->

    <div id="header">
      <div class="superHeader">
        <span>Related Sites:</span>
            <a href="http://swishewiki.org/" title="swishe wiki">swish-e wiki</a> |
            <a href="http://www.xmlsoft.org/" title="libxml2 home page">libxml2</a> |
            <a href="http://www.zlib.net/" title="zlib home page">zlib</a> |
            <a href="http://www.foolabs.com/xpdf/" title="xpdf home page">xpdf</a> |
            <a href="http://cvs.sourceforge.net/viewcvs.py/swishe/" title="View CVS at SourceForge">CVS @ SourceForge</a> 
      </div>

      <div class="midHeader">
        <h1 class="headerTitle" lang="la">Swish-e</h1>
        <div class="headerSubTitle">Simple Web Indexing System for Humans - Enhanced</div>

        <br class="doNotDisplay doNotPrint" />

        <div class="headerLinks">
          <span class="doNotDisplay">Tools:</span>

              <!-- don't know what platform, so link to download page -->

              <a href="http://swish-e.org/download/index.html">download latest version</a>


        </div>
      </div>
    </div>
    <!-- index -->

  <!-- noindex -->
  <div class="subHeader">

   <form method="get"
        action="http://swish-e.org/search/index.html"
        enctype="application/x-www-form-urlencoded"
        class="srchform">

         <table width='100%'>
          <tr>
           <td align='left'>
            <a href="http://swish-e.org/index.html">home</a> |
            <a href="http://swish-e.org/support.html">support</a> |
            <a href="http://swish-e.org/download/index.html">download</a>
           </td>

           <td align='right'>


     <label for="searchfield">Search for</label>
     <input maxlength="200" value="" id="searchfield" size="30" name="query" type="text" alt="Search input field"/>
     <input value="search swish-e.org" name="submit" type="submit" class='button' />

                </td>
           </tr>
          </table>

   </form>

  </div>
  <!-- index -->



    <div id="side-bar">

    <!-- noindex -->
<ul class="menu"><li class="menuparent">

    <a class="menu" 
    href="./index.html"
    >Doc Overview</a>

<!-- noindex -->
<ul class="submenu"><li class="">

    <a class="submenu" 
    href="./readme.html"
     title="First time users">README</a>

</li><li class="">

    <a class="submenu" 
    href="./install.html"
     title="Installation and usage overview">Install</a>

</li><li class="">

    <a class="submenu" 
    href="./changes.html"
     title="Important changes from previous versions">Changes</a>

</li><li class="">

    <a class="submenu" 
    href="./swish-config.html"
     title="Directives that go in your Swish-e configuration file">Configuration</a>

</li><li class="">

    <a class="submenu" 
    href="./swish-run.html"
     title="Command line options for Swish-e binary">Running</a>

</li><li class="">

    <a class="submenu" 
    href="./swish-search.html"
     title="Swish-e's search language">Searching</a>

</li><li class="">

    <a class="submenu" 
    href="./swish-faq.html"
    >FAQ</a>

</li><li class="">

    <a class="submenu" 
    href="./swish-bugs.html"
    >Known issues</a>

</li><li class="">

    <a class="submenu" 
    href="./swish-3.0.html"
    >The Future</a>

</li><li class="">

    <a class="submenu" 
    href="./swish-library.html"
     title="Swish-e C API">C API</a>

</li><li class="">

    <a class="thisfile" 
    href="./api.html"
     title="Perl interface to the Swish-e library">Perl API &#187;</a>

</li><li class="">

    <a class="submenu" 
    href="./swish.cgi.html"
     title="Example CGI/mod_perl script">Swish.cgi</a>

</li><li class="">

    <a class="submenu" 
    href="./search.cgi.html"
     title="Example Perl script using SWISH::API">Search.cgi</a>

</li><li class="">

    <a class="submenu" 
    href="./spider.html"
     title="The Swish-e HTTP spider">Spider.pl</a>

</li><li class="">

    <a class="submenu" 
    href="./filter.html"
     title="How to index non-text documents">Filters</a>

</li></ul>
<!-- index -->


</li></ul>
<!-- index -->



</div>

<div id="main-copy">
    
    
    
    
<h1>SWISH::API - Perl interface to the Swish-e C Library</h1>
Swish-e version 2.4.5



    <!-- noindex -->

    
        <h2>Table of Contents</h2>
        <div class="toc">
            
    <ul class="toc">
        
            <li>
                <a href="#synopsis">SYNOPSIS</a>
                
            </li>
        
            <li>
                <a href="#description">DESCRIPTION</a>
                
            </li>
        
            <li>
                <a href="#dependencies">DEPENDENCIES</a>
                
            </li>
        
            <li>
                <a href="#overview">OVERVIEW</a>
                
            </li>
        
            <li>
                <a href="#methods">METHODS</a>
                
    <ul class="toc">
        
            <li>
                <a href="#swish_api_swish_handle_object">SWISH::API - Swish Handle Object</a>
                
    <ul class="toc">
        
            <li>
                <a href="#error_handling">Error Handling</a>
                
            </li>
        
            <li>
                <a href="#generating_search_and_result_objects">Generating Search and Result Objects</a>
                
            </li>
        
    </ul>

            </li>
        
            <li>
                <a href="#swish_api_search_search_objects">SWISH::API::Search - Search Objects</a>
                
            </li>
        
            <li>
                <a href="#swish_api_results_generating_and_accessing_results">SWISH::API::Results - Generating and accessing results</a>
                
            </li>
        
            <li>
                <a href="#results_methods">Results Methods</a>
                
            </li>
        
            <li>
                <a href="#swish_api_result_result_methods">SWISH::API::Result - Result Methods</a>
                
            </li>
        
            <li>
                <a href="#utility_methods">Utility Methods</a>
                
            </li>
        
    </ul>

            </li>
        
            <li>
                <a href="#notes">NOTES</a>
                
            </li>
        
            <li>
                <a href="#copyright">COPYRIGHT</a>
                
            </li>
        
            <li>
                <a href="#author">AUTHOR</a>
                
            </li>
        
            <li>
                <a href="#support">SUPPORT</a>
                
            </li>
        
    </ul>

        </div>
    
    <!-- index -->





<hr />


    <div class="sub-section">
        
<h1><a name="synopsis"></a>SYNOPSIS</h1>

<pre class="pre-section">    use SWISH::API;

    my $swish = SWISH::API-&gt;new( 'index.swish-e' );

    $swish-&gt;abort_last_error
        if $swish-&gt;Error;

    # A short-cut way to search

    my $results = $swish-&gt;query( "foo OR bar" );

    # Or more typically
    my $search = $swish-&gt;new_search_object;

    # then in a loop
    my $results = $search-&gt;execute( $query );

    # always check for errors (but aborting is not always necessary)

    $swish-&gt;abort_last_error
        if $swish-&gt;Error;

    # Display a list of results

    my $hits = $results-&gt;hits;
    if ( !$hits ) {
        print "No Results\n";
        return;  /* for example *.
    }

    print "Found ", $results-&gt;hits, " hits\n";

    # Seek to a given page - should check for errors
    $results-&gt;seek_result( ($page-1) * $page_size );

    while ( my $result = $results-&gt;next_result ) {
        printf("Path: %s\n  Rank: %lu\n  Size: %lu\n  Title: %s\n  Index: %s\n  Modified: %s\n  Record #: %lu\n  File   #: %lu\n\n",
            $result-&gt;property( "swishdocpath" ),
            $result-&gt;property( "swishrank" ),
            $result-&gt;property( "swishdocsize" ),
            $result-&gt;property( "swishtitle" ),
            $result-&gt;property( "swishdbfile" ),
            $result-&gt;result_property_str( "swishlastmodified" ),
            $result-&gt;property( "swishreccount" ),
            $result-&gt;property( "swishfilenum" )
        );
    }

    # display properties and metanames

    for my $index_name ( $swish-&gt;index_names ) {
        my @metas = $swish-&gt;meta_list( $index_name );
        my @props = $swish-&gt;property_list( $index_name );

        for my $m ( @metas ) {
            my $name = $m-&gt;name;
            my $id = $m-&gt;id;
            my $type = $m-&gt;type;
        }
        # (repeat above for @props)
    }</pre>

    </div>

    <div class="sub-section">
        
<h1><a name="description"></a>DESCRIPTION</h1>

<p>This module provides a Perl interface to the Swish-e search engine.
This module allows embedding the swish-e search code into your application
avoiding the need to fork to run the swish-e binary and to keep an index file
open when running multiple queries.  This results in increased search performance.</p>

    </div>

    <div class="sub-section">
        
<h1><a name="dependencies"></a>DEPENDENCIES</h1>

<p>You must have installed Swish-e version 2.4 before building this module.
Download from:</p>
<pre class="pre-section">    http://swish-e.org</pre>

    </div>

    <div class="sub-section">
        
<h1><a name="overview"></a>OVERVIEW</h1>

<p>This module includes a number of classes.</p>
<p>Searching consists of connecting to a swish-e index (or indexes), and then running queries
against the open index.  Connecting to the index creates a swish object blessed into
the SWISH::API class.</p>
<p>A SWISH::API::Search object is created from the SWISH::API object.
The SWISH::API::Search object can have associated parameters (e.g. result sort order).</p>
<p>The SWISH::API::Search object is used to query the associated index file or files.
A query on a search object returns a results object of the class SWISH::API::Results.
Then individual results of the SWISH::API::Result class can be fetched by calling a
method of the results object.</p>
<p>Finally, a result's properties can be accessed by calling methods on the result object.</p>

    </div>

    <div class="sub-section">
        
<h1><a name="methods"></a>METHODS</h1>


    </div>

    <div class="sub-section">
        
<h2><a name="swish_api_swish_handle_object"></a>SWISH::API - Swish Handle Object</h2>

<p>To begin using Swish you must first create a Swish Handle object.  This
object makes the connection to one or more index files and is used to
create objects used for searching the associated index files.</p>
<ul>
<li><a name="item__swish"></a><a name="_swish"></a><b>$swish = SWISH::API-&gt;new( $index_files );</b>
<p>This method returns a swish handle object blessed into the SWISH::API class.
$index_files is a space separated list of index files to open.
This always returns an object, even on errors.
Caller must check for errors (see below).</p>
</li>
<li><a name="item__indexes"></a><a name="_indexes"></a><b>@indexes = $swish-&gt;index_names;</b>
<p>Returns a list of index names associated with the swish handle.
These were the indexes specified as a parameter on the SWISH::API-&gt;new call.
This can be used in calls below that require specifying the index file name.</p>
</li>
<li><a name="item__header_names"></a><a name="_header_names"></a><b>@header_names = $swish-&gt;header_names;</b>
<p>Returns a list of possible header names.  These can be used to lookup
header values.  See <code>Swishheader_value</code> method below.</p>
</li>
<li><a name="item__values"></a><a name="_values"></a><b>@values = $swish-&gt;header_value( $index_file, $header_name );</b>
<p>A swish-e index has data associated with it stored in the index header.  This method
provides access to that data.</p>
<p>Returns the header value for the header and index file specified.  Most headers
are a single item, but some headers (e.g. "Stopwords") return a list.</p>
<p>The list of possible header names can be obtained from the Swishheader_names method.</p>
</li>
<li><a name="item__swish_rank_scheme_"></a><a name="_swish_rank_scheme_"></a><b>$swish-&gt;rank_scheme( 0|1 );</b>
<p>Similar to the -R option with the swish-e command line tool. The default
ranking scheme is 0. Set it to 1 to experiment with other ranking features.
See the SWISH-CONFIG documentation for more on ranking schemes.</p>
</li>
</ul>

    </div>

    <div class="sub-section">
        
<h3><a name="error_handling"></a>Error Handling</h3>

<p>All errors are stored in and accessed via the SWISH::API object (the Swish Handle).
That is, even an error that occurs when calling a method on a result
(SWISH::API::Result) object will store the error in the parent SWISH:API object.</p>
<p>Check for errors after every method call.  Some errors are critical errors and will require
destruction of the SWISH::API object.  Critical errors will typically only happen when
attaching to the database and are errors such as an invalid index file name, permissions
errors, or passing invalid objects to calls.</p>
<p>Typically, if you receive an error when attaching to an index file or files you should assume
that the error is critical and let the swish object fall out of scope (and destroyed).  Otherwise,
if an error is detected you should check if it is a critical error.
If the error is not critical you may
continue using the objects that have been created (for example, an invalid meta name will
generate a non-critical error, so you may continue searching using the same search object).</p>
<p>Error state is cleared upon a new query.</p>
<p>Again, all error methods need to be called on the parent swish object</p>
<ul>
<li><a name="item__swish_error"></a><a name="_swish_error"></a><b>$swish-&gt;error</b>
<p>Returns true if an error occurred on the last operation.  On errors the value returned
is the internal Swish-e error number (which is less than zero).</p>
</li>
<li><a name="item__swish_critical_error"></a><a name="_swish_critical_error"></a><b>$swish-&gt;critical_error</b>
<p>Returns true if the last error was a critical error</p>
</li>
<li><a name="item__swish_abort_last_error"></a><a name="_swish_abort_last_error"></a><b>$swish-&gt;abort_last_error</b>
<p>Aborts the running program and prints an error message to STDERR.</p>
</li>
<li><a name="item__str"></a><a name="_str"></a><b>$str = $swish-&gt;error_string</b>
<p>Returns the string description of the current error (based on the value
returned by $swish-&gt;error).  This is a generic error string.</p>
</li>
<li><a name="item__msg"></a><a name="_msg"></a><b>$msg = $swish-&gt;last_error_msg</b>
<p>Returns a string with specific information about the last error, if any.
For example, if a query of:</p>
<pre class="pre-section">    badmeta=foo</pre>
<p>and "badmeta" is an invalid metaname $swish-&gt;error_string
might return "Unknown metaname", but $swish-&gt;last_error_msg might return "badmeta".</p>
</li>
</ul>

    </div>

    <div class="sub-section">
        
<h3><a name="generating_search_and_result_objects"></a>Generating Search and Result Objects</h3>

<ul>
<li><a name="item__search"></a><a name="_search"></a><b>$search = $swish-&gt;new_search_object( $query );</b>
<p>This creates a new search object blessed into the SWISH::API::Search class.  The optional
$query parameter is a query string to store in the search object.</p>
<p>See the section on <code>SWISH::API::Search</code> for methods available on the returned object.</p>
<p>The advantage of this method is that a search object can be used for multiple queries:</p>
<pre class="pre-section">    $search = $swish-&gt;New_Search_Objet;
    while ( $query = next_query() ) {
        $results = $search-&gt;execute( $query );
        ...
    }</pre>
</li>
<li><a name="item__results"></a><a name="_results"></a><b>$results = $swish-&gt;query( $query );</b>
<p>This is a short-cut which avoids the step of creating a separate search object.
It returns a results object blessed into the SWISH::API::Results class described below.</p>
<p>This method basically is the equivalent of</p>
<pre class="pre-section">    $results = $swish-&gt;new_search_object-&gt;execute( $query );</pre>
</li>
</ul>

    </div>

    <div class="sub-section">
        
<h2><a name="swish_api_search_search_objects"></a>SWISH::API::Search - Search Objects</h2>

<p>A search object holds the parameters used to generate a list of results.  These methods
are used to adjust these parameters and to create the list of results for the current
set of search parameters.</p>
<ul>
<li><a name="item__search_set_query_"></a><a name="_search_set_query_"></a><b>$search-&gt;set_query( $query );</b>
<p>This will set (or replace) the query string associated with a search object.
This method is typically not used as the query can be set when executing the
actual query or when creating a search object.</p>
</li>
<li><a name="item__search_set_structure_"></a><a name="_search_set_structure_"></a><b>$search-&gt;set_structure( $structure_bits );</b>
<p>This method may change in the future.</p>
<p>A "structure" is a bit-mapped flag used to limit search results to specific parts
of an HTML document, such as the title or in H tags.  The possible bits are:</p>
<pre class="pre-section">    IN_FILE         = 1      This is the default
    IN_TITLE        = 2      In &lt;title&gt; tag
    IN_HEAD         = 4      In &lt;head&gt; tag
    IN_BODY         = 8      In &lt;body&gt;
    IN_COMMENTS     = 16     In html comments
    IN_HEADER       = 32     In &lt;h*&gt;
    IN_EMPHASIZED   = 64     In &lt;em&gt;, &lt;b&gt;, &lt;strong&gt;, &lt;i&gt;
    IN_META         = 128    In a meta tag (e.g. not swishdefault)</pre>
<p>So if you wish to limit your searches to words in heading tags (e.g. &lt;H1&gt;)
or in the &lt;title&gt; tag use:</p>
<pre class="pre-section">    $search-&gt;set_structure( IN_HEAD | IN_TITLE );</pre>
</li>
<li><a name="item__search_phrase_delimiter_"></a><a name="_search_phrase_delimiter_"></a><b>$search-&gt;phrase_delimiter( $char );</b>
<p>Sets the character used as the phrase delimiter in searches.  The default
is double-quotes (").</p>
</li>
<li><a name="item__search_set_search_limit_"></a><a name="_search_set_search_limit_"></a><b>$search-&gt;set_search_limit( $property, $low, $high );</b>
<p>Sets a range from $low to $high inclusive that the given $property must be in
to be selected as a result.  Call multiple times to set more than one limit
on different properties.
Limits are ANDed, that is, a result must be within the range of all limits
specified to be included in a list of results.</p>
<p>For example to limit searches to documents modified in the last 48 hours:</p>
<pre class="pre-section">    my $start = time - 48 * 60 * 60;
    $search-&gt;set_search_limit( 'swishlastmodified', $start, time() );</pre>
<p>An error will be set if the property has already been specified or if 
$high &lt; $low.</p>
<p>Other errors may not be reported until running the query, such as the property
name is invalid or if $low or $high are not numeric and the property specified
is a numeric property.</p>
<p>Once a query is run you cannot change the limit settings for the search object
without calling the reset_search_limit method first.</p>
</li>
<li><a name="item__search_reset_search_limit_"></a><a name="_search_reset_search_limit_"></a><b>$search-&gt;reset_search_limit;</b>
<p>Clears the limit parameters for the given object.  This must be called if
the limit parameters need to be changed.</p>
</li>
<li><a name="item__search_set_sort_"></a><a name="_search_set_sort_"></a><b>$search-&gt;set_sort( $sort_string );</b>
<p>Sets the sort order of search results.  The string is a space separated
list of valid document properties.  Each property may contain a qualifier
that sets the direction of the sort.</p>
<p>For example, to sort the results by path name in ascending order and by rank in
descending order:</p>
<pre class="pre-section">    $search-&gt;set_sort( 'swishdocpath asc swishrank desc' );</pre>
<p>The "asc" and "desc" qualifiers are optional, and if omitted ascending is assumed.</p>
<p>Currently, errors (e.g invalid property name) are not detected on this call, but rather when
executing a query.  This may change in the future.</p>
</li>
</ul>

    </div>

    <div class="sub-section">
        
<h2><a name="swish_api_results_generating_and_accessing_results"></a>SWISH::API::Results - Generating and accessing results</h2>

<p>Searching generates a results object blessed into the SWISH::API::Results class.</p>
<ul>
<li><a name="item__results"></a><a name="_results"></a><b>$results = $search-&gt;execute( $query );</b>
<p>Executes a query based on the parameters in the search object.
$query is an optional query string to use for the search ($query replaces
the set query string in the search object).</p>
<p>A typical use would be to create a search object once and then call this method
for each query using the same search object changing only the passed in $query.</p>
<p>The caller should check for errors after making this all.</p>
</li>
</ul>

    </div>

    <div class="sub-section">
        
<h2><a name="results_methods"></a>Results Methods</h2>

<p>A query creates a results object that contains information about the query
(e.g. number of hits) and access to the individual results.</p>
<ul>
<li><a name="item__hits"></a><a name="_hits"></a><b>$hits = $results-&gt;hits;</b>
<p>Returns the number of results for the query.  If zero and no errors were reported
after calling $search-&gt;execute then the query returned zero results.</p>
</li>
<li><a name="item__parsed_words"></a><a name="_parsed_words"></a><b>@parsed_words = $results-&gt;parsed_words( $index_name );</b>
<p>Returns an array of tokenized words and operators with stopwords removed.
This is the array of tokens used by swish for the query.</p>
<p>$index_name must match one of the index files specified on the creation of
the swish object (via the SWISH::API-&gt;new call).</p>
<p>The parsed words are useful for highlighting search terms in associated documents.</p>
</li>
<li><a name="item__removed_stopwords"></a><a name="_removed_stopwords"></a><b>@removed_stopwords = $results-&gt;removed_stopwords( $index_name) ;</b>
<p>Returns an array of stopwords removed from a query, if any, for the index
specified.</p>
<p>$index_name must match one of the index files specified on the creation of
the swish object (via the SWISH::API-&gt;new call).</p>
</li>
<li><a name="item__results_seek_result_"></a><a name="_results_seek_result_"></a><b>$results-&gt;seek_result( $position );</b>
<p>Seeks to the position specified in the result list.  Zero is the first position
and $results-&gt;hits-1 is the last position.  Seeking past the end of results
sets a non-critical error condition.</p>
<p>Useful for seeking to a specific "page" of results.</p>
</li>
<li><a name="item__result"></a><a name="_result"></a><b>$result = $results-&gt;next_result;</b>
<p>Fetches the next result from the list of results.  Returns undef if no
more results are available.  $result is an object blessed into the
SWISH::API::Result class.</p>
</li>
</ul>

    </div>

    <div class="sub-section">
        
<h2><a name="swish_api_result_result_methods"></a>SWISH::API::Result - Result Methods</h2>

<p>The follow methods provide access to data related to an individual result.</p>
<ul>
<li><a name="item__prop"></a><a name="_prop"></a><b>$prop = $result-&gt;property( $prop_name );</b>
<p>Fetches the property specified for the current result.
An invalid property name will cause an exception (which can be caught
by wrapping the call in an eval block).</p>
<p>Can return undefined.</p>
<p>Date properties are returned as a timestamp.  Use something like Date::Format to
format the strings (or just call scalar localtime( $prop ) ).</p>
</li>
<li><a name="item__prop"></a><a name="_prop"></a><b>$prop = $result-&gt;result_property_str( $prop_name );</b>
<p>Fetches and formats the property.  Unlike above, invalid property names return the
string "(null)" -- this will likely change to match the above (i.e. throw an exception).</p>
<p>Undefined values are returned at the null string ("").</p>
</li>
<li><a name="item__value"></a><a name="_value"></a><b>$value = $result-&gt;result_index_value( $header_name );</b>
<p>Returns the header value specified.  This is similar to
$swish-&gt;header_value(), but the index file is not specified
(it is determined by the result).</p>
</li>
</ul>

    </div>

    <div class="sub-section">
        
<h2><a name="utility_methods"></a>Utility Methods</h2>

<ul>
<li><a name="item__metas"></a><a name="_metas"></a><b>@metas = $swish-&gt;meta_list( $index_name );</b>
<p>Swish-e has "MetaNames" which allow searching by fields in the index.
This method returns information about the Metanames.</p>
<p>Pass in the name of an open index file name and returns a 
list of SWISH::API::MetaName objects.  Three methods are currently 
defined on these objects:</p>
<pre class="pre-section">    $meta-&gt;name;
    $meta-&gt;id;
    $meta-&gt;type;</pre>
<p>Name returns the name of the meta as defined in the MetaNames
config option when the index was created.</p>
<p>The id is the internal ID number used to represent the meta name.</p>
<p>type is the type of metaname.  Currently only one type exists and its
value is zero.</p>
</li>
<li><a name="item__props"></a><a name="_props"></a><b>@props = $swish-&gt;property_list( $index_name );</b>
<p>Swish-e can store content or "properties" in the index and return this data
when running a query.
A document's path, URL, title, size, date or summary are examples
of properites.  Each property is accessed via its PropertyName.
This method returns information about the PropertNames stored in the index.</p>
<p>Pass in the name of an open index file name and returns a 
list of SWISH::API::MetaName objects.  Three methods are currently 
defined on these objects:</p>
<pre class="pre-section">    $prop-&gt;name;
    $prop-&gt;id;
    $prop-&gt;type;</pre>
<p>name returns the name of the meta as defined in the MetaNames
config option when the index was created.</p>
<p>The id is the internal ID number used to represent the meta name.</p>
<p>type is the type of metaname.  Currently only one type exists and its
value is zero.</p>
</li>
<li><a name="item__propes"></a><a name="_propes"></a><b>@propes = $result-&gt;property_list;</b>
</li>
<li><a name="item__meta"></a><a name="_meta"></a><b>@meta = $result-&gt;meta_list;</b>
<p>These also return a list of Property or Metaname description objects, but are
accessed via a result record.  Since the result comes from a specific index file
there's no need to specify the index file name.</p>
</li>
<li><a name="item__stemmed_word"></a><a name="_stemmed_word"></a><b>$stemmed_word = $swish-&gt;stem_word( $word );</b>
<p>*Deprecated*</p>
<p>Returns the stemmed version of the passed in word.</p>
<p>Deprecated because only stems using the original Porter Stemmer
and uses a shared memory location in the SW_HANDLE object to store the stemmed
word.  See below for other stemming options.</p>
</li>
<li><a name="item__fuzzy_word"></a><a name="_fuzzy_word"></a><b>$fuzzy_word = $swish-&gt;Fuzzify( $indexname, $word );</b>
<p>Like stem_word() used to work, only it uses whatever stemmer is named in $indexname.
Returns the same kind of fuzzy_word object as the fuzzy_word() method.</p>
</li>
<li><a name="item__mode_string"></a><a name="_mode_string"></a><b>$mode_string = $result-&gt;fuzzy_mode;</b>
<p>Returns the string (e.g. "Stemming_en", "Soundex", "None" ) indicating the stemming
method used while indexing the given document.</p>
</li>
<li><a name="item__fuzzy_word"></a><a name="_fuzzy_word"></a><b>$fuzzy_word = $result-&gt;fuzzy_word( $word );</b>
<p>Converts $word using the same fuzzy mode used to index the $result.
Returns a SWISH::API::fuzzy_word object.  Methods on the object are used
to access the converted words and other data as shown below.</p>
</li>
<li><a name="item__count"></a><a name="_count"></a><b>$count = $fuzzy_word-&gt;word_count;</b>
<p>Returns the number of output words.  Normally this is the value one, but may
be more depending on the stemmer used.  DoubleMetaphone can return two strings
for a single input string.</p>
</li>
<li><a name="item__status"></a><a name="_status"></a><b>$status = $fuzzy_word-&gt;word_error;</b>
<p>Returns any error code that the stemmer might set.  Normally, this return value
is zero, indicating that the stemming/fuzzy operation succedded.  The values returned
are defined in the swish-e source file /src/stemmer.h.</p>
</li>
<li><a name="item__words"></a><a name="_words"></a><b>@words = $fuzzy_word-&gt;word_list;</b>
<p>Returns the converted words from the stemming/fuzzy operation.  Normally, the array will
contain a single element, although may contain more (i.e. if DoubleMetaphone is
used and the input word returns two strings).</p>
<p>In the event that a word does not stem (e.g. trying to stem a number), this method
will return the original input word specified when $result-&gt;fuzzy_word( $word )
was called.</p>
</li>
<li><a name="item__parsed_words"></a><a name="_parsed_words"></a><b>@parsed_words = $swish-&gt;swish_words( $string, $index_file );</b>
<p>* Not implemented *</p>
<p>Splits up the input string into tokens of swish words and operators.</p>
</li>
</ul>

    </div>

    <div class="sub-section">
        
<h1><a name="notes"></a>NOTES</h1>

<p>Perl's garbage collection makes it easy to write code for searching with Swish-e,
but care must be taken not to keep objects around too long which can use up memory.</p>
<p>Here's an example of a potential problem.  Say you have a very large number
of documents indexed and you want to find the first hit for a number of
popular keywords (error checking omitted in this bad example):</p>
<pre class="pre-section">    sub first_hit {
      my $query = shift;
      my $handle = SWISH::API-&gt;new( 'index.swish-e');
      my $results = $handle-&gt;query( $query );
      my $first_hit = $results-&gt;next_result;
      return $first_hit;
    }

    my @first_hit_list;
    for ( @keywords )
        push @first_hit_list, $first_hit($_);
    }</pre>
<p>The first_hit() subroutine is returning a SWISH::Result object.  That makes
it easy to access properties:</p>
<pre class="pre-section">   # print file names
   for my $result ( @first_hit_list ) {
      print $result-&gt;property('swishdocpath'),"\n";
   }</pre>
<p>But as long as a SWISH::API::Result object is around, so is the entire list
of results generated by the $handle-&gt;query() call, and the index file is
still open (because a SWISH::API::Result depends on a SWISH::API::Results object, which
depends on a SWISH::API object).</p>
<p>In this case it would be better to return from first_hit() just the
properties you need:</p>
<pre class="pre-section">      ...
      my $first_hit = $results-&gt;next_result;
      return $first_hit-&gt;property('swishdocpath');
   }</pre>
<p>Then when first_hit() sub ends the result list will be freed, and the
index file closed, thanks to Perl's reference count tracking.</p>
<p>Note: the other problem with the above code is that the same index file is
opened for each call to the function.  Don't do that, instead open the
index file once.</p>

    </div>

    <div class="sub-section">
        
<h1><a name="copyright"></a>COPYRIGHT</h1>

<p>This library is free software; you can redistribute it
and/or modify it under the same terms as Perl itself.</p>

    </div>

    <div class="sub-section">
        
<h1><a name="author"></a>AUTHOR</h1>

<p>Bill Moseley moseley@hank.org. 2002/2003/2004</p>

    </div>

    <div class="sub-section">
        
<h1><a name="support"></a>SUPPORT</h1>

<p>Please contact the Swish-e discussion email list for support with this module
or with Swish-e.  Please do not contact the developers directly.</p>

    </div>















</div>

<!-- ##### Footer ##### -->
<!-- noindex -->

<div id="footer">
    <span class="doNotPrint">
        Swish-e is distributed with <strong>no warranty</strong> under the terms of the <br />
        <a href='/license.html'>Swish-e License</a>.<br />
        Questions may be posted to the 
        <a href="http://swish-e.org/discuss.html" title="email list and list archive">Swish-e Discussion list</a>.
    </span>

    <p>
    <SCRIPT type='text/javascript' language='JavaScript'
             src='http://www.ohloh.net/projects/3196;badge_js'></SCRIPT>
    </p>

    <p>
        <strong>URI &raquo;</strong> http://swish-e.org/ 
        &bull; <strong>Updated &raquo;</strong> Thu, 21 Sep 2006 22:24:49 UTC
    </p>
</div>
<!-- index -->



</body>
</html>