[Namazu-cvs 756] r244 - Search-Namazu/trunk/Search-Namazu

cvsd @ vaj.namazu.org cvsd @ vaj.namazu.org
2006年 3月 28日 (火) 13:48:19 JST


Author: knok
Date: 2006-03-28 13:48:18 +0900 (Tue, 28 Mar 2006)
New Revision: 244

Modified:
   Search-Namazu/trunk/Search-Namazu/ChangeLog
   Search-Namazu/trunk/Search-Namazu/Namazu.pm
   Search-Namazu/trunk/Search-Namazu/Namazu.xs
Log:
Added maxget parameter.


Modified: Search-Namazu/trunk/Search-Namazu/ChangeLog
===================================================================
--- Search-Namazu/trunk/Search-Namazu/ChangeLog	2006-03-27 07:44:22 UTC (rev 243)
+++ Search-Namazu/trunk/Search-Namazu/ChangeLog	2006-03-28 04:48:18 UTC (rev 244)
@@ -1,3 +1,7 @@
+2006-03-28  NOKUBI Takatsugu  <knok @ daionet.gr.jp>
+
+	* Namazu.{xs,pm}: Added maxget parameter.
+
 2006-03-27  NOKUBI Takatsugu  <knok @ daionet.gr.jp>
 
 	* Namazu.pm (Search): Add a new parameter 'returnas'.

Modified: Search-Namazu/trunk/Search-Namazu/Namazu.pm
===================================================================
--- Search-Namazu/trunk/Search-Namazu/Namazu.pm	2006-03-27 07:44:22 UTC (rev 243)
+++ Search-Namazu/trunk/Search-Namazu/Namazu.pm	2006-03-28 04:48:18 UTC (rev 244)
@@ -130,8 +130,13 @@
 
 Speciry maximum numbers of hits. Same as MaxHit directive in namazurc.
 
-=head4 returnas
+=head3 maxget
 
+Speciry result object numbers of hits to limit too many results.
+If the parameter was omitted, it is assumed same value as maxhit.
+
+=head3 returnas
+
 Specify return method, if the parameter is set as 'reference', it
 returns a reference of array as a result.
 
@@ -233,8 +238,9 @@
     my $sortord = $args{'sortOrder'};
     my $lang = $args{'lang'};
     my $query = $args{'query'};
-    my $maxhit = $args{'maxhit'};
+    my $maxhit = $args{'maxhit'} || 10000;
     my $returnas = $args{'returnas'};
+    my $maxget = $args{'maxget'} || $maxhit;
 
 # initialize
 
@@ -282,7 +288,7 @@
     if (defined $lang) {
 	nmz_setlang($lang);
     }
-    nmz_setmaxhit($maxhit) if defined $maxhit;
+    nmz_setmaxhit($maxhit);
 
 # query and get hlist
 
@@ -293,7 +299,7 @@
 # create Search::Namazu::Result object
 
     if ($returnas eq 'reference') {
-	my $hlistref = call_search_main_ref($query);
+	my $hlistref = call_search_main_ref($query, $maxget);
 	my $status = nmz_getstatus();
 	if ($status != NMZ_SUCCESS) {
 	    return $status;
@@ -301,7 +307,7 @@
 	# return objects
 	return $hlistref;
     } else {
-	my @hlists = call_search_main($query);
+	my @hlists = call_search_main($query, $maxget);
 	my $status = nmz_getstatus();
 	if ($status != NMZ_SUCCESS) {
 	    return $status;

Modified: Search-Namazu/trunk/Search-Namazu/Namazu.xs
===================================================================
--- Search-Namazu/trunk/Search-Namazu/Namazu.xs	2006-03-27 07:44:22 UTC (rev 243)
+++ Search-Namazu/trunk/Search-Namazu/Namazu.xs	2006-03-28 04:48:18 UTC (rev 244)
@@ -58,7 +58,7 @@
 
 static int status = 0;
 
-AV * call_search_main_c(char *query)
+AV * call_search_main_c(char *query, int maxget)
 {
 	AV *retar;
 	NmzResult hlist;
@@ -66,9 +66,11 @@
 	int i;
 	status = 0;
 	retar = newAV();
+	av_extend(retar, hlist.num - 1);
 	hlist = nmz_search(query);
 	status = hlist.stat;
 	for (i = 0; i < hlist.num; i ++) {
+	    if (i < maxget) {
 		SV *ohlist = perl_eval_pv("new Search::Namazu::Result", TRUE);
 		dSP;
 		nmz_get_field_data(hlist.data[i].idxid, hlist.data[i].docid, "uri", result[0]);
@@ -91,9 +93,12 @@
 		PUTBACK;
 		perl_call_method("set", G_DISCARD);
 		SvREFCNT_inc(ohlist);
-		av_push(retar, ohlist);
+		av_store(retar, i, ohlist);
 		FREETMPS;
 		LEAVE;
+	    } else {
+		av_store(retar, i, &PL_sv_undef);
+	    }	   
 	}
 	nmz_free_hlist(hlist);
 	return retar;
@@ -104,8 +109,9 @@
 PROTOTYPES: DISABLE
 
 void
-call_search_main(query)
+call_search_main(query, maxget)
 	SV *query
+	int maxget
 
 	PPCODE:
 		char *qstr;
@@ -116,7 +122,7 @@
 		qstr = SvPV(query, PL_na);
 		nmz_codeconv_query(qstr);
 		strcpy(cqstr, qstr);
-		retar = call_search_main_c(cqstr);
+		retar = call_search_main_c(cqstr, maxget);
 #if ! defined(PERL_VERSION)
 		{ /* workaround for only one result */
 			SV *ohlist = perl_eval_pv("new Search::Namazu::Result", TRUE);
@@ -129,8 +135,9 @@
 		nmz_free_internal();
 
 SV*
-call_search_main_ref(query)
+call_search_main_ref(query, maxget)
 	SV *query
+	int maxget
 
 	CODE:
 		char *qstr;
@@ -141,7 +148,7 @@
 		qstr = SvPV(query, PL_na);
 		nmz_codeconv_query(qstr);
 		strcpy(cqstr, qstr);
-		retar = call_search_main_c(cqstr);
+		retar = call_search_main_c(cqstr, maxget);
 		nmz_free_internal();
 		RETVAL = newRV_inc((SV*) retar);
 	OUTPUT:
@@ -202,7 +209,7 @@
 
 void
 nmz_setmaxhit(max)
-	int max;
+	int max
 
 	CODE:
 		nmz_set_maxhit(max);




Namazu-cvs メーリングリストの案内