Namazu-users-ja(旧)


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Search::Namazu::Search(date値の取得)



いわきりです

#patchを採用してほしいなぁ > 野首さん

S Okiyama wrote in <002901c330a9$b1ea6280$23dba8c0@genome7> :
>問題主旨としまして、
>(1)Search::Namazuでのfiled名指定のsort方法と
>(field sort機能は活きていますか)

機能していません。

S Okiyama wrote in <004401c330b7$5d257470$23dba8c0@genome7> :
>(3)ソース改変なしに対応できる技等があれば使用したい。
>(ソース改変はバージョンup時に作業漏れの対象となりえる危険を含む、
> また、的確な使用方法であるかによりデグレの可能性あり)

毎度の改変を考えるなら、コミッターにpatchを送って採用してもらうとか、
コミッターをやらせてくださいとお願いするのもありかと :)

sortの昇順/降順のpatchがどう当たっていたかよく見てないので
sortorderが逆転するかもしれませんが、nmz_set_sortfield()を
Search::Namazuで有効にするpatchを送ります。


diff -u Search-Namazu-0.92/Namazu.pm Search-Namazu-test/Namazu.pm
--- Search-Namazu-0.92/Namazu.pm	Wed Jun 19 19:01:10 2002
+++ Search-Namazu-test/Namazu.pm	Thu Jun 12 18:26:30 2003
@@ -205,6 +205,7 @@
     my %args = @_;
     my $index = $args{'index'};
     my $sortmeth = $args{'sortMethod'};
+    my $sortfield = $args{'sortField'};
     my $sortord = $args{'sortOrder'};
     my $lang = $args{'lang'};
     my $query = $args{'query'};
@@ -237,7 +238,7 @@
     } elsif ($sortmeth == NMZ_SORTBYSCORE) {
 	nmz_sortbyscore();
     } elsif ($sortmeth == NMZ_SORTBYFIELD) {
-	nmz_sortbyfield();
+	nmz_sortbyfield($sortfield);
     } else {
 	nmz_sortbydate();
     }
@@ -289,7 +290,7 @@
 }
 
 sub set {
-    my ($self, $score, $uri, $date, $rank, $summary, $title, $author) = @_;
+    my ($self, $score, $uri, $date, $rank, $summary, $title, $author, 
$sdate) = @_;
     $self->{score} = $score;
     $self->{uri} = $uri;
     $self->{date} = $date;
@@ -297,6 +298,7 @@
     $self->{summary} = $summary;
     $self->{title} = $title;
     $self->{author} = $author;
+    $self->{sdate} = $sdate;
 }
 
 sub score {
@@ -362,6 +364,15 @@
     $self->{'author'};
 }
 
+sub sdate {
+    my $self = shift;
+    if (@_) {
+	my $sdate = shift;
+	$self->{'sdate'} = $sdate;
+    }
+    $self->{'sdate'};
+}
+
 1;
 __END__
 
diff -u Search-Namazu-0.92/Namazu.xs Search-Namazu-test/Namazu.xs
--- Search-Namazu-0.92/Namazu.xs	Wed Jun 19 19:01:10 2002
+++ Search-Namazu-test/Namazu.xs	Thu Jun 12 18:10:23 2003
@@ -68,7 +68,7 @@
 		int i;
 		AV *retar;
 		NmzResult hlist;
-		char result[4][BUFSIZE];
+		char result[5][BUFSIZE];
 
 		qstr = SvPV(query, PL_na);
 		strcpy(cqstr, qstr);
@@ -81,6 +81,7 @@
 			nmz_get_field_data(hlist.data[i].idxid, hlist.data[i].docid, "summary", 
result[1]);
 			nmz_get_field_data(hlist.data[i].idxid, hlist.data[i].docid, "title", 
result[2]);
 			nmz_get_field_data(hlist.data[i].idxid, hlist.data[i].docid, "author", 
result[3]);
+			nmz_get_field_data(hlist.data[i].idxid, hlist.data[i].docid, "date", 
result[4]);
 			ENTER;
 			SAVETMPS;
 			PUSHMARK(SP);
@@ -92,6 +93,7 @@
 			PUSHs(sv_2mortal(newSVpv(result[1], strlen(result[1]))));
 			PUSHs(sv_2mortal(newSVpv(result[2], strlen(result[2]))));
 			PUSHs(sv_2mortal(newSVpv(result[3], strlen(result[3]))));
+			PUSHs(sv_2mortal(newSVpv(result[4], strlen(result[4]))));
 			PUTBACK;
 			perl_call_method("set", G_DISCARD);
 			av_push(retar, ohlist);
@@ -127,27 +129,34 @@
 void
 nmz_sortbydate()
 	CODE:
-		nmz_set_sortmethod(SORT_BY_SCORE);
+		nmz_set_sortmethod(SORT_BY_DATE);
 
 void
 nmz_sortbyscore()
 	CODE:
-		nmz_set_sortmethod(SORT_BY_DATE);
+		nmz_set_sortmethod(SORT_BY_SCORE);
 
 void
-nmz_sortbyfield()
+nmz_sortbyfield(field)
+	SV *field
+
+	PREINIT:
+		char *tmp;
+
 	CODE:
+		tmp = SvPV(field, PL_na);
 		nmz_set_sortmethod(SORT_BY_FIELD);
+		nmz_set_sortfield(tmp);
 
 void
 nmz_descendingsort()
 	CODE:
-		nmz_set_sortorder(ASCENDING);
+		nmz_set_sortorder(DESCENDING);
 
 void
 nmz_ascendingsort()
 	CODE:
-		nmz_set_sortorder(DESCENDING);
+		nmz_set_sortorder(ASCENDING);
 
 int
 nmz_setlang(lang)

-- 
Youichi Iwakiri