From 050f6c7a3c4e12ede3aa89dff06215b4904aac43 Mon Sep 17 00:00:00 2001 From: James Dyer Date: Mon, 4 Jun 2012 19:48:26 +0000 Subject: [PATCH] SOLR-2993: fix (2) for fail on TestSpellCheckResponse: ConjunctionSolrSpellChecker was not preserving original Token Freqs. git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1346116 13f79535-47bb-0310-9956-ffa450edef68 --- .../solr/spelling/ConjunctionSolrSpellChecker.java | 13 ++++++++++++- solr/example/solr/conf/solrconfig.xml | 2 +- .../solrj/response/TestSpellCheckResponse.java | 3 +-- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/solr/core/src/java/org/apache/solr/spelling/ConjunctionSolrSpellChecker.java b/solr/core/src/java/org/apache/solr/spelling/ConjunctionSolrSpellChecker.java index 9ce67213940..86c6aac9dc1 100644 --- a/solr/core/src/java/org/apache/solr/spelling/ConjunctionSolrSpellChecker.java +++ b/solr/core/src/java/org/apache/solr/spelling/ConjunctionSolrSpellChecker.java @@ -19,6 +19,7 @@ package org.apache.solr.spelling; import java.io.IOException; import java.util.ArrayList; +import java.util.HashMap; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; @@ -135,8 +136,12 @@ public class ConjunctionSolrSpellChecker extends SolrSpellChecker { //TODO: This just interleaves the results. In the future, we might want to let users give each checker its // own weight and use that in combination to score & frequency to sort the results ? private SpellingResult mergeCheckers(SpellingResult[] results, int numSug) { + Map combinedTokenFrequency = new HashMap(); Map>> allSuggestions = new LinkedHashMap>>(); for(SpellingResult result : results) { + if(result.getTokenFrequency()!=null) { + combinedTokenFrequency.putAll(result.getTokenFrequency()); + } for(Map.Entry> entry : result.getSuggestions().entrySet()) { List> allForThisToken = allSuggestions.get(entry.getKey()); if(allForThisToken==null) { @@ -161,6 +166,10 @@ public class ConjunctionSolrSpellChecker extends SolrSpellChecker { anyData = true; Map.Entry corr = iter.next(); combinedResult.add(original, corr.getKey(), corr.getValue()); + Integer tokenFrequency = combinedTokenFrequency.get(original); + if(tokenFrequency!=null) { + combinedResult.addFrequency(original, tokenFrequency); + } if(++numberAdded==numSug) { break; } @@ -170,7 +179,9 @@ public class ConjunctionSolrSpellChecker extends SolrSpellChecker { break; } } - } + } + + return combinedResult; } diff --git a/solr/example/solr/conf/solrconfig.xml b/solr/example/solr/conf/solrconfig.xml index 762cddd928c..bd80e6ce088 100755 --- a/solr/example/solr/conf/solrconfig.xml +++ b/solr/example/solr/conf/solrconfig.xml @@ -1245,7 +1245,7 @@ collations (re-written queries) can include a combination of corrections from both spellcheckers --> default - + wordbreak on true 10 diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/response/TestSpellCheckResponse.java b/solr/solrj/src/test/org/apache/solr/client/solrj/response/TestSpellCheckResponse.java index 17d6890dea4..67ec83b826b 100644 --- a/solr/solrj/src/test/org/apache/solr/client/solrj/response/TestSpellCheckResponse.java +++ b/solr/solrj/src/test/org/apache/solr/client/solrj/response/TestSpellCheckResponse.java @@ -56,10 +56,9 @@ public class TestSpellCheckResponse extends SolrJettyTestBase { server.add(doc); server.commit(true, true); - SolrQuery query = new SolrQuery("*:*"); + SolrQuery query = new SolrQuery("name:samsang"); query.set(CommonParams.QT, "/spell"); query.set("spellcheck", true); - query.set(SpellingParams.SPELLCHECK_Q, "samsang"); query.set(SpellingParams.SPELLCHECK_BUILD, true); QueryRequest request = new QueryRequest(query); SpellCheckResponse response = request.process(server).getSpellCheckResponse();