List of usage examples for org.apache.solr.common.util NamedList NamedList
public NamedList()
From source file:alba.solr.core.Loader.java
License:Apache License
@Override public NamedList<String> getStatistics() { NamedList<String> nl = new NamedList<String>(); nl.add("prova", "abc"); return nl;/* w w w . j a v a 2 s .c o m*/ }
From source file:alba.solr.searchcomponents.AlbaRequestHandler.java
License:Apache License
public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception { // TODO Auto-generated method stub /* List<SearchComponent> components = new ArrayList<SearchComponent>(); /*ww w. j a v a2 s . com*/ MySearchComponent msc = new MySearchComponent(); ResponseBuilder rb = new ResponseBuilder(req, rsp, components); msc.process(rb);*/ //rsp.add("hello", rb.rsp.getValues()); req.getContext().put(Loader.FUNCTIONS, functions); Object params[] = new Object[2]; params[0] = req; params[1] = rsp; // what if this method calls rsp.add( .. ) ???? Object result = this.function.getMethod().invoke(this.function.getInstance(), params); if (Map.class.isAssignableFrom(result.getClass())) { // if we got a Map, just return it as-is rsp.add(this.sectionName, result); } else // if we got anything else, try to serialize it! if (List.class.isAssignableFrom(result.getClass())) { for (Object o : (List) result) { DocumentObjectBinder dob = new DocumentObjectBinder(); SolrInputDocument sd = dob.toSolrInputDocument(o); SolrDocument dest = ClientUtils.toSolrDocument(sd); HashMap<Object, Object> nl = (HashMap<Object, Object>) dest.get("functionDescriptor"); //rsp.add(nl.get("name").toString(), dest2); rsp.add(null, dest); } } if (StaticResource.class.isAssignableFrom(result.getClass())) { FilteredShowFileRequestHandler file = new FilteredShowFileRequestHandler(); file.init(new NamedList()); //to initialize internal variables - but in this way it will NOT get the proper configuration from SolrConfig! ModifiableSolrParams solrParams = new ModifiableSolrParams(req.getParams()); StaticResource resource = ((StaticResource) result); solrParams.set("file", resource.getName()); //TODO Proper mapping here!! //solrParams.set("contentType", "text/xml;charset=utf-8"); solrParams.set("contentType", resource.getContentType()); req.setParams(solrParams); file.handleRequest(req, rsp); // logger.error("returning the content of " + ); } else { // unable to do any kind of serialization.. just add the result and let the ResponseWriter handle it rsp.add(null, result); } }
From source file:at.newmedialab.lmf.util.solr.suggestion.service.SuggestionService.java
License:Apache License
public SuggestionService(SolrCore solrCore, NamedList args) { NamedList l = new NamedList(); //set spellcheck component if there is one if (((ArrayList) args.get("first-components")).contains("spellcheck")) { List component = new ArrayList<String>(); component.add("spellcheck"); l.add("first-components", component); spellcheck_enabled = true;/*from ww w . j a va2 s. c o m*/ } this.solrCore = solrCore; this.searchHandler = new SearchHandler(); this.searchHandler.init(l); this.searchHandler.inform(solrCore); }
From source file:com.doculibre.constellio.services.AutocompleteServicesImpl.java
License:Open Source License
@Override public NamedList<Object> suggest(String q, IndexField indexField) { NamedList<Object> returnList = new NamedList<Object>(); if (!indexField.isAutocompleted()) { return returnList; }//from ww w . j a v a2 s . com SolrServer server = null; try { String collectionName = indexField.getRecordCollection().getName(); server = SolrCoreContext.getSolrServer(collectionName); } catch (Exception e) { throw new RuntimeException(e); } if (!hasStringType(indexField)) { // FIXME voir avec Rida s'il faut analyser la requete return suggest(q, indexField.getName(), server, false); } // FIXME valider avec Vincent si on se base sur le champ de copie (dans // le cas des chaines de // caractere)? q = AnalyzerUtils.analyze(q, indexField.getName(), server, true); String associatedIndexFieldName = getAssociatedIndexFieldName(indexField); returnList = suggest(q, associatedIndexFieldName, server, true); return returnList; }
From source file:com.doculibre.constellio.services.AutocompleteServicesImpl.java
License:Open Source License
@SuppressWarnings("unchecked") static private NamedList<Object> suggest(String q, String fieldName, SolrServer server, Boolean isStringField) { NamedList<Object> returnList = new NamedList<Object>(); // escape special characters SolrQuery query = new SolrQuery(); /*//from www . j a v a 2 s .c o m * // * Set terms.lower to the input term * query.setParam(TermsParams.TERMS_LOWER, q); // * Set terms.prefix to * the input term query.setParam(TermsParams.TERMS_PREFIX, q); // * Set * terms.lower.incl to false * query.setParam(TermsParams.TERMS_LOWER_INCLUSIVE, "false"); // * Set * terms.fl to the name of the source field * query.setParam(TermsParams.TERMS_FIELD, fieldName); */ query.setParam(TermsParams.TERMS_FIELD, fieldName);// query.addTermsField("spell"); query.setParam(TermsParams.TERMS_LIMIT, TERMS_LIMIT);// query.setTermsLimit(MAX_TERMS); query.setParam(TermsParams.TERMS, "true");// query.setTerms(true); query.setParam(TermsParams.TERMS_LOWER, q);// query.setTermsLower(q); query.setParam(TermsParams.TERMS_PREFIX, q);// query.setTermsPrefix(q); query.setParam(TermsParams.TERMS_MINCOUNT, TERMS_MINCOUNT); query.setRequestHandler(SolrServices.AUTOCOMPLETE_QUERY_NAME); try { QueryResponse qr = server.query(query); NamedList<Object> values = qr.getResponse(); NamedList<Object> terms = (NamedList<Object>) values.get("terms");// TermsResponse // resp // = // qr.getTermsResponse(); NamedList<Object> suggestions = (NamedList<Object>) terms.get(fieldName);// items // = // resp.getTerms("spell"); if (!isStringField) { q = AnalyzerUtils.analyzePhrase(q, false); } for (int i = 0; i < suggestions.size(); i++) { String currentSuggestion = suggestions.getName(i); // System.out.println(currentSuggestion); if (isStringField) { if (currentSuggestion.contains(q)) { // String suffix = // StringUtils.substringAfter(currentSuggestion, q); // if (suffix.isEmpty() && // !currentSuggestion.equals(q)){ // //q n est pas dans currentSuggestion // break; // } if (currentSuggestion.contains(SPECIAL_CHAR)) { // le resultat de recherche retourne des fois une // partie de la valeur existant // dans le champ! currentSuggestion = StringUtils.substringAfter(currentSuggestion, SPECIAL_CHAR); } returnList.add(currentSuggestion, suggestions.getVal(i)); } } else { currentSuggestion = AnalyzerUtils.analyzePhrase(currentSuggestion, false); if (currentSuggestion.contains(q)) { returnList.add(currentSuggestion, suggestions.getVal(i)); } } } } catch (SolrServerException e) { throw new RuntimeException(e); } return returnList; }
From source file:com.doculibre.constellio.servlets.ConstellioServletUtils.java
License:Open Source License
public static NamedList<Object> getErrorNamedList(Exception e, SolrParams solrParams) { NamedList<Object> responseHeader = new NamedList<Object>(); responseHeader.add(ServletsConstants.RESPONSE_STATUS, 500); NamedList<Object> error = new NamedList<Object>(); error.add(ServletsConstants.MESSAGE, e.getMessage()); StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); e.printStackTrace(pw);/*from ww w . ja v a 2s .co m*/ pw.flush(); pw.close(); error.add(ServletsConstants.STACK_TRACE, sw.getBuffer().toString()); addParams(responseHeader, solrParams); NamedList<Object> nl = new NamedList<Object>(); nl.add(ServletsConstants.RESPONSE_HEADER, responseHeader); nl.add(ServletsConstants.ERROR, error); return nl; }
From source file:com.doculibre.constellio.servlets.ConstellioServletUtils.java
License:Open Source License
public static NamedList<Object> getSuccessfulNamedList(SolrParams solrParams) { NamedList<Object> responseHeader = new NamedList<Object>(); responseHeader.add(ServletsConstants.RESPONSE_STATUS, 0); NamedList<Object> nl = new NamedList<Object>(); nl.add(ServletsConstants.RESPONSE_HEADER, responseHeader); addParams(responseHeader, solrParams); return nl;/* w ww.java2s.co m*/ }
From source file:com.doculibre.constellio.servlets.ConstellioServletUtils.java
License:Open Source License
private static void addParams(NamedList<Object> responseHeader, SolrParams solrParams) { NamedList<Object> params = new NamedList<Object>(); responseHeader.add("params", params); Iterator<String> enumParams = solrParams.getParameterNamesIterator(); while (enumParams.hasNext()) { String param = enumParams.next(); if (!param.equals(ServletsConstants.DIGEST_PARAM)) { String[] values = solrParams.getParams(param); params.add(param, values.length > 1 ? Arrays.asList(values) : values[0]); }/* www.j a v a2s . c o m*/ } }
From source file:com.doculibre.constellio.spellchecker.SpellChecker.java
License:Open Source License
public NamedList<Object> suggestNamedList(String sentence, String collectionName) { NamedList<Object> nl = new NamedList<Object>(); addSuggestions(sentence, collectionName, null, nl, null); return nl;/*ww w .ja va 2 s . c o m*/ }
From source file:com.doculibre.constellio.spellchecker.SpellChecker.java
License:Open Source License
private void addNamedList(NamedList<Object> mainList, String word, boolean missSpelled, List<String> suggestions) { NamedList<Object> nlWord = new NamedList<Object>(); nlWord.add("frequency", missSpelled ? 0 : 1); NamedList<Object> suggestionsNamedList = new NamedList<Object>(); if (suggestions != null) { for (String suggestedWord : suggestions) { NamedList<Object> nlSuggestedWord = new NamedList<Object>(); nlSuggestedWord.add("frequency", 1); suggestionsNamedList.add(suggestedWord, nlSuggestedWord); }//from ww w . j ava2 s . c om } nlWord.add("suggestions", suggestionsNamedList); mainList.add(word, nlWord); }