Java Code Examples for org.apache.solr.common.util.SimpleOrderedMap#getName()

The following examples show how to use org.apache.solr.common.util.SimpleOrderedMap#getName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FacetBucket.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
public void mergeBucket(@SuppressWarnings("rawtypes") SimpleOrderedMap bucket, FacetMerger.Context mcontext) {
  // todo: for refinements, we want to recurse, but not re-do stats for intermediate buckets

  mcontext.setShardFlag(bucketNumber);

  // drive merging off the received bucket?
  for (int i=0; i<bucket.size(); i++) {
    String key = bucket.getName(i);
    Object val = bucket.getVal(i);
    if ("count".equals(key)) {
      count += ((Number)val).longValue();
      continue;
    }
    if ("val".equals(key)) {
      // this is taken care of at a higher level...
      continue;
    }

    FacetMerger merger = getMerger(key, val);

    if (merger != null) {
      merger.merge( val , mcontext );
    }
  }
}
 
Example 2
Source File: SolrUtils.java    From vind with Apache License 2.0 5 votes vote down vote up
private static HashMap<FieldDescriptor, TermFacetResult<?>> getTermFacetResults(QueryResponse response, DocumentFactory factory, DocumentFactory childFactory, Map<String,Facet>  facetsQuery, String searchContext) {
    final HashMap<FieldDescriptor, TermFacetResult<?>> facets = new HashMap<>();
    //term facets
    if (Objects.nonNull(response.getResponse())) {
        final SimpleOrderedMap jsonFacetResult = (SimpleOrderedMap) response.getResponse().get("facets");
        if (Objects.nonNull(jsonFacetResult)) {
            for (int i = 0; i < jsonFacetResult.size(); i++) {
                final String facetName = jsonFacetResult.getName(i);
                if (jsonFacetResult.getName(i).startsWith("dynamic_")) {
                    final String fieldName = getFieldDescriptorName(searchContext, facetName);
                    FieldDescriptor<?> fieldDesc = factory.getField(fieldName);
                    if (Objects.isNull(fieldDesc) && Objects.nonNull(childFactory)) {
                        fieldDesc = childFactory.getField(fieldName);
                    }
                    final FieldDescriptor<?> descriptor = fieldDesc;

                    final ArrayList<SimpleOrderedMap> termFacet =
                            ((ArrayList<SimpleOrderedMap>) ((SimpleOrderedMap) jsonFacetResult.get(facetName)).get("buckets"));

                    if (Objects.nonNull(descriptor)) {
                        final UseCase useCase = UseCase.valueOf(facetsQuery.get(fieldName).getScope().name());
                        final TermFacetResult<?> facet = new TermFacetResult(termFacet.stream()
                                .map(f ->
                                    new FacetValue<>(
                                            castForDescriptor(f.get("val"), descriptor, useCase),
                                            NumberUtils.toLong(f.get("count").toString(),0))
                                )
                                .collect(Collectors.toList()));

                        facets.put(descriptor, facet);
                    } else {
                        log.error("Unable to create a facet result: the field '{}' is not configured as facet.", fieldName);
                        throw new RuntimeException("Unable to create a faceted result: the field '" + fieldName + "' is not configured as facet.");
                    }
                }
            }
        }
    }
    return facets;
}
 
Example 3
Source File: SchemaXmlWriter.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings({"unchecked"})
private void writeFieldTypes(List<SimpleOrderedMap<Object>> fieldTypePropertiesList) throws IOException {
  for (SimpleOrderedMap<Object> fieldTypeProperties : fieldTypePropertiesList) {
    SimpleOrderedMap<Object> analyzerProperties = null;
    SimpleOrderedMap<Object> indexAnalyzerProperties = null;
    SimpleOrderedMap<Object> queryAnalyzerProperties = null;
    SimpleOrderedMap<Object> multiTermAnalyzerProperties = null;
    SimpleOrderedMap<Object> perFieldSimilarityProperties = null;
    openStartTag(IndexSchema.FIELD_TYPE);
    for (int fieldTypePropNum = 0 ; fieldTypePropNum < fieldTypeProperties.size() ; ++fieldTypePropNum) {
      String fieldTypePropName = fieldTypeProperties.getName(fieldTypePropNum);
      if (fieldTypePropName.equals(FieldType.ANALYZER)) {
        analyzerProperties = (SimpleOrderedMap<Object>)fieldTypeProperties.getVal(fieldTypePropNum);
      } else if (fieldTypePropName.equals(FieldType.INDEX_ANALYZER)) {
        indexAnalyzerProperties =  (SimpleOrderedMap<Object>)fieldTypeProperties.getVal(fieldTypePropNum); 
      } else if (fieldTypePropName.equals(FieldType.QUERY_ANALYZER)) {
        queryAnalyzerProperties = (SimpleOrderedMap<Object>)fieldTypeProperties.getVal(fieldTypePropNum);
      } else if (fieldTypePropName.equals(FieldType.MULTI_TERM_ANALYZER)) {
        multiTermAnalyzerProperties = (SimpleOrderedMap<Object>)fieldTypeProperties.getVal(fieldTypePropNum);
      } else if (fieldTypePropName.equals(FieldType.SIMILARITY)) {
        perFieldSimilarityProperties = (SimpleOrderedMap<Object>)fieldTypeProperties.getVal(fieldTypePropNum);
      } else {
        writeAttr(fieldTypePropName, fieldTypeProperties.getVal(fieldTypePropNum).toString());
      }
    }
    boolean isEmptyTag = null == analyzerProperties           && null == indexAnalyzerProperties
                      && null == queryAnalyzerProperties      && null == multiTermAnalyzerProperties
                      && null == perFieldSimilarityProperties;
    if (isEmptyTag) {
      closeStartTag(true);
    } else {
      closeStartTag(false);
      incLevel();
      if (null != analyzerProperties)           writeAnalyzer(analyzerProperties, null);
      if (null != indexAnalyzerProperties)      writeAnalyzer(indexAnalyzerProperties, FieldType.INDEX);
      if (null != queryAnalyzerProperties)      writeAnalyzer(queryAnalyzerProperties, FieldType.QUERY);
      if (null != multiTermAnalyzerProperties)  writeAnalyzer(multiTermAnalyzerProperties, FieldType.MULTI_TERM);
      if (null != perFieldSimilarityProperties) writeSimilarity(perFieldSimilarityProperties);
      decLevel();
      endTag(IndexSchema.FIELD_TYPE);
    }
  }
}
 
Example 4
Source File: SchemaXmlWriter.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings({"unchecked"})
private void writeAnalyzer(SimpleOrderedMap<Object> analyzerProperties, String analyzerType) throws IOException {
  openStartTag(FieldType.ANALYZER);
  if (null != analyzerType) {
    writeAttr(FieldType.TYPE, analyzerType);
  }
  List<SimpleOrderedMap<Object>> charFilterPropertiesList = null;
  SimpleOrderedMap<Object> tokenizerProperties = null;
  List<SimpleOrderedMap<Object>> filterPropertiesList = null;
  for (int i = 0 ; i < analyzerProperties.size() ; ++i) {
    String name = analyzerProperties.getName(i);
    if (name.equals(FieldType.CHAR_FILTERS)) {
      charFilterPropertiesList = (List<SimpleOrderedMap<Object>>)analyzerProperties.getVal(i);
    } else if (name.equals(FieldType.TOKENIZER)) {
      tokenizerProperties = (SimpleOrderedMap<Object>)analyzerProperties.getVal(i);
    } else if (name.equals(FieldType.FILTERS)) {
      filterPropertiesList = (List<SimpleOrderedMap<Object>>)analyzerProperties.getVal(i);
    } else if (name.equals(FieldType.CLASS_NAME)) {
      if ( ! "solr.TokenizerChain".equals(analyzerProperties.getVal(i))) {
        writeAttr(name, analyzerProperties.getVal(i).toString());
      }
    } else if (name.equals(IndexSchema.LUCENE_MATCH_VERSION_PARAM)) {
      writeAttr(name, analyzerProperties.getVal(i).toString());
    }
  }
  boolean isEmptyTag
      = null == charFilterPropertiesList && null == tokenizerProperties && null == filterPropertiesList;
  if (isEmptyTag) {
    closeStartTag(true);
  } else {
    closeStartTag(false);
    incLevel();
    if (null != charFilterPropertiesList) {
      for (SimpleOrderedMap<Object> charFilterProperties : charFilterPropertiesList) {
        openStartTag(FieldType.CHAR_FILTER);
        for (int i = 0 ; i < charFilterProperties.size() ; ++i) {
          writeAttr(charFilterProperties.getName(i), charFilterProperties.getVal(i).toString());
        }
        closeStartTag(true);
      }
    }
    if (null != tokenizerProperties) {
      openStartTag(FieldType.TOKENIZER);
      for (int i = 0 ; i < tokenizerProperties.size() ; ++i) {
        writeAttr(tokenizerProperties.getName(i), tokenizerProperties.getVal(i).toString());
      }
      closeStartTag(true);
    }
    if (null != filterPropertiesList) {
      for (SimpleOrderedMap<Object> filterProperties : filterPropertiesList) {
        openStartTag(FieldType.FILTER);
        for (int i = 0 ; i < filterProperties.size() ; ++i) {
          writeAttr(filterProperties.getName(i), filterProperties.getVal(i).toString());
        }
        closeStartTag(true);
      }
    }
    decLevel();
    endTag(FieldType.ANALYZER);
  }
}