lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Robert Muir <rcm...@gmail.com>
Subject Re: svn commit: r1420275 - in /lucene/dev/trunk/lucene/sandbox/src: java/org/apache/lucene/sandbox/postingshighlight/PostingsHighlighter.java test/org/apache/lucene/sandbox/postingshighlight/TestPostingsHighlighter.java
Date Tue, 11 Dec 2012 16:57:02 GMT
Thanks!

Unfortunately I suspect there are many more bugs...!

On Tue, Dec 11, 2012 at 11:47 AM,  <mikemccand@apache.org> wrote:
> Author: mikemccand
> Date: Tue Dec 11 16:47:49 2012
> New Revision: 1420275
>
> URL: http://svn.apache.org/viewvc?rev=1420275&view=rev
> Log:
> LUCENE-4290: be sure to throw exc if index didn't index offsets
>
> Modified:
>     lucene/dev/trunk/lucene/sandbox/src/java/org/apache/lucene/sandbox/postingshighlight/PostingsHighlighter.java
>     lucene/dev/trunk/lucene/sandbox/src/test/org/apache/lucene/sandbox/postingshighlight/TestPostingsHighlighter.java
>
> Modified: lucene/dev/trunk/lucene/sandbox/src/java/org/apache/lucene/sandbox/postingshighlight/PostingsHighlighter.java
> URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/sandbox/src/java/org/apache/lucene/sandbox/postingshighlight/PostingsHighlighter.java?rev=1420275&r1=1420274&r2=1420275&view=diff
> ==============================================================================
> --- lucene/dev/trunk/lucene/sandbox/src/java/org/apache/lucene/sandbox/postingshighlight/PostingsHighlighter.java
(original)
> +++ lucene/dev/trunk/lucene/sandbox/src/java/org/apache/lucene/sandbox/postingshighlight/PostingsHighlighter.java
Tue Dec 11 16:47:49 2012
> @@ -104,7 +104,7 @@ public final class PostingsHighlighter {
>    }
>
>    public PostingsHighlighter(String field, int maxLength) {
> -    this(field, DEFAULT_MAX_LENGTH, BreakIterator.getSentenceInstance(Locale.ROOT),
new PassageScorer(), new PassageFormatter());
> +    this(field, maxLength, BreakIterator.getSentenceInstance(Locale.ROOT), new PassageScorer(),
new PassageFormatter());
>    }
>
>    public PostingsHighlighter(String field, int maxLength, BreakIterator breakIterator,
PassageScorer scorer, PassageFormatter formatter) {
> @@ -201,7 +201,7 @@ public final class PostingsHighlighter {
>        if (leaf != lastLeaf) {
>          termsEnum = t.iterator(null);
>          postings = new DocsAndPositionsEnum[terms.size()];
> -      };
> +      }
>        Passage passages[] = highlightDoc(termTexts, termContexts, subContext.ord, weights,
content.length(), bi, doc - subContext.docBase, termsEnum, postings, maxPassages);
>        if (passages.length > 0) {
>          // otherwise a null snippet
> @@ -354,7 +354,7 @@ public final class PostingsHighlighter {
>          if (off == otherOff) {
>            return id - other.id;
>          } else {
> -          return off - otherOff;
> +          return Long.signum(((long)off) - otherOff);
>          }
>        } catch (IOException e) {
>          throw new RuntimeException(e);
>
> Modified: lucene/dev/trunk/lucene/sandbox/src/test/org/apache/lucene/sandbox/postingshighlight/TestPostingsHighlighter.java
> URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/sandbox/src/test/org/apache/lucene/sandbox/postingshighlight/TestPostingsHighlighter.java?rev=1420275&r1=1420274&r2=1420275&view=diff
> ==============================================================================
> --- lucene/dev/trunk/lucene/sandbox/src/test/org/apache/lucene/sandbox/postingshighlight/TestPostingsHighlighter.java
(original)
> +++ lucene/dev/trunk/lucene/sandbox/src/test/org/apache/lucene/sandbox/postingshighlight/TestPostingsHighlighter.java
Tue Dec 11 16:47:49 2012
> @@ -146,4 +146,39 @@ public class TestPostingsHighlighter ext
>      ir.close();
>      dir.close();
>    }
> +
> +  public void testUserFailedToIndexOffsets() throws Exception {
> +    Directory dir = newDirectory();
> +    IndexWriterConfig iwc = newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random(),
MockTokenizer.SIMPLE, true));
> +    iwc.setMergePolicy(newLogMergePolicy());
> +    RandomIndexWriter iw = new RandomIndexWriter(random(), dir, iwc);
> +
> +    FieldType offsetsType = new FieldType(TextField.TYPE_STORED);
> +    offsetsType.setIndexOptions(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS);
> +    Field body = new Field("body", "", offsetsType);
> +    Document doc = new Document();
> +    doc.add(body);
> +
> +    body.setStringValue("This is a test. Just a test highlighting from postings. Feel
free to ignore.");
> +    iw.addDocument(doc);
> +    body.setStringValue("This test is another test. Not a good sentence. Test test test
test.");
> +    iw.addDocument(doc);
> +
> +    IndexReader ir = iw.getReader();
> +    iw.close();
> +
> +    IndexSearcher searcher = newSearcher(ir);
> +    PostingsHighlighter highlighter = new PostingsHighlighter("body");
> +    Query query = new TermQuery(new Term("body", "test"));
> +    TopDocs topDocs = searcher.search(query, null, 10, Sort.INDEXORDER);
> +    assertEquals(2, topDocs.totalHits);
> +    try {
> +      highlighter.highlight(query, searcher, topDocs, 2);
> +      fail("did not hit expected exception");
> +    } catch (IllegalArgumentException iae) {
> +      // expected
> +    }
> +    ir.close();
> +    dir.close();
> +  }
>  }
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@lucene.apache.org
For additional commands, e-mail: dev-help@lucene.apache.org


Mime
View raw message