From bea54d7896ceb8c5be7b1a74c7676c0a9dbe7ecf Mon Sep 17 00:00:00 2001 From: mujah Date: Tue, 31 Jan 2017 20:08:02 +0800 Subject: [PATCH 1/7] solr-fulltext-search module created --- solr-fulltext-search/pom.xml | 90 +++++++++++++++++++ .../solr/fulltexh/search/model/Product.java | 5 ++ .../search/service/SolrSearchService.java | 5 ++ 3 files changed, 100 insertions(+) create mode 100644 solr-fulltext-search/pom.xml create mode 100644 solr-fulltext-search/src/main/java/com/baeldung/solr/fulltexh/search/model/Product.java create mode 100644 solr-fulltext-search/src/main/java/com/baeldung/solr/fulltexh/search/service/SolrSearchService.java diff --git a/solr-fulltext-search/pom.xml b/solr-fulltext-search/pom.xml new file mode 100644 index 000000000000..4afcb5838ad8 --- /dev/null +++ b/solr-fulltext-search/pom.xml @@ -0,0 +1,90 @@ + + + 4.0.0 + com.baeldung + solr-fulltext-search + 0.0.1-SNAPSHOT + jar + solr-fulltext-search + + + + UTF-8 + 2.19.1 + + + + + org.apache.solr + solr-solrj + 6.1.0 + + + log4j + log4j + 1.2.16 + + + junit + junit + 4.12 + test + + + + + + + + maven-compiler-plugin + + + org.apache.maven.plugins + maven-surefire-plugin + ${maven-surefire-plugin.version} + + + **/*IntegrationTest.java + **/*LiveTest.java + + + + + + + + + integration + + + + org.apache.maven.plugins + maven-surefire-plugin + + + integration-test + + test + + + + **/*LiveTest.java + + + **/*IntegrationTest.java + + + + + + + json + + + + + + + + \ No newline at end of file diff --git a/solr-fulltext-search/src/main/java/com/baeldung/solr/fulltexh/search/model/Product.java b/solr-fulltext-search/src/main/java/com/baeldung/solr/fulltexh/search/model/Product.java new file mode 100644 index 000000000000..b5fb3342823d --- /dev/null +++ b/solr-fulltext-search/src/main/java/com/baeldung/solr/fulltexh/search/model/Product.java @@ -0,0 +1,5 @@ +package com.baeldung.solr.fulltexh.search.model; + +public class Product { + +} diff --git a/solr-fulltext-search/src/main/java/com/baeldung/solr/fulltexh/search/service/SolrSearchService.java b/solr-fulltext-search/src/main/java/com/baeldung/solr/fulltexh/search/service/SolrSearchService.java new file mode 100644 index 000000000000..aa511f0e1ba4 --- /dev/null +++ b/solr-fulltext-search/src/main/java/com/baeldung/solr/fulltexh/search/service/SolrSearchService.java @@ -0,0 +1,5 @@ +package com.baeldung.solr.fulltexh.search.service; + +public interface SolrSearchService { + +} From 6dea634f6ee91b11ba3970735ecce89da015d0a6 Mon Sep 17 00:00:00 2001 From: mujah Date: Tue, 31 Jan 2017 20:10:09 +0800 Subject: [PATCH 2/7] solr-fulltext-search modue created --- pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pom.xml b/pom.xml index b76c9b8ddd2a..6b95ba0350c3 100644 --- a/pom.xml +++ b/pom.xml @@ -95,6 +95,7 @@ resteasy selenium-junit-testng + solr-fulltext-search spark-java spring-akka spring-amqp From 458913f2db3f0787a450b1e2f847dad3b2ff0527 Mon Sep 17 00:00:00 2001 From: mujah Date: Sun, 26 Feb 2017 22:06:46 +0800 Subject: [PATCH 3/7] solr-fulltext-search change s --- solr-fulltext-search/pom.xml | 2 +- .../solr/fulltexh/search/model/Product.java | 5 - .../search/service/SolrSearchService.java | 5 - .../solr/fulltext/search/model/Item.java | 51 +++ .../search/service/ItemSearchService.java | 15 + .../search/service/ItemSearchServiceImpl.java | 34 ++ .../ItemSearchServiceIntegrationTest.java | 374 ++++++++++++++++++ 7 files changed, 475 insertions(+), 11 deletions(-) delete mode 100644 solr-fulltext-search/src/main/java/com/baeldung/solr/fulltexh/search/model/Product.java delete mode 100644 solr-fulltext-search/src/main/java/com/baeldung/solr/fulltexh/search/service/SolrSearchService.java create mode 100644 solr-fulltext-search/src/main/java/com/baeldung/solr/fulltext/search/model/Item.java create mode 100644 solr-fulltext-search/src/main/java/com/baeldung/solr/fulltext/search/service/ItemSearchService.java create mode 100644 solr-fulltext-search/src/main/java/com/baeldung/solr/fulltext/search/service/ItemSearchServiceImpl.java create mode 100644 solr-fulltext-search/src/test/java/com/baeldung/solr/fulltext/search/service/ItemSearchServiceIntegrationTest.java diff --git a/solr-fulltext-search/pom.xml b/solr-fulltext-search/pom.xml index 4afcb5838ad8..bed6afd48fae 100644 --- a/solr-fulltext-search/pom.xml +++ b/solr-fulltext-search/pom.xml @@ -18,7 +18,7 @@ org.apache.solr solr-solrj - 6.1.0 + 6.4.1 log4j diff --git a/solr-fulltext-search/src/main/java/com/baeldung/solr/fulltexh/search/model/Product.java b/solr-fulltext-search/src/main/java/com/baeldung/solr/fulltexh/search/model/Product.java deleted file mode 100644 index b5fb3342823d..000000000000 --- a/solr-fulltext-search/src/main/java/com/baeldung/solr/fulltexh/search/model/Product.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.baeldung.solr.fulltexh.search.model; - -public class Product { - -} diff --git a/solr-fulltext-search/src/main/java/com/baeldung/solr/fulltexh/search/service/SolrSearchService.java b/solr-fulltext-search/src/main/java/com/baeldung/solr/fulltexh/search/service/SolrSearchService.java deleted file mode 100644 index aa511f0e1ba4..000000000000 --- a/solr-fulltext-search/src/main/java/com/baeldung/solr/fulltexh/search/service/SolrSearchService.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.baeldung.solr.fulltexh.search.service; - -public interface SolrSearchService { - -} diff --git a/solr-fulltext-search/src/main/java/com/baeldung/solr/fulltext/search/model/Item.java b/solr-fulltext-search/src/main/java/com/baeldung/solr/fulltext/search/model/Item.java new file mode 100644 index 000000000000..d7a0524ca92e --- /dev/null +++ b/solr-fulltext-search/src/main/java/com/baeldung/solr/fulltext/search/model/Item.java @@ -0,0 +1,51 @@ +package com.baeldung.solr.fulltext.search.model; + +import org.apache.solr.client.solrj.beans.Field; + +public class Item { + + @Field + private String id; + + @Field + private String description; + + @Field + private String category; + + @Field + private float price; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getCategory() { + return category; + } + + public void setCategory(String category) { + this.category = category; + } + + public float getPrice() { + return price; + } + + public void setPrice(float price) { + this.price = price; + } + +} diff --git a/solr-fulltext-search/src/main/java/com/baeldung/solr/fulltext/search/service/ItemSearchService.java b/solr-fulltext-search/src/main/java/com/baeldung/solr/fulltext/search/service/ItemSearchService.java new file mode 100644 index 000000000000..fa906fc975ab --- /dev/null +++ b/solr-fulltext-search/src/main/java/com/baeldung/solr/fulltext/search/service/ItemSearchService.java @@ -0,0 +1,15 @@ +package com.baeldung.solr.fulltext.search.service; + +import java.io.IOException; + +import org.apache.solr.client.solrj.SolrServerException; + +import com.baeldung.solr.fulltext.search.model.Item; + +public interface ItemSearchService { + + public void index(String id, String description, String category, float price) throws SolrServerException, IOException; + + public void indexBean(Item item) throws IOException, SolrServerException; + +} diff --git a/solr-fulltext-search/src/main/java/com/baeldung/solr/fulltext/search/service/ItemSearchServiceImpl.java b/solr-fulltext-search/src/main/java/com/baeldung/solr/fulltext/search/service/ItemSearchServiceImpl.java new file mode 100644 index 000000000000..573cc58bc067 --- /dev/null +++ b/solr-fulltext-search/src/main/java/com/baeldung/solr/fulltext/search/service/ItemSearchServiceImpl.java @@ -0,0 +1,34 @@ +package com.baeldung.solr.fulltext.search.service; + +import java.io.IOException; + +import org.apache.solr.client.solrj.SolrClient; +import org.apache.solr.client.solrj.SolrServerException; +import org.apache.solr.common.SolrInputDocument; + +import com.baeldung.solr.fulltext.search.model.Item; + +public class ItemSearchServiceImpl implements ItemSearchService { + + private final SolrClient solrClient; + + public ItemSearchServiceImpl(SolrClient solrClient) { + this.solrClient = solrClient; + } + + public void index(String id, String description, String category, float price) throws SolrServerException, IOException { + SolrInputDocument doc = new SolrInputDocument(); + doc.addField("id", id); + doc.addField("description", description); + doc.addField("category", category); + doc.addField("price", price); + solrClient.add(doc); + solrClient.commit(); + } + + public void indexBean(Item item) throws IOException, SolrServerException { + solrClient.addBean(item); + solrClient.commit(); + } + +} diff --git a/solr-fulltext-search/src/test/java/com/baeldung/solr/fulltext/search/service/ItemSearchServiceIntegrationTest.java b/solr-fulltext-search/src/test/java/com/baeldung/solr/fulltext/search/service/ItemSearchServiceIntegrationTest.java new file mode 100644 index 000000000000..94661ffc2ed1 --- /dev/null +++ b/solr-fulltext-search/src/test/java/com/baeldung/solr/fulltext/search/service/ItemSearchServiceIntegrationTest.java @@ -0,0 +1,374 @@ +package com.baeldung.solr.fulltext.search.service; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +import java.util.List; +import java.util.Map; + +import org.apache.solr.client.solrj.SolrClient; +import org.apache.solr.client.solrj.SolrQuery; +import org.apache.solr.client.solrj.impl.HttpSolrClient; +import org.apache.solr.client.solrj.response.FacetField.Count; +import org.apache.solr.client.solrj.response.QueryResponse; +import org.apache.solr.client.solrj.response.RangeFacet; +import org.apache.solr.client.solrj.response.SpellCheckResponse; +import org.apache.solr.client.solrj.response.SpellCheckResponse.Suggestion; +import org.apache.solr.client.solrj.response.SuggesterResponse; +import org.apache.solr.common.SolrDocument; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +import com.baeldung.solr.fulltext.search.model.Item; + +public class ItemSearchServiceIntegrationTest { + + private static SolrClient solrClient; + private static ItemSearchService itemSearchService; + private static final String solrUrl = "http://localhost:8987/solr/item"; + + @BeforeClass + public static void initBeans() throws Exception { + solrClient = new HttpSolrClient.Builder(solrUrl).build(); + itemSearchService = new ItemSearchServiceImpl(solrClient); + + solrClient.commit(); + } + + @Before + public void clearSolrData() throws Exception { + solrClient.deleteByQuery("*:*"); + } + + @Test + public void whenIndexing_thenAvailableOnRetrieval() throws Exception { + itemSearchService.index("hm0001", "Washing Machine", "Home Appliances", 450f); + final SolrDocument indexedDoc = solrClient.getById("hm0001"); + assertEquals("hm0001", indexedDoc.get("id")); + } + + @Test + public void whenIndexingBean_thenAvailableOnRetrieval() throws Exception { + Item item = new Item(); + item.setId("hm0002"); + item.setCategory("Televisions"); + item.setDescription("LED TV 32"); + item.setPrice(500); + itemSearchService.indexBean(item); + } + + @Test + public void whenSearchingByBasicQuery_thenAllMatchingItemsShouldAvialble() throws Exception { + itemSearchService.index("hm0001", "Brand1 Washing Machine", "Home Appliances", 450f); + itemSearchService.index("hm0002", "Brand1 Refrigerator", "Home Appliances", 450f); + itemSearchService.index("hm0003", "LED TV 32", "Brand1 Home Appliances", 450f); + + SolrQuery query = new SolrQuery(); + query.setQuery("brand1"); + query.setStart(0); + query.setRows(10); + + QueryResponse response = solrClient.query(query); + List items = response.getBeans(Item.class); + + assertEquals(3, items.size()); + + } + + @Test + public void whenSearchingWithWildCard_thenAllMatchingItemsShouldAvialble() throws Exception { + itemSearchService.index("hm0001", "Brand1 Washing Machine", "Home Appliances", 450f); + itemSearchService.index("hm0002", "Brand1 Refrigerator", "Home Appliances", 450f); + itemSearchService.index("hm0003", "LED TV 32", "Brand1 Home Appliances", 450f); + + SolrQuery query = new SolrQuery(); + query.setQuery("*rand?"); + + QueryResponse response = solrClient.query(query); + List items = response.getBeans(Item.class); + + assertEquals(3, items.size()); + } + + @Test + public void whenSearchingWithLogicalOperators_thenAllMatchingItemsShouldAvialble() throws Exception { + itemSearchService.index("hm0001", "Brand1 Washing Machine", "Home Appliances", 450f); + itemSearchService.index("hm0002", "Brand1 Refrigerator", "Home Appliances", 450f); + itemSearchService.index("hm0003", "Brand2 LED TV 32", "Washing Appliances", 450f); + + SolrQuery query = new SolrQuery(); + query.setQuery("brand1 AND (Washing OR Refrigerator)"); + + QueryResponse response = solrClient.query(query); + List items = response.getBeans(Item.class); + + assertEquals(2, items.size()); + } + + @Test + public void whenSearchingWithFields_thenAllMatchingItemsShouldAvialble() throws Exception { + itemSearchService.index("0001", "Brand1 Washing Machine", "Home Appliances", 450f); + itemSearchService.index("0002", "Brand1 Refrigerator", "Home Appliances", 450f); + itemSearchService.index("0003", "Brand2 LED TV 32", "Brand1 Washing Home Appliances", 450f); + + SolrQuery query = new SolrQuery(); + query.setQuery("description:Brand* AND category:*Washing*"); + + QueryResponse response = solrClient.query(query); + List items = response.getBeans(Item.class); + + assertEquals(1, items.size()); + } + + @Test + public void whenSearchingWithPhrase_thenAllMatchingItemsShouldAvialble() throws Exception { + itemSearchService.index("hm0001", "Brand1 Washing Machine", "Home Appliances", 450f); + itemSearchService.index("hm0002", "Brand1 Refrigerator", "Home Appliances", 450f); + itemSearchService.index("hm0003", "Brand2 Dishwasher", "Washing tools and equipment ", 450f); + + SolrQuery query = new SolrQuery(); + query.setQuery("washing MachIne"); + + QueryResponse response = solrClient.query(query); + List items = response.getBeans(Item.class); + + assertEquals(2, items.size()); + } + + @Test + public void whenSearchingWithRealPhrase_thenAllMatchingItemsShouldAvialble() throws Exception { + itemSearchService.index("hm0001", "Brand1 Washing Machine", "Home Appliances", 450f); + itemSearchService.index("hm0002", "Brand1 Refrigerator", "Home Appliances", 450f); + itemSearchService.index("hm0003", "Brand2 Dishwasher", "Washing tools and equipment ", 450f); + + SolrQuery query = new SolrQuery(); + query.setQuery("\"washing machine\""); + + QueryResponse response = solrClient.query(query); + List items = response.getBeans(Item.class); + + assertEquals(1, items.size()); + } + + @Test + public void whenSearchingPhraseWithProximity_thenAllMatchingItemsShouldAvialble() throws Exception { + itemSearchService.index("hm0001", "Brand1 Washing Machine", "Home Appliances", 450f); + itemSearchService.index("hm0002", "Brand1 Refrigerator", "Home Appliances", 450f); + itemSearchService.index("hm0003", "Brand2 Dishwasher", "Washing tools and equipment ", 450f); + + SolrQuery query = new SolrQuery(); + query.setQuery("\"Washing equipment\"~2"); + + QueryResponse response = solrClient.query(query); + List items = response.getBeans(Item.class); + + assertEquals(1, items.size()); + } + + @Test + public void whenSearchingWithPriceRange_thenAllMatchingItemsShouldAvialble() throws Exception { + itemSearchService.index("hm0001", "Brand1 Washing Machine", "Home Appliances", 100f); + itemSearchService.index("hm0002", "Brand1 Refrigerator", "Home Appliances", 300f); + itemSearchService.index("hm0003", "Brand2 Dishwasher", "Home Appliances", 200f); + itemSearchService.index("hm0004", "Brand2 Dishwasher", "Washing tools and equipment ", 450f); + + SolrQuery query = new SolrQuery(); + query.setQuery("price:[100 TO 300]"); + + QueryResponse response = solrClient.query(query); + List items = response.getBeans(Item.class); + + assertEquals(3, items.size()); + } + + @Test + public void whenSearchingWithPriceRangeInclusiveExclusive_thenAllMatchingItemsShouldAvialble() throws Exception { + itemSearchService.index("hm0001", "Brand1 Washing Machine", "Home Appliances", 100f); + itemSearchService.index("hm0002", "Brand1 Refrigerator", "Home Appliances", 300f); + itemSearchService.index("hm0003", "Brand2 Dishwasher", "Home Appliances", 200f); + itemSearchService.index("hm0004", "Brand2 Dishwasher", "Washing tools and equipment ", 450f); + + SolrQuery query = new SolrQuery(); + query.setQuery("price:{100 TO 300]"); + + QueryResponse response = solrClient.query(query); + List items = response.getBeans(Item.class); + + assertEquals(2, items.size()); + } + + @Test + public void whenSearchingWithFilterQuery_thenAllMatchingItemsShouldAvialble() throws Exception { + itemSearchService.index("hm0001", "Brand1 Washing Machine", "Home Appliances", 100f); + itemSearchService.index("hm0002", "Brand1 Refrigerator", "Home Appliances", 300f); + itemSearchService.index("hm0003", "Brand2 Ceiling Fan", "Home Appliances", 200f); + itemSearchService.index("hm0004", "Brand2 Dishwasher", "Washing tools and equipment ", 250f); + + SolrQuery query = new SolrQuery(); + query.setQuery("price:[100 TO 300]"); + query.addFilterQuery("description:Brand1", "category:Home Appliances"); + + QueryResponse response = solrClient.query(query); + List items = response.getBeans(Item.class); + + assertEquals(2, items.size()); + } + + @Test + public void whenSearchingWithFacetFields_thenAllMatchingFacetsShouldAvialble() throws Exception { + itemSearchService.index("hm0001", "Brand1 Washing Machine", "CategoryA", 100f); + itemSearchService.index("hm0002", "Brand1 Refrigerator", "CategoryA", 300f); + itemSearchService.index("hm0003", "Brand2 Ceiling Fan", "CategoryB", 200f); + itemSearchService.index("hm0004", "Brand2 Dishwasher", "CategoryB", 250f); + + SolrQuery query = new SolrQuery(); + query.setQuery("*:*"); + query.addFacetField("category"); + + QueryResponse response = solrClient.query(query); + List facetResults = response.getFacetField("category").getValues(); + + assertEquals(2, facetResults.size()); + + for (Count count : facetResults) { + if ("categorya".equalsIgnoreCase(count.getName())) { + assertEquals(2, count.getCount()); + } else if ("categoryb".equalsIgnoreCase(count.getName())) { + assertEquals(2, count.getCount()); + } else { + fail("unexpected category"); + } + } + } + + @Test + public void whenSearchingWithFacetQuery_thenAllMatchingFacetsShouldAvialble() throws Exception { + itemSearchService.index("hm0001", "Brand1 Washing Machine", "CategoryA", 100f); + itemSearchService.index("hm0002", "Brand1 Refrigerator", "CategoryA", 300f); + itemSearchService.index("hm0003", "Brand2 Ceiling Fan", "CategoryB", 200f); + itemSearchService.index("hm0004", "Brand2 Dishwasher", "CategoryB", 250f); + + SolrQuery query = new SolrQuery(); + query.setQuery("*:*"); + + query.addFacetQuery("Washing OR Refrigerator"); + query.addFacetQuery("Brand2"); + + QueryResponse response = solrClient.query(query); + Map facetQueryMap = response.getFacetQuery(); + + assertEquals(2, facetQueryMap.size()); + + for (Map.Entry entry : facetQueryMap.entrySet()) { + String facetQuery = entry.getKey(); + + if ("Washing OR Refrigerator".equals(facetQuery)) { + assertEquals(Integer.valueOf(2), entry.getValue()); + } else if ("Brand2".equals(facetQuery)) { + assertEquals(Integer.valueOf(2), entry.getValue()); + } else { + fail("unexpected query"); + } + + } + } + + @Test + public void whenSearchingWithFacetRange_thenAllMatchingFacetsShouldAvialble() throws Exception { + itemSearchService.index("hm0001", "Brand1 Washing Machine", "CategoryA", 100f); + itemSearchService.index("hm0002", "Brand1 Refrigerator", "CategoryA", 125f); + itemSearchService.index("hm0003", "Brand2 Ceiling Fan", "CategoryB", 150f); + itemSearchService.index("hm0004", "Brand2 Dishwasher", "CategoryB", 250f); + + SolrQuery query = new SolrQuery(); + query.setQuery("*:*"); + + query.addNumericRangeFacet("price", 100, 275, 25); + + QueryResponse response = solrClient.query(query); + List rangeFacets = response.getFacetRanges().get(0).getCounts(); + + assertEquals(7, rangeFacets.size()); + } + + @Test + public void whenSearchingWithHitHighlighting_thenKeywordsShouldBeHighlighted() throws Exception { + itemSearchService.index("hm0001", "Brand1 Washing Machine", "Home Appliances", 100f); + itemSearchService.index("hm0002", "Brand1 Refrigerator", "Home Appliances", 300f); + itemSearchService.index("hm0003", "Brand2 Ceiling Fan", "Home Appliances", 200f); + itemSearchService.index("hm0004", "Brand2 Dishwasher", "Washing equipments", 250f); + + SolrQuery query = new SolrQuery(); + query.setQuery("Appliances"); + query.setHighlight(true); + query.addHighlightField("category"); + query.setHighlightSimplePre(""); + query.setHighlightSimplePost(""); + QueryResponse response = solrClient.query(query); + + Map>> hitHighlightedMap = response.getHighlighting(); + Map> highlightedFieldMap = hitHighlightedMap.get("hm0001"); + List highlightedList = highlightedFieldMap.get("category"); + String highLightedText = highlightedList.get(0); + + assertEquals("Home Appliances", highLightedText); + + } + + @Test + public void whenSearchingWithKeywordWithMistake_thenSpellingSuggestionsShouldBeReturned() throws Exception { + itemSearchService.index("hm0001", "Brand1 Washing Machine", "Home Appliances", 100f); + itemSearchService.index("hm0002", "Brand1 Refrigerator", "Home Appliances", 300f); + itemSearchService.index("hm0003", "Brand2 Ceiling Fan", "Home Appliances", 200f); + itemSearchService.index("hm0004", "Brand2 Dishwasher", "Washing equipments", 250f); + + SolrQuery query = new SolrQuery(); + query.setQuery("hme"); + query.set("spellcheck", "on"); + QueryResponse response = solrClient.query(query); + + SpellCheckResponse spellCheckResponse = response.getSpellCheckResponse(); + + assertEquals(false, spellCheckResponse.isCorrectlySpelled()); + + Suggestion suggestion = spellCheckResponse.getSuggestions().get(0); + + assertEquals("hme", suggestion.getToken()); + + List alternatives = suggestion.getAlternatives(); + String alternative = alternatives.get(0); + + assertEquals("home", alternative); + } + + @Test + public void whenSearchingWithIncompleteKeyword_thenKeywordSuggestionsShouldBeReturned() throws Exception { + itemSearchService.index("hm0001", "Brand1 Washing Machine", "Home Appliances", 100f); + itemSearchService.index("hm0002", "Brand1 Refrigerator", "Home Appliances", 300f); + itemSearchService.index("hm0003", "Brand2 Ceiling Fan", "Home Appliances", 200f); + itemSearchService.index("hm0004", "Brand2 Dishwasher", "Home washing equipments", 250f); + + SolrQuery query = new SolrQuery(); + query.setRequestHandler("/suggest"); + query.set("suggest", "true"); + query.set("suggest.build", "true"); + query.set("suggest.dictionary", "mySuggester"); + query.set("suggest.q", "Hom"); + QueryResponse response = solrClient.query(query); + + SuggesterResponse suggesterResponse = response.getSuggesterResponse(); + Map> suggestedTerms = suggesterResponse.getSuggestedTerms(); + List suggestions = suggestedTerms.get("mySuggester"); + + assertEquals(2, suggestions.size()); + + for (String term : suggestions) { + if (!"Home Appliances".equals(term) && !"Home washing equipments".equals(term)) { + fail("Unexpected suggestions"); + } + } + + } + +} From d890d45d9f9b3cadea1b80b4dd1da44e6b65b70f Mon Sep 17 00:00:00 2001 From: mujah Date: Tue, 28 Feb 2017 21:49:31 +0800 Subject: [PATCH 4/7] pom changes merged from upstream --- solr-fulltext-search/pom.xml | 8 -------- 1 file changed, 8 deletions(-) diff --git a/solr-fulltext-search/pom.xml b/solr-fulltext-search/pom.xml index e4cf1e49cd54..bed6afd48fae 100644 --- a/solr-fulltext-search/pom.xml +++ b/solr-fulltext-search/pom.xml @@ -18,15 +18,7 @@ org.apache.solr solr-solrj -<<<<<<< HEAD -<<<<<<< HEAD 6.4.1 -======= - 6.1.0 ->>>>>>> 1bfc944c5a5db228a6bd648794360df6aeb58225 -======= - 6.4.1 ->>>>>>> 13eb6f54ae1a11dc8025cd9795794e8b2a433508 log4j From 7a71eba1d2293a66b9c6ac946d86a310d349031b Mon Sep 17 00:00:00 2001 From: mujah Date: Sun, 5 Mar 2017 20:50:58 +0800 Subject: [PATCH 5/7] removed integration tests from mvn build --- solr-fulltext-search/pom.xml | 34 ---------------------------------- 1 file changed, 34 deletions(-) diff --git a/solr-fulltext-search/pom.xml b/solr-fulltext-search/pom.xml index bed6afd48fae..5b2950d64c21 100644 --- a/solr-fulltext-search/pom.xml +++ b/solr-fulltext-search/pom.xml @@ -53,38 +53,4 @@ - - - integration - - - - org.apache.maven.plugins - maven-surefire-plugin - - - integration-test - - test - - - - **/*LiveTest.java - - - **/*IntegrationTest.java - - - - - - - json - - - - - - - \ No newline at end of file From dd4fd0f76b15b9334f078e5fbf03e9fc38365d6d Mon Sep 17 00:00:00 2001 From: mujah Date: Sat, 11 Mar 2017 11:56:42 +0800 Subject: [PATCH 6/7] Refactoring test class --- solr-fulltext-search/pom.xml | 34 +++++++++++++++++++ ...st.java => ItemSearchServiceLiveTest.java} | 2 +- 2 files changed, 35 insertions(+), 1 deletion(-) rename solr-fulltext-search/src/test/java/com/baeldung/solr/fulltext/search/service/{ItemSearchServiceIntegrationTest.java => ItemSearchServiceLiveTest.java} (99%) diff --git a/solr-fulltext-search/pom.xml b/solr-fulltext-search/pom.xml index 5b2950d64c21..982ae0f685ea 100644 --- a/solr-fulltext-search/pom.xml +++ b/solr-fulltext-search/pom.xml @@ -53,4 +53,38 @@ + + + live + + + + org.apache.maven.plugins + maven-surefire-plugin + + + integration-test + + test + + + + **/*LiveTest.java + + + **/*IntegrationTest.java + + + + + + + json + + + + + + + \ No newline at end of file diff --git a/solr-fulltext-search/src/test/java/com/baeldung/solr/fulltext/search/service/ItemSearchServiceIntegrationTest.java b/solr-fulltext-search/src/test/java/com/baeldung/solr/fulltext/search/service/ItemSearchServiceLiveTest.java similarity index 99% rename from solr-fulltext-search/src/test/java/com/baeldung/solr/fulltext/search/service/ItemSearchServiceIntegrationTest.java rename to solr-fulltext-search/src/test/java/com/baeldung/solr/fulltext/search/service/ItemSearchServiceLiveTest.java index 94661ffc2ed1..1489d40787bf 100644 --- a/solr-fulltext-search/src/test/java/com/baeldung/solr/fulltext/search/service/ItemSearchServiceIntegrationTest.java +++ b/solr-fulltext-search/src/test/java/com/baeldung/solr/fulltext/search/service/ItemSearchServiceLiveTest.java @@ -22,7 +22,7 @@ import com.baeldung.solr.fulltext.search.model.Item; -public class ItemSearchServiceIntegrationTest { +public class ItemSearchServiceLiveTest { private static SolrClient solrClient; private static ItemSearchService itemSearchService; From 84a7a808b537737df540c0d0c0b883e97d55629c Mon Sep 17 00:00:00 2001 From: mujah Date: Sat, 11 Mar 2017 12:26:59 +0800 Subject: [PATCH 7/7] removed test profile --- solr-fulltext-search/pom.xml | 34 ---------------------------------- 1 file changed, 34 deletions(-) diff --git a/solr-fulltext-search/pom.xml b/solr-fulltext-search/pom.xml index 982ae0f685ea..5b2950d64c21 100644 --- a/solr-fulltext-search/pom.xml +++ b/solr-fulltext-search/pom.xml @@ -53,38 +53,4 @@ - - - live - - - - org.apache.maven.plugins - maven-surefire-plugin - - - integration-test - - test - - - - **/*LiveTest.java - - - **/*IntegrationTest.java - - - - - - - json - - - - - - - \ No newline at end of file