Changeset 246

Show
Ignore:
Timestamp:
03/29/06 09:38:41 (6 years ago)
Author:
knok
Message:

Added "fields" parameter.

Location:
Search-Namazu/trunk/Search-Namazu
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • Search-Namazu/trunk/Search-Namazu/ChangeLog

    r245 r246  
     12006-03-29  NOKUBI Takatsugu  <knok@daionet.gr.jp> 
     2 
     3        * Namazu.{xs,pm}: Added "fields" parameter. 
     4 
    152006-03-28  NOKUBI Takatsugu  <knok@daionet.gr.jp> 
    26 
  • Search-Namazu/trunk/Search-Namazu/Namazu.pm

    r244 r246  
    4040  } 
    4141 
     42  $x = Search::Namazu::Search(index => '/usr/local/namazu/index', 
     43                                query => 'foo', 
     44                                fields => ["uri", "score", "from"]); 
     45 
     46  foreach my $rxs (@$x) { 
     47      print ($rxs->get("uri"), $rxs->get("score"), $rxs->get("from")); 
     48  } 
     49 
    4250=head1 DESCRIPTION 
    4351 
     
    141149returns a reference of array as a result. 
    142150 
     151=head3 fields 
     152 
     153Specify you want to get fields as a refrence of array. In the case, 
     154the result is returned as a reference of array, contains 
     155Search::Namazu::ResultXS objects. 
     156 
    143157=head2 Search::Namazu::Result 
    144158 
     
    177191 
    178192It returns size. 
     193 
     194=head2 Search::Namazu::ResultXS 
     195 
     196Search::Namazu::ResultXS object is also for keeping result information. 
     197It has the following methods: 
     198 
     199=head3 get 
     200 
     201It returns specified value of field. 
    179202 
    180203=head1 COPYRIGHT 
     
    242265    my $returnas = $args{'returnas'}; 
    243266    my $maxget = $args{'maxget'} || $maxhit; 
     267    my $fields = $args{'fields'}; 
    244268 
    245269# initialize 
     
    299323# create Search::Namazu::Result object 
    300324 
    301     if ($returnas eq 'reference') { 
     325    if (ref($fields) eq "ARRAY") { 
     326        my $hlistref = call_search_main_fields($query, $maxget, $fields); 
     327        my $status = nmz_getstatus(); 
     328        if ($status != NMZ_SUCCESS) { 
     329            return $status; 
     330        } 
     331        # return objects 
     332        return $hlistref; 
     333    } elsif ($returnas eq 'reference') { 
    302334        my $hlistref = call_search_main_ref($query, $maxget); 
    303335        my $status = nmz_getstatus(); 
  • Search-Namazu/trunk/Search-Namazu/Namazu.xs

    r245 r246  
    6767        status = 0; 
    6868        retar = newAV(); 
     69        hlist = nmz_search(query); 
    6970        av_extend(retar, hlist.num - 1); 
    70         hlist = nmz_search(query); 
    7171        status = hlist.stat; 
    7272        for (i = 0; i < hlist.num; i ++) { 
     
    105105} 
    106106 
     107AV * call_search_main_fields_c(char *query, int maxget, AV *fields) 
     108{ 
     109        AV *retar; 
     110        HV *stash; 
     111        char **fstr; 
     112        int *fsize; 
     113        NmzResult hlist; 
     114        int i; 
     115        int flen; 
     116 
     117        retar = newAV(); 
     118        flen = av_len(fields); 
     119        if (flen < 0 || maxget <= 0 || query == NULL) 
     120                return retar; 
     121        status = 0; 
     122        fstr = (char **) malloc(sizeof(char *) * (flen + 1)); 
     123        fsize = (int *) malloc(sizeof(int) * (flen + 1)); 
     124        for (i = 0; i <= flen; i ++) { 
     125                SV **x; 
     126                x = av_fetch(fields, i, 0); 
     127                fstr[i] = SvPV_nolen(*x); 
     128                fsize[i] = SvCUR(*x); 
     129        } 
     130        hlist = nmz_search(query); 
     131        av_extend(retar, hlist.num - 1); 
     132        status = hlist.stat; 
     133        stash = gv_stashpv("Search::Namazu::ResultXS", 0); 
     134        for (i = 0; i < hlist.num; i ++) { 
     135                if (i < maxget) { 
     136                        HV *hash; 
     137                        SV *ref; 
     138                        int j; 
     139                        char fcont[BUFSIZE]; 
     140 
     141                        hash = newHV(); 
     142                        for (j = 0; j <= flen; j ++) { 
     143                                nmz_get_field_data(hlist.data[i].idxid, 
     144                                        hlist.data[i].docid, 
     145                                        fstr[j], fcont); 
     146                                hv_store(hash, fstr[j], fsize[j],  
     147                                        newSVpv(fcont, strlen(fcont)), 0); 
     148                        } 
     149 
     150                        ref = newRV_inc((SV*) hash); 
     151                        sv_bless(ref, stash); 
     152                        av_store(retar, i, ref); 
     153                } else { 
     154                        av_store(retar, i, &PL_sv_undef); 
     155                } 
     156        } 
     157        nmz_free_hlist(hlist); 
     158        free(fstr); 
     159        free(fsize); 
     160        return retar; 
     161} 
     162 
    107163MODULE = Search::Namazu         PACKAGE = Search::Namazu 
    108164 
     
    155211                RETVAL 
    156212 
     213SV* 
     214call_search_main_fields(query, maxget, fieldref) 
     215        SV *query 
     216        int maxget 
     217        SV *fieldref 
     218 
     219        CODE: 
     220                char *qstr; 
     221                char cqstr[BUFSIZE * 2]; 
     222                AV *retar; 
     223                AV *fields; 
     224                int i; 
     225 
     226                fields = (AV *) SvRV(fieldref); 
     227                qstr = SvPV(query, PL_na); 
     228                nmz_codeconv_query(qstr); 
     229                strcpy(cqstr, qstr); 
     230                retar = call_search_main_fields_c(cqstr, maxget, fields); 
     231                nmz_free_internal(); 
     232                RETVAL = newRV_inc((SV*) retar); 
     233        OUTPUT: 
     234                RETVAL 
     235 
    157236int 
    158237nmz_addindex(index)