java/code/src/com/redhat/rhn/frontend/action/help/DocSearchSetupAction.java | 31 ++++ java/code/src/com/redhat/rhn/frontend/strings/java/StringResource_en_US.xml | 10 + search-server/spacewalk-search/src/java/com/redhat/satellite/search/index/IndexManager.java | 66 ++++++---- 3 files changed, 79 insertions(+), 28 deletions(-)
New commits: commit 49d8f4ae4ab37d18b5cd275de4de7db3699af5ff Author: Partha Aji paji@redhat.com Date: Wed Sep 1 19:27:24 2010 -0400
518664 - Made spacewalk search deal with other locales
diff --git a/java/code/src/com/redhat/rhn/frontend/action/help/DocSearchSetupAction.java b/java/code/src/com/redhat/rhn/frontend/action/help/DocSearchSetupAction.java index 79fa315..b0d03f3 100644 --- a/java/code/src/com/redhat/rhn/frontend/action/help/DocSearchSetupAction.java +++ b/java/code/src/com/redhat/rhn/frontend/action/help/DocSearchSetupAction.java @@ -17,6 +17,7 @@ package com.redhat.rhn.frontend.action.help; import com.redhat.rhn.common.conf.ConfigDefaults; import com.redhat.rhn.common.localization.LocalizationService; import com.redhat.rhn.common.validator.ValidatorException; +import com.redhat.rhn.common.validator.ValidatorWarning; import com.redhat.rhn.frontend.context.Context; import com.redhat.rhn.frontend.dto.HelpDocumentOverview; import com.redhat.rhn.frontend.struts.RequestContext; @@ -38,6 +39,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.Enumeration; import java.util.HashMap; +import java.util.LinkedList; import java.util.List; import java.util.Locale; import java.util.Map; @@ -62,6 +64,7 @@ public class DocSearchSetupAction extends RhnAction { private static final String OPT_CONTENT_TITLE = "search_content_title";
/** {@inheritDoc} */ + @Override public ActionForward execute(ActionMapping mapping, ActionForm formIn, HttpServletRequest request, HttpServletResponse response) {
@@ -167,7 +170,7 @@ public class DocSearchSetupAction extends RhnAction { if (!StringUtils.isBlank(searchString)) { List results = performSearch(ctx.getWebSession().getId(), searchString, - viewmode); + viewmode, request); log.debug("GET search: " + results); request.setAttribute("pageList", results != null ? results : Collections.EMPTY_LIST); @@ -178,7 +181,7 @@ public class DocSearchSetupAction extends RhnAction { }
private List performSearch(Long sessionId, String searchString, - String mode) + String mode, HttpServletRequest request) throws XmlRpcFault, MalformedURLException {
log.debug("Performing doc search"); @@ -204,7 +207,29 @@ public class DocSearchSetupAction extends RhnAction { searchFreeForm = true; } args.add(searchFreeForm); - List results = (List)client.invoke("index.search", args); + List results = Collections.EMPTY_LIST; + try { + results = (List)client.invoke("index.search", args); + } + catch (XmlRpcFault e) { + if (e.getErrorCode() == 200) { + //This is most likely a language error + //so lets try the search the default language + //removing the 'lang' from the args + args.remove(args.size() - 2); + results = (List)client.invoke("index.search", args); + + List<ValidatorWarning> warnings = new LinkedList<ValidatorWarning>(); + warnings.add(new ValidatorWarning + ("packages.search.index_files_missing_for_docs")); + + getStrutsDelegate().saveMessages(request, Collections.EMPTY_LIST, warnings); + + } + else { + throw e; + } + }
if (log.isDebugEnabled()) { log.debug("results = [" + results + "]"); diff --git a/java/code/src/com/redhat/rhn/frontend/strings/java/StringResource_en_US.xml b/java/code/src/com/redhat/rhn/frontend/strings/java/StringResource_en_US.xml index c1e6408..4369778 100644 --- a/java/code/src/com/redhat/rhn/frontend/strings/java/StringResource_en_US.xml +++ b/java/code/src/com/redhat/rhn/frontend/strings/java/StringResource_en_US.xml @@ -2795,6 +2795,16 @@ available for this kickstart profile to function properly. </context-group> </trans-unit>
+ <trans-unit id="packages.search.index_files_missing_for_docs"> +<source>Index files were missing from search-server for your locale. The search operation was performed using the default locale. Assuming data exists in database for your locale, indexes can be regenerated by running: /etc/init.d/rhn-search cleanindex, then restart rhn-search</source> + <context-group name="ctx"> + <context context-type="sourcefile">/rhn/channels/Search</context> + <context context-type="sourcefile">/rhn/systems/Search</context> + <context context-type="sourcefile">/rhn/help/Search</context> + <context context-type="sourcefile">/rhn/errata/Search</context> + </context-group> + </trans-unit> + <trans-unit id="packages.search.could_not_execute_query"> <source>Could not execute query '{0}'.</source> <context-group name="ctx"> diff --git a/search-server/spacewalk-search/src/java/com/redhat/satellite/search/index/IndexManager.java b/search-server/spacewalk-search/src/java/com/redhat/satellite/search/index/IndexManager.java index d34e2af..ce80df2 100644 --- a/search-server/spacewalk-search/src/java/com/redhat/satellite/search/index/IndexManager.java +++ b/search-server/spacewalk-search/src/java/com/redhat/satellite/search/index/IndexManager.java @@ -15,12 +15,18 @@
package com.redhat.satellite.search.index;
-import com.redhat.satellite.search.config.Configuration; -import com.redhat.satellite.search.index.builder.BuilderFactory; -import com.redhat.satellite.search.index.ngram.NGramAnalyzer; -import com.redhat.satellite.search.index.ngram.NGramQueryParser; -import com.redhat.satellite.search.rpc.handlers.IndexHandler; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.Set; +import java.util.TreeMap;
+import org.apache.commons.lang.StringUtils; import org.apache.hadoop.fs.FileSystem; import org.apache.log4j.Logger; import org.apache.lucene.analysis.Analyzer; @@ -47,15 +53,11 @@ import org.apache.nutch.searcher.HitDetails; import org.apache.nutch.searcher.Summary; import org.apache.nutch.util.NutchConfiguration;
-import java.io.File; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; +import com.redhat.satellite.search.config.Configuration; +import com.redhat.satellite.search.index.builder.BuilderFactory; +import com.redhat.satellite.search.index.ngram.NGramAnalyzer; +import com.redhat.satellite.search.index.ngram.NGramQueryParser; +import com.redhat.satellite.search.rpc.handlers.IndexHandler;
/** * Indexing workhorse class @@ -78,7 +80,8 @@ public class IndexManager { private AnalyzerFactory nutchAnalyzerFactory; // Name conflict with our Configuration class and Hadoop's private org.apache.hadoop.conf.Configuration nutchConf; - private Map<String, String> docLocaleLookUp = new HashMap<String, String>(); + private Map<String, String> docLocaleLookUp = new TreeMap<String, String> + (String.CASE_INSENSITIVE_ORDER); private Map<String, FetchedSegments> docSegments; /** * Constructor @@ -677,14 +680,22 @@ public class IndexManager { }
private String getDocIndexPath(String lang) throws IOException { - if (docLocaleLookUp.containsKey(lang)) { - return BuilderFactory.DOCS_TYPE + File.separator + - docLocaleLookUp.get(lang); + String l = lookupLocale(lang); + if (!StringUtils.isBlank(l)) { + return BuilderFactory.DOCS_TYPE + File.separator + l; } log.error("Unable to find docs index dir for language " + lang); throw new IOException("Unable to find docs index dir for language: " + lang); }
+ private String lookupLocale(String lang) { + String ret = docLocaleLookUp.get(lang.toLowerCase()); + if (StringUtils.isBlank(ret)) { + Locale l = new Locale(lang); + ret = docLocaleLookUp.get(l.getLanguage().toLowerCase()); + } + return ret; + }
private Analyzer getDocAnalyzer(String lang) { /** @@ -775,9 +786,9 @@ public class IndexManager { nutchConf = NutchConfiguration.create(); nutchAnalyzerFactory = new AnalyzerFactory(nutchConf); FileSystem fs = FileSystem.get(nutchConf); - docSegments = new HashMap<String, FetchedSegments>(); + docSegments = new TreeMap<String, FetchedSegments> + (String.CASE_INSENSITIVE_ORDER); for (String key : docLocaleLookUp.keySet()) { - String lang = docLocaleLookUp.get(key); String segmentsDir = indexWorkDir + File.separator + getDocIndexPath(key) + File.separator + "segments"; FetchedSegments segments = new FetchedSegments(fs, segmentsDir, nutchConf); @@ -841,9 +852,11 @@ public class IndexManager { }
private void initDocLocaleLookup() { - docLocaleLookUp.put("bn_IN", "bn-IN"); + docLocaleLookUp.put("bn", "bn-IN"); + docLocaleLookUp.put("bn_in", "bn-IN"); docLocaleLookUp.put("de", "de-DE"); - docLocaleLookUp.put("en_US", "en-US"); + docLocaleLookUp.put("en_us", "en-US"); + docLocaleLookUp.put("en", "en-US"); docLocaleLookUp.put("es", "es-ES"); docLocaleLookUp.put("fr", "fr-FR"); docLocaleLookUp.put("gu", "gu-IN"); @@ -852,11 +865,14 @@ public class IndexManager { docLocaleLookUp.put("ja", "ja-JP"); docLocaleLookUp.put("ko", "ko-KR"); docLocaleLookUp.put("pa", "pa-IN"); - docLocaleLookUp.put("pt_BR", "pt-BR"); + docLocaleLookUp.put("pt_br", "pt-BR"); + docLocaleLookUp.put("pt", "pt-BR"); + docLocaleLookUp.put("pt_pt", "pt-BR"); docLocaleLookUp.put("ru", "ru-RU"); docLocaleLookUp.put("ta", "ta-IN"); - docLocaleLookUp.put("zh_CN", "zh-CN"); - docLocaleLookUp.put("zh_TW", "zh-TW"); + docLocaleLookUp.put("zh", "zh-CN"); + docLocaleLookUp.put("zh_cn", "zh-CN"); + docLocaleLookUp.put("zh_tw", "zh-TW"); // Below exist in docs, but weren't available as a doc option from // satellite webui and they weren't available Locales on my machine // guessing at what they will look at.
spacewalk-commits@lists.fedorahosted.org