List of usage examples for org.apache.solr.common.util NamedList size
public int size()
From source file:alba.solr.core.Loader.java
License:Apache License
@Override public void init() { requestHandlers = new HashMap<String, AlbaRequestHandler>(); searchComponents = new HashMap<String, CallableFunction>(); functions = new HashMap<String, CallableFunction>(); postFilters = new HashMap<String, CallableFunction>(); pseudoFields = new HashMap<String, SolrPseudoField>(); dynamicFunctions = new HashMap<String, DocValuesDynamicValueSource>(); packageScanner = new PackageScanner(); cachedResults = new HashMap<Object, CachedResult>(); docTransformers = new HashMap<String, CallableFunction>(); responseWriters = new HashMap<String, AlbaResponseWriter>(); NamedList l = this.getInitParams(); NamedList<String> packagesToScan = (NamedList<String>) this.getInitParams().get("packagesToScan"); String packageName = ""; for (int i = 0; i < packagesToScan.size(); i++) { packageName = packagesToScan.getVal(i); //loadPlugins(packageName); loadPlugins2(packageName);// w w w. j a v a2 s . co m } }
From source file:co.diji.solr.XMLWriter.java
License:Apache License
public void writeNamedList(String name, NamedList val) throws IOException { int sz = val.size(); startTag("lst", name, sz <= 0); for (int i = 0; i < sz; i++) { writeVal(val.getName(i), val.getVal(i)); }/*from w ww. j a v a 2s . co m*/ if (sz > 0) { writer.write("</lst>"); } }
From source file:com.constellio.data.dao.services.bigVault.CustomizedSpellCheckResponse.java
License:Apache License
public CustomizedSpellCheckResponse(NamedList<Object> spellInfo) { Object sugg = spellInfo.get("suggestions"); if (sugg == null) { correctlySpelled = true;//from ww w.j a va2 s . c o m return; } for (int i = 0; i < spellInfo.size(); i++) { String n = spellInfo.getName(i); if ("correctlySpelled".equals(n)) { correctlySpelled = (Boolean) spellInfo.getVal(i); } else if ("collationInternalRank".equals(n)) { //continue; } else if ("collations".equals(n)) { List<Object> collationInfo = spellInfo.getAll(n); collations = new ArrayList<>(collationInfo.size()); for (Object o : collationInfo) { if (o instanceof String) { collations.add(new Collation().setCollationQueryString((String) o)); } else if (o instanceof NamedList) { @SuppressWarnings("unchecked") NamedList<Object> expandedCollation = (NamedList<Object>) o; String collationQuery = (String) expandedCollation.get("collationQuery"); int hits = (Integer) expandedCollation.get("hits"); @SuppressWarnings("unchecked") NamedList<String> misspellingsAndCorrections = (NamedList<String>) expandedCollation .get("misspellingsAndCorrections"); Collation collation = new Collation(); collation.setCollationQueryString(collationQuery); collation.setNumberOfHits(hits); for (int ii = 0; ii < misspellingsAndCorrections.size(); ii++) { String misspelling = misspellingsAndCorrections.getName(ii); String correction = misspellingsAndCorrections.getVal(ii); collation.addMisspellingsAndCorrection(new Correction(misspelling, correction)); } collations.add(collation); } else { throw new AssertionError("Should get Lists of Strings or List of NamedLists here."); } } } else { @SuppressWarnings("unchecked") Suggestion s = new Suggestion(n, (NamedList<Object>) spellInfo.getVal(i)); suggestionMap.put(n, s); suggestions.add(s); } } }
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 w w w. j av a 2s. com*/ * // * 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.services.AutocompleteServicesImpl.java
License:Open Source License
private static void print(String q, NamedList<Object> suggestions) { System.out.println("########### " + q + " ##############"); for (int i = 0; i < suggestions.size(); i++) { System.out.println(suggestions.getName(i) + "\t" + suggestions.getVal(i)); }/*from www . j a v a 2s. c o m*/ }
From source file:com.doculibre.constellio.servlets.SolrJExampleMain.java
License:Open Source License
/** * Print documents and facets// w w w . j a va 2s . com * * @param response */ @SuppressWarnings("unchecked") public static void print(QueryResponse response) { SolrDocumentList docs = response.getResults(); if (docs != null) { System.out.println(docs.getNumFound() + " documents found, " + docs.size() + " returned : "); for (int i = 0; i < docs.size(); i++) { SolrDocument doc = docs.get(i); System.out.println("\t" + doc.toString()); } } List<FacetField> fieldFacets = response.getFacetFields(); if (fieldFacets != null && fieldFacets.isEmpty()) { System.out.println("\nField Facets : "); for (FacetField fieldFacet : fieldFacets) { System.out.print("\t" + fieldFacet.getName() + " :\t"); if (fieldFacet.getValueCount() > 0) { for (Count count : fieldFacet.getValues()) { System.out.print(count.getName() + "[" + count.getCount() + "]\t"); } } System.out.println(""); } } Map<String, Integer> queryFacets = response.getFacetQuery(); if (queryFacets != null && !queryFacets.isEmpty()) { System.out.println("\nQuery facets : "); for (String queryFacet : queryFacets.keySet()) { System.out.println("\t" + queryFacet + "\t[" + queryFacets.get(queryFacet) + "]"); } System.out.println(""); } NamedList<NamedList<Object>> spellCheckResponse = (NamedList<NamedList<Object>>) response.getResponse() .get("spellcheck"); if (spellCheckResponse != null) { Iterator<Entry<String, NamedList<Object>>> wordsIterator = spellCheckResponse.iterator(); while (wordsIterator.hasNext()) { Entry<String, NamedList<Object>> entry = wordsIterator.next(); String word = entry.getKey(); NamedList<Object> spellCheckWordResponse = entry.getValue(); boolean correct = spellCheckWordResponse.get("frequency").equals(1); System.out.println("Word: " + word + ",\tCorrect?: " + correct); NamedList<Integer> suggestions = (NamedList<Integer>) spellCheckWordResponse.get("suggestions"); if (suggestions != null && suggestions.size() > 0) { System.out.println("Suggestions : "); Iterator<Entry<String, Integer>> suggestionsIterator = suggestions.iterator(); while (suggestionsIterator.hasNext()) { System.out.println("\t" + suggestionsIterator.next().getKey()); } } System.out.println(""); } } }
From source file:com.doculibre.constellio.utils.NamedListUtilsTest.java
License:Open Source License
/** * convert an XML file to a NamedList and convert it back to a XML document. * Important : These documents are converted in SolrDocument, it does not * test the conversion of document represented by a NamedList, *///from w w w. j a v a 2 s.co m @Test public void testConversions() throws IOException { File f = new File(NamedListUtilsTest.class.getResource("ANamedList.xml").getFile()); String initialXML = readFileAsString(f); NamedList<Object> nl = NamedListUtils.convertXMLToNamedList(new FileInputStream(f)); TestCase.assertEquals(3, nl.size()); Iterator<Map.Entry<String, Object>> keys = nl.iterator(); TestCase.assertEquals(ServletsConstants.RESPONSE_HEADER, keys.next().getKey()); TestCase.assertEquals(ServletsConstants.RESPONSE, keys.next().getKey()); File tempFile = File.createTempFile("temp", ".xml"); NamedListUtils.convertResponseNamedListToXML(nl, new FileOutputStream(tempFile)); String xml = readFileAsString(tempFile); System.out.println(xml); TestCase.assertEquals(initialXML.replaceAll(" ", "").replace("\n", ""), xml.replaceAll(" ", "").replace("\n", "").replace("\r", "")); }
From source file:com.frank.search.solr.core.ResultHelper.java
License:Apache License
static Map<com.frank.search.solr.core.query.PivotField, List<FacetPivotFieldEntry>> convertFacetQueryResponseToFacetPivotMap( FacetQuery query, QueryResponse response) { if (VersionUtil.isSolr3XAvailable()) { // pivot facets are a solr 4+ Feature return Collections.emptyMap(); }/* w w w .java2s . c om*/ Map<com.frank.search.solr.core.query.PivotField, List<FacetPivotFieldEntry>> facetResult = new HashMap<com.frank.search.solr.core.query.PivotField, List<FacetPivotFieldEntry>>(); NamedList<List<PivotField>> facetPivot = response.getFacetPivot(); if (facetPivot != null && facetPivot.size() > 0) { for (int i = 0; i < facetPivot.size(); i++) { String name = facetPivot.getName(i); List<PivotField> pivotResult = facetPivot.get(name); facetResult.put(new SimplePivotField(name), convertPivotResult(pivotResult)); } } return facetResult; }
From source file:com.github.fengtan.sophie.tables.CoresTable.java
License:Open Source License
/** * Recursively convert a hierarchical NamedList into a linear Map. * /*from w w w. j a va 2s.c om*/ * @param namedList * Hierarchical NamedList. * @param map * Map to be populated. * @return Linear Map populated with values in the NamedList. */ private Map<String, String> linearizeNamedList(NamedList<?> namedList, Map<String, String> map) { // Inspect all elements in the NamedList. for (int idx = 0; idx < namedList.size(); idx++) { Object object = namedList.getVal(idx); if (object instanceof NamedList) { // Element is a NamedList: populate the map recursively. linearizeNamedList((NamedList<?>) object, map); } else { // Element is not a NamedList: add it to the map. String name = namedList.getName(idx); map.put(name, object.toString()); // Create column if it does not exist yet. if (!hasColumn(name)) { addColumn(name); } } } // Return populated map. return map; }
From source file:com.ifactory.press.db.solr.processor.FieldMergingProcessorFactory.java
License:Apache License
private void doInit() { Object o = initArgs.get("destinationField"); if (o == null || !(o instanceof String)) { log.error("destinationField must be present as a string, got " + o); return;//w w w . j ava2 s. c om } destinationField = (String) o; FieldType destinationFieldType = schema.getFieldType(destinationField); if (destinationFieldType == null) { log.error("deistinationField is not defined in the schema: it has no schema type"); return; } o = initArgs.get("sourceField"); if (o == null || !(o instanceof NamedList)) { log.error("sourceField must be present as a list, got " + o); return; } NamedList<?> sourceFields = (NamedList<?>) o; if (sourceFields.size() == 0) { log.error("destinationField must not be empty"); } sourceAnalyzers = new HashMap<String, Analyzer>(); for (int i = 0; i < sourceFields.size(); i++) { String sourceFieldName = sourceFields.getName(i); o = sourceFields.getVal(i); FieldType fieldType; if (o instanceof String && !((String) o).isEmpty()) { String analysisFieldName = (String) o; fieldType = schema.getFieldTypeByName(analysisFieldName); if (fieldType == null) { log.error("No such field type: " + analysisFieldName); } } else { fieldType = schema.getFieldType(sourceFieldName); if (fieldType == null) { log.error("No field type for field: " + sourceFieldName); } } if (fieldType != null) { sourceAnalyzers.put(sourceFieldName, fieldType.getIndexAnalyzer()); } } }