user/dev discussion of public-inbox itself
 help / color / mirror / Atom feed
* [PATCH] search: query_approxidate: cleanup regexp, more tests
@ 2021-02-11  5:57 Eric Wong
  0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2021-02-11  5:57 UTC (permalink / raw)
  To: meta

The cleanup doesn't seem to matter, I initially thought I needed
to handle "" (two double quotes) explicitly because that's what
Xapian does to escape a double quote inside a double-quoted
phrase.  It turns out we only need to be able to pass phrases
through to Xapian unmodified, and the existing group of
["\x{201c}\x{201d}] is sufficient for our purposes.
---
 lib/PublicInbox/Search.pm |  2 +-
 t/search.t                | 21 +++++++++++++++++++++
 2 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/lib/PublicInbox/Search.pm b/lib/PublicInbox/Search.pm
index 520aa31d..c5a1bd69 100644
--- a/lib/PublicInbox/Search.pm
+++ b/lib/PublicInbox/Search.pm
@@ -357,7 +357,7 @@ sub query_approxidate {
 	my $DQ = qq<"\x{201c}\x{201d}>; # Xapian can use curly quotes
 	$_[2] =~ tr/\x00/ /; # Xapian doesn't do NUL, we use it as a placeholder
 	my ($terms, $phrase, $to_parse);
-	$_[2] =~ s{([^$DQ]*)([${DQ}][^\"]*[$DQ])?}{
+	$_[2] =~ s{([^$DQ]*)([$DQ][^$DQ]*[$DQ])?}{
 		($terms, $phrase) = ($1, $2);
 		$terms =~ s!\b(d|rt|dt):(\S+)!
 			date_parse_prepare($to_parse //= [], $1, $2)!sge;
diff --git a/t/search.t b/t/search.t
index effba1df..124c9acf 100644
--- a/t/search.t
+++ b/t/search.t
@@ -603,6 +603,27 @@ SKIP: {
 	is($qs, qq[f:bob "hello world" d:19931002..20101002],
 		'post-phrase date corrected');
 
+	# Xapian uses "" to escape " inside phrases, we don't explictly
+	# handle that, but are able to pass the result through unchanged
+	for my $pair (["\x{201c}", "\x{201d}"], ['"', '"']) {
+		my ($x, $y) = @$pair;
+		$orig = $qs = qq[${x}hello d:1993-10-02.."" world$y];
+		$s->query_approxidate($g, $qs);
+		is($qs, $orig, 'phrases unchanged \x'.ord($x).'-\x'.ord($y));
+
+		$s->query_approxidate($g, my $tmp = "$qs d:..2010-10-02");
+		is($tmp, "$orig d:..20101002",
+			'two phrases did not throw off date parsing');
+
+		$orig = $qs = qq[${x}hello d:1993-10-02..$y$x world$y];
+		$s->query_approxidate($g, $qs);
+		is($qs, $orig, 'phrases unchanged \x'.ord($x).'-\x'.ord($y));
+
+		$s->query_approxidate($g, $tmp = "$qs d:..2010-10-02");
+		is($tmp, "$orig d:..20101002",
+			'two phrases did not throw off date parsing');
+	}
+
 	my $x_days_ago = strftime('%Y%m%d', gmtime(time - (5 * 86400)));
 	$orig = $qs = qq[broken d:5.days.ago..];
 	$s->query_approxidate($g, $qs);

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-02-11  5:57 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-11  5:57 [PATCH] search: query_approxidate: cleanup regexp, more tests Eric Wong

user/dev discussion of public-inbox itself

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://public-inbox.org/meta
	git clone --mirror http://czquwvybam4bgbro.onion/meta
	git clone --mirror http://hjrcffqmbrq6wope.onion/meta
	git clone --mirror http://ou63pmih66umazou.onion/meta

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 meta meta/ https://public-inbox.org/meta \
		meta@public-inbox.org
	public-inbox-index meta

Example config snippet for mirrors.
Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.mail.public-inbox.meta
	nntp://ou63pmih66umazou.onion/inbox.comp.mail.public-inbox.meta
	nntp://czquwvybam4bgbro.onion/inbox.comp.mail.public-inbox.meta
	nntp://hjrcffqmbrq6wope.onion/inbox.comp.mail.public-inbox.meta
	nntp://news.gmane.io/gmane.mail.public-inbox.general
 note: .onion URLs require Tor: https://www.torproject.org/

code repositories for the project(s) associated with this inbox:

	https://80x24.org/public-inbox.git

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git