Archive of RubyForge sup-devel mailing list
 help / color / mirror / Atom feed
* [sup-devel] [PATCH] catch xapian query parser exceptions and display them to the user
@ 2010-02-15 18:30 Michael Stapelberg
  2010-02-16 11:10 ` Olly Betts
  2010-02-27  7:46 ` Rich Lane
  0 siblings, 2 replies; 3+ messages in thread
From: Michael Stapelberg @ 2010-02-15 18:30 UTC (permalink / raw)
  To: sup-devel

[-- Attachment #1: Type: text/plain, Size: 414 bytes --]

Hi,

a query such as "NOT label:debian" will generate an error in the xapian query
parser. Instead of crashing, the user should see the error message to get his
query right. The attached patch fixes this.

Please note that the appropriate type instead of RuntimeError would be
Xapian::QueryParserError, but the latter is not defined for some reason. A
problem with the xapian ruby bindings?

Best regards,
Michael

[-- Attachment #2: 0001-xapian.patch --]
[-- Type: application/octet-stream, Size: 1307 bytes --]

From 63e61d0b026c5da875a771e8fb0e6e8ff8d8dae3 Mon Sep 17 00:00:00 2001
From: Michael Stapelberg <michael@stapelberg.de>
Date: Mon, 15 Feb 2010 19:27:38 +0100
Subject: [PATCH] catch xapian query parser exceptions and display them to the user

---
 lib/sup/xapian_index.rb |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)

diff --git a/lib/sup/xapian_index.rb b/lib/sup/xapian_index.rb
index cf701b4..c3d492b 100644
--- a/lib/sup/xapian_index.rb
+++ b/lib/sup/xapian_index.rb
@@ -265,7 +265,11 @@ EOS
     qp.add_valuerangeprocessor(Xapian::NumberValueRangeProcessor.new(DATE_VALUENO, 'date:', true))
     NORMAL_PREFIX.each { |k,v| qp.add_prefix k, v }
     BOOLEAN_PREFIX.each { |k,v| qp.add_boolean_prefix k, v }
-    xapian_query = qp.parse_query(subs, Xapian::QueryParser::FLAG_PHRASE|Xapian::QueryParser::FLAG_BOOLEAN|Xapian::QueryParser::FLAG_LOVEHATE|Xapian::QueryParser::FLAG_WILDCARD, PREFIX['body'])
+    begin
+      xapian_query = qp.parse_query(subs, Xapian::QueryParser::FLAG_PHRASE|Xapian::QueryParser::FLAG_BOOLEAN|Xapian::QueryParser::FLAG_LOVEHATE|Xapian::QueryParser::FLAG_WILDCARD, PREFIX['body'])
+    rescue RuntimeError => e
+      raise ParseError, "xapian query parser error: #{e}"
+    end
 
     debug "parsed xapian query: #{xapian_query.description}"
 
-- 
1.6.5


[-- Attachment #3: Type: text/plain, Size: 143 bytes --]

_______________________________________________
Sup-devel mailing list
Sup-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-devel

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [sup-devel] [PATCH] catch xapian query parser exceptions and display them to the user
  2010-02-15 18:30 [sup-devel] [PATCH] catch xapian query parser exceptions and display them to the user Michael Stapelberg
@ 2010-02-16 11:10 ` Olly Betts
  2010-02-27  7:46 ` Rich Lane
  1 sibling, 0 replies; 3+ messages in thread
From: Olly Betts @ 2010-02-16 11:10 UTC (permalink / raw)
  To: sup-devel

Michael Stapelberg writes:
> Please note that the appropriate type instead of RuntimeError would be
> Xapian::QueryParserError, but the latter is not defined for some reason. A
> problem with the xapian ruby bindings?

Currently Xapian's exception hierarchy isn't wrapped for Ruby.  I suspect my
Ruby skills aren't up to fixing that, though I'm certainly happy to help if
anyone wants to tackle it.

Cheers,
    Olly

_______________________________________________
Sup-devel mailing list
Sup-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-devel


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [sup-devel] [PATCH] catch xapian query parser exceptions and display them to the user
  2010-02-15 18:30 [sup-devel] [PATCH] catch xapian query parser exceptions and display them to the user Michael Stapelberg
  2010-02-16 11:10 ` Olly Betts
@ 2010-02-27  7:46 ` Rich Lane
  1 sibling, 0 replies; 3+ messages in thread
From: Rich Lane @ 2010-02-27  7:46 UTC (permalink / raw)
  To: Michael Stapelberg; +Cc: sup-devel

Applied to master.
_______________________________________________
Sup-devel mailing list
Sup-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-devel


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2010-02-27  7:46 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-02-15 18:30 [sup-devel] [PATCH] catch xapian query parser exceptions and display them to the user Michael Stapelberg
2010-02-16 11:10 ` Olly Betts
2010-02-27  7:46 ` Rich Lane

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox