You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucy.apache.org by ma...@apache.org on 2011/11/10 20:15:11 UTC

[lucy-commits] svn commit: r1200481 - in /incubator/lucy/trunk: core/Lucy/Highlight/Highlighter.c perl/t/303-highlighter.t

Author: marvin
Date: Thu Nov 10 19:15:10 2011
New Revision: 1200481

URL: http://svn.apache.org/viewvc?rev=1200481&view=rev
Log:
LUCY-188 Highlighter should accept weighted Queries (Compilers).

Highlighter should accept pre-weighted Compiler objects, using the
supplied Query if it isa Compiler rather than invoking Make_Compiler()
on it.

Modified:
    incubator/lucy/trunk/core/Lucy/Highlight/Highlighter.c
    incubator/lucy/trunk/perl/t/303-highlighter.t

Modified: incubator/lucy/trunk/core/Lucy/Highlight/Highlighter.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/core/Lucy/Highlight/Highlighter.c?rev=1200481&r1=1200480&r2=1200481&view=diff
==============================================================================
--- incubator/lucy/trunk/core/Lucy/Highlight/Highlighter.c (original)
+++ incubator/lucy/trunk/core/Lucy/Highlight/Highlighter.c Thu Nov 10 19:15:10 2011
@@ -57,14 +57,19 @@ Highlighter_init(Highlighter *self, Sear
     self->query          = Searcher_Glean_Query(searcher, query);
     self->searcher       = (Searcher*)INCREF(searcher);
     self->field          = CB_Clone(field);
-    self->compiler       = Query_Make_Compiler(self->query, searcher,
-                                               Query_Get_Boost(self->query),
-                                               false);
     self->excerpt_length = excerpt_length;
     self->slop           = excerpt_length / 3;
     self->window_width   = excerpt_length + (self->slop * 2);
     self->pre_tag        = CB_new_from_trusted_utf8("<strong>", 8);
     self->post_tag       = CB_new_from_trusted_utf8("</strong>", 9);
+    if (Query_Is_A(self->query, COMPILER)) {
+        self->compiler = (Compiler*)INCREF(self->query);
+    }
+    else {
+        self->compiler = Query_Make_Compiler(self->query, searcher,
+                                             Query_Get_Boost(self->query),
+                                             false);
+    }
     return self;
 }
 

Modified: incubator/lucy/trunk/perl/t/303-highlighter.t
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/perl/t/303-highlighter.t?rev=1200481&r1=1200480&r2=1200481&view=diff
==============================================================================
--- incubator/lucy/trunk/perl/t/303-highlighter.t (original)
+++ incubator/lucy/trunk/perl/t/303-highlighter.t Thu Nov 10 19:15:10 2011
@@ -55,7 +55,7 @@ sub highlight {
 
 package main;
 
-use Test::More tests => 35;
+use Test::More tests => 37;
 use Lucy::Test;
 
 binmode( STDOUT, ":utf8" );
@@ -374,6 +374,18 @@ is_deeply(
     "Skip leading whitespace but get first sentence"
 );
 
+$q = $searcher->glean_query("foo");
+my $compiler = $q->make_compiler(searcher => $searcher);
+$hl = Lucy::Highlight::Highlighter->new(
+    searcher => $searcher,
+    query    => $compiler,
+    field    => 'content',
+);
+is( $$compiler, ${ $hl->get_query },
+    "Highlighter accepts Compiler as Query" );
+is( $$compiler, ${ $hl->get_compiler },
+    "Highlighter uses supplied Compiler" );
+
 $hl = MyHighlighter->new(
     searcher => $searcher,
     query    => "blind",