From f5898fb07fde8ca32ff626a0c39207b852500cf9 Mon Sep 17 00:00:00 2001 From: Nik Everett Date: Wed, 6 Jan 2016 12:32:09 -0500 Subject: [PATCH 1/2] [highlighting] Test for boundary chars --- .../search/highlight/HighlighterSearchIT.java | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/core/src/test/java/org/elasticsearch/search/highlight/HighlighterSearchIT.java b/core/src/test/java/org/elasticsearch/search/highlight/HighlighterSearchIT.java index 41fe4975e4b..008aac38832 100644 --- a/core/src/test/java/org/elasticsearch/search/highlight/HighlighterSearchIT.java +++ b/core/src/test/java/org/elasticsearch/search/highlight/HighlighterSearchIT.java @@ -19,6 +19,7 @@ package org.elasticsearch.search.highlight; import com.carrotsearch.randomizedtesting.generators.RandomPicks; + import org.elasticsearch.action.index.IndexRequestBuilder; import org.elasticsearch.action.search.SearchRequestBuilder; import org.elasticsearch.action.search.SearchResponse; @@ -802,9 +803,8 @@ public class HighlighterSearchIT extends ESIntegTestCase { assertAcked(prepareCreate("test").addMapping("type1", type1TermVectorMapping())); ensureGreen(); - client().prepareIndex("test", "type1") - .setSource("field1", "this is a test", "field2", "The quick brown fox jumps over the lazy dog").get(); - refresh(); + indexRandom(true, client().prepareIndex("test", "type1") + .setSource("field1", "this is a test", "field2", "The quick brown fox jumps over the lazy dog")); logger.info("--> highlighting and searching on field1"); SearchSourceBuilder source = searchSource() @@ -822,7 +822,6 @@ public class HighlighterSearchIT extends ESIntegTestCase { searchResponse = client().prepareSearch("test").setSource(source).get(); - // LUCENE 3.1 UPGRADE: Caused adding the space at the end... assertHighlight(searchResponse, 0, "field1", 0, 1, equalTo("this is a test")); logger.info("--> searching on _all, highlighting on field2"); @@ -832,7 +831,6 @@ public class HighlighterSearchIT extends ESIntegTestCase { searchResponse = client().prepareSearch("test").setSource(source).get(); - // LUCENE 3.1 UPGRADE: Caused adding the space at the end... assertHighlight(searchResponse, 0, "field2", 0, 1, equalTo("The quick brown fox jumps over the lazy dog")); logger.info("--> searching on _all, highlighting on field2"); @@ -842,8 +840,17 @@ public class HighlighterSearchIT extends ESIntegTestCase { searchResponse = client().prepareSearch("test").setSource(source).get(); - // LUCENE 3.1 UPGRADE: Caused adding the space at the end... assertHighlight(searchResponse, 0, "field2", 0, 1, equalTo("The quick brown fox jumps over the lazy dog")); + + logger.info("--> searching with boundary characters"); + source = searchSource() + .query(matchQuery("field2", "quick")) + .highlighter(highlight().field("field2", 30, 1).boundaryChars(new char[] {' '})); + + searchResponse = client().prepareSearch("test").setSource(source).get(); + + assertHighlight(searchResponse, 0, "field2", 0, 1, equalTo("The quick brown fox jumps over")); + } /** From add60a7560c1b47c604ad3d34e858ab7eaa296f8 Mon Sep 17 00:00:00 2001 From: Nik Everett Date: Wed, 6 Jan 2016 13:42:15 -0500 Subject: [PATCH 2/2] [highlighting] Another test for boundary chars --- .../search/highlight/HighlighterSearchIT.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/core/src/test/java/org/elasticsearch/search/highlight/HighlighterSearchIT.java b/core/src/test/java/org/elasticsearch/search/highlight/HighlighterSearchIT.java index 008aac38832..80636388f54 100644 --- a/core/src/test/java/org/elasticsearch/search/highlight/HighlighterSearchIT.java +++ b/core/src/test/java/org/elasticsearch/search/highlight/HighlighterSearchIT.java @@ -851,6 +851,15 @@ public class HighlighterSearchIT extends ESIntegTestCase { assertHighlight(searchResponse, 0, "field2", 0, 1, equalTo("The quick brown fox jumps over")); + logger.info("--> searching with boundary characters on the field"); + source = searchSource() + .query(matchQuery("field2", "quick")) + .highlighter(highlight().field(new Field("field2").fragmentSize(30).numOfFragments(1).boundaryChars(new char[] {' '}))); + + searchResponse = client().prepareSearch("test").setSource(source).get(); + + assertHighlight(searchResponse, 0, "field2", 0, 1, equalTo("The quick brown fox jumps over")); + } /**