Changeset 246
- Timestamp:
- 03/29/06 09:38:41 (6 years ago)
- Location:
- Search-Namazu/trunk/Search-Namazu
- Files:
-
- 3 modified
Legend:
- Unmodified
- Added
- Removed
-
Search-Namazu/trunk/Search-Namazu/ChangeLog
r245 r246 1 2006-03-29 NOKUBI Takatsugu <knok@daionet.gr.jp> 2 3 * Namazu.{xs,pm}: Added "fields" parameter. 4 1 5 2006-03-28 NOKUBI Takatsugu <knok@daionet.gr.jp> 2 6 -
Search-Namazu/trunk/Search-Namazu/Namazu.pm
r244 r246 40 40 } 41 41 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 42 50 =head1 DESCRIPTION 43 51 … … 141 149 returns a reference of array as a result. 142 150 151 =head3 fields 152 153 Specify you want to get fields as a refrence of array. In the case, 154 the result is returned as a reference of array, contains 155 Search::Namazu::ResultXS objects. 156 143 157 =head2 Search::Namazu::Result 144 158 … … 177 191 178 192 It returns size. 193 194 =head2 Search::Namazu::ResultXS 195 196 Search::Namazu::ResultXS object is also for keeping result information. 197 It has the following methods: 198 199 =head3 get 200 201 It returns specified value of field. 179 202 180 203 =head1 COPYRIGHT … … 242 265 my $returnas = $args{'returnas'}; 243 266 my $maxget = $args{'maxget'} || $maxhit; 267 my $fields = $args{'fields'}; 244 268 245 269 # initialize … … 299 323 # create Search::Namazu::Result object 300 324 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') { 302 334 my $hlistref = call_search_main_ref($query, $maxget); 303 335 my $status = nmz_getstatus(); -
Search-Namazu/trunk/Search-Namazu/Namazu.xs
r245 r246 67 67 status = 0; 68 68 retar = newAV(); 69 hlist = nmz_search(query); 69 70 av_extend(retar, hlist.num - 1); 70 hlist = nmz_search(query);71 71 status = hlist.stat; 72 72 for (i = 0; i < hlist.num; i ++) { … … 105 105 } 106 106 107 AV * 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 107 163 MODULE = Search::Namazu PACKAGE = Search::Namazu 108 164 … … 155 211 RETVAL 156 212 213 SV* 214 call_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 157 236 int 158 237 nmz_addindex(index)
