lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From k...@apache.org
Subject svn commit: r1184756 - in /lucene/dev/branches/branch_3x: ./ lucene/ lucene/backwards/src/test/ lucene/contrib/ lucene/contrib/highlighter/src/java/org/apache/lucene/search/vectorhighlight/ lucene/contrib/highlighter/src/test/org/apache/lucene/search/v...
Date Sun, 16 Oct 2011 04:01:59 GMT
Author: koji
Date: Sun Oct 16 04:01:58 2011
New Revision: 1184756

URL: http://svn.apache.org/viewvc?rev=1184756&view=rev
Log:
LUCENE-3513: Add SimpleFragListBuilder constructor with margin parameter

Modified:
    lucene/dev/branches/branch_3x/   (props changed)
    lucene/dev/branches/branch_3x/lucene/   (props changed)
    lucene/dev/branches/branch_3x/lucene/backwards/src/test/   (props changed)
    lucene/dev/branches/branch_3x/lucene/contrib/CHANGES.txt
    lucene/dev/branches/branch_3x/lucene/contrib/highlighter/src/java/org/apache/lucene/search/vectorhighlight/SimpleFragListBuilder.java
    lucene/dev/branches/branch_3x/lucene/contrib/highlighter/src/test/org/apache/lucene/search/vectorhighlight/SimpleFragListBuilderTest.java
    lucene/dev/branches/branch_3x/solr/   (props changed)

Modified: lucene/dev/branches/branch_3x/lucene/contrib/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/contrib/CHANGES.txt?rev=1184756&r1=1184755&r2=1184756&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/contrib/CHANGES.txt (original)
+++ lucene/dev/branches/branch_3x/lucene/contrib/CHANGES.txt Sun Oct 16 04:01:58 2011
@@ -76,6 +76,9 @@ API Changes
  * LUCENE-3436: Add SuggestMode to the spellchecker, so you can specify the strategy
    for suggesting related terms.  (James Dyer via Robert Muir)
 
+ * LUCENE-3513: Add SimpleFragListBuilder constructor with margin parameter.
+   (Kelsey Francis via Koji Sekiguchi)
+
 ======================= Lucene 3.4.0 ================
 
 New Features

Modified: lucene/dev/branches/branch_3x/lucene/contrib/highlighter/src/java/org/apache/lucene/search/vectorhighlight/SimpleFragListBuilder.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/contrib/highlighter/src/java/org/apache/lucene/search/vectorhighlight/SimpleFragListBuilder.java?rev=1184756&r1=1184755&r2=1184756&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/contrib/highlighter/src/java/org/apache/lucene/search/vectorhighlight/SimpleFragListBuilder.java
(original)
+++ lucene/dev/branches/branch_3x/lucene/contrib/highlighter/src/java/org/apache/lucene/search/vectorhighlight/SimpleFragListBuilder.java
Sun Oct 16 04:01:58 2011
@@ -28,13 +28,28 @@ import org.apache.lucene.search.vectorhi
  */
 public class SimpleFragListBuilder implements FragListBuilder {
   
-  public static final int MARGIN = 6;
-  public static final int MIN_FRAG_CHAR_SIZE = MARGIN * 3;
+  public static final int MARGIN_DEFAULT = 6;
+  public static final int MIN_FRAG_CHAR_SIZE_FACTOR = 3;
+
+  final int margin;
+  final int minFragCharSize;
+
+  public SimpleFragListBuilder( int margin ){
+    if( margin < 0 )
+      throw new IllegalArgumentException( "margin(" + margin + ") is too small. It must be
0 or higher." );
+
+    this.margin = margin;
+    this.minFragCharSize = Math.max( 1, margin * MIN_FRAG_CHAR_SIZE_FACTOR );
+  }
+
+  public SimpleFragListBuilder(){
+    this( MARGIN_DEFAULT );
+  }
 
   public FieldFragList createFieldFragList(FieldPhraseList fieldPhraseList, int fragCharSize)
{
-    if( fragCharSize < MIN_FRAG_CHAR_SIZE )
+    if( fragCharSize < minFragCharSize )
       throw new IllegalArgumentException( "fragCharSize(" + fragCharSize + ") is too small.
It must be " +
-          MIN_FRAG_CHAR_SIZE + " or higher." );
+          minFragCharSize + " or higher." );
 
     FieldFragList ffl = new FieldFragList( fragCharSize );
 
@@ -56,8 +71,8 @@ public class SimpleFragListBuilder imple
 
       wpil.clear();
       wpil.add( phraseInfo );
-      int st = phraseInfo.getStartOffset() - MARGIN < startOffset ?
-          startOffset : phraseInfo.getStartOffset() - MARGIN;
+      int st = phraseInfo.getStartOffset() - margin < startOffset ?
+          startOffset : phraseInfo.getStartOffset() - margin;
       int en = st + fragCharSize;
       if( phraseInfo.getEndOffset() > en )
         en = phraseInfo.getEndOffset();

Modified: lucene/dev/branches/branch_3x/lucene/contrib/highlighter/src/test/org/apache/lucene/search/vectorhighlight/SimpleFragListBuilderTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/contrib/highlighter/src/test/org/apache/lucene/search/vectorhighlight/SimpleFragListBuilderTest.java?rev=1184756&r1=1184755&r2=1184756&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/contrib/highlighter/src/test/org/apache/lucene/search/vectorhighlight/SimpleFragListBuilderTest.java
(original)
+++ lucene/dev/branches/branch_3x/lucene/contrib/highlighter/src/test/org/apache/lucene/search/vectorhighlight/SimpleFragListBuilderTest.java
Sun Oct 16 04:01:58 2011
@@ -30,7 +30,7 @@ public class SimpleFragListBuilderTest e
   public void testTooSmallFragSize() throws Exception {
     try{
       SimpleFragListBuilder sflb = new SimpleFragListBuilder();
-      sflb.createFieldFragList( fpl( "a", "b c d" ), SimpleFragListBuilder.MIN_FRAG_CHAR_SIZE
- 1 );
+      sflb.createFieldFragList( fpl( "a", "b c d" ), sflb.minFragCharSize - 1 );
       fail( "IllegalArgumentException must be thrown" );
     }
     catch ( IllegalArgumentException expected ) {
@@ -39,14 +39,14 @@ public class SimpleFragListBuilderTest e
   
   public void testSmallerFragSizeThanTermQuery() throws Exception {
     SimpleFragListBuilder sflb = new SimpleFragListBuilder();
-    FieldFragList ffl = sflb.createFieldFragList( fpl( "abcdefghijklmnopqrs", "abcdefghijklmnopqrs"
), SimpleFragListBuilder.MIN_FRAG_CHAR_SIZE );
+    FieldFragList ffl = sflb.createFieldFragList( fpl( "abcdefghijklmnopqrs", "abcdefghijklmnopqrs"
), sflb.minFragCharSize );
     assertEquals( 1, ffl.getFragInfos().size() );
     assertEquals( "subInfos=(abcdefghijklmnopqrs((0,19)))/1.0(0,19)", ffl.getFragInfos().get(
0 ).toString() );
   }
   
   public void testSmallerFragSizeThanPhraseQuery() throws Exception {
     SimpleFragListBuilder sflb = new SimpleFragListBuilder();
-    FieldFragList ffl = sflb.createFieldFragList( fpl( "\"abcdefgh jklmnopqrs\"", "abcdefgh
  jklmnopqrs" ), SimpleFragListBuilder.MIN_FRAG_CHAR_SIZE );
+    FieldFragList ffl = sflb.createFieldFragList( fpl( "\"abcdefgh jklmnopqrs\"", "abcdefgh
  jklmnopqrs" ), sflb.minFragCharSize );
     assertEquals( 1, ffl.getFragInfos().size() );
     if (VERBOSE) System.out.println( ffl.getFragInfos().get( 0 ).toString() );
     assertEquals( "subInfos=(abcdefghjklmnopqrs((0,21)))/1.0(0,21)", ffl.getFragInfos().get(
0 ).toString() );



Mime
View raw message