Java Code Examples for org.apache.solr.common.util.NamedList#setName()

The following examples show how to use org.apache.solr.common.util.NamedList#setName() . 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: RewriteFacetCountsComponent.java    From SearchServices with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Update entries in a list to reference ACS properties rather than Solr fields.
 *
 * @param mappings The mapping from ACS properties to Solr fields.
 * @param propertyList The list to update.
 */
private void updateToACSNaming(BiMap<String, String> mappings, NamedList<Object> propertyList)
{
    for (int i = 0; i < propertyList.size(); i++)
    {
        String name = propertyList.getName(i);
        String newName = mappings.inverse().get(name);
        if (newName != null)
        {
            propertyList.setName(i, newName);
        }
    }
}
 
Example 2
Source File: MtasSolrResultUtil.java    From mtas with Apache License 2.0 5 votes vote down vote up
/**
 * Decode.
 *
 * @param nl the nl
 * @return the named list
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
static NamedList<Object> decode(NamedList<Object> nl) {
  for (int i = 0; i < nl.size(); i++) {
    String key = nl.getName(i);
    Object o = nl.getVal(i);
    if (key.matches("^_encoded_.*$")) {
      if (o instanceof String) {
        Object decodedObject = decode((String) nl.getVal(i));
        String decodedKey = key.replaceFirst("^_encoded_", "");
        if (decodedKey.equals("")) {
          decodedKey = "_" + decodedObject.getClass().getSimpleName() + "_";
        }
        nl.setName(i, decodedKey);
        nl.setVal(i, decodedObject);
      } else if (o instanceof NamedList) {
        NamedList nl2 = (NamedList) o;
        for (int j = 0; j < nl2.size(); j++) {
          if (nl2.getVal(j) instanceof String) {
            nl2.setVal(j, decode((String) nl2.getVal(j)));
          }
        }
      } else {
        // System.out.println("unknown type " +
        // o.getClass().getCanonicalName());
      }
    } else {
      if (o instanceof NamedList) {
        nl.setVal(i, decode((NamedList<Object>) o));
      } else if (o instanceof ArrayList) {
        nl.setVal(i, decode((ArrayList<Object>) o));
      }
    }
  }
  return nl;
}
 
Example 3
Source File: SolrReturnFields.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
private void parseFieldList(String[] fl, SolrQueryRequest req) {
  _wantsScore = false;
  _wantsAllFields = false;
  if (fl == null || fl.length == 0 || fl.length == 1 && fl[0].length()==0) {
    _wantsAllFields = true;
    return;
  }

  NamedList<String> rename = new NamedList<>();
  DocTransformers augmenters = new DocTransformers();
  for (String fieldList : fl) {
    add(fieldList,rename,augmenters,req);
  }
  for( int i=0; i<rename.size(); i++ ) {
    String from = rename.getName(i);
    String to = rename.getVal(i);
    okFieldNames.add( to );
    boolean copy = (reqFieldNames!=null && reqFieldNames.contains(from));
    if(!copy) {
      // Check that subsequent copy/rename requests have the field they need to copy
      for(int j=i+1; j<rename.size(); j++) {
        if(from.equals(rename.getName(j))) {
          rename.setName(j, to); // copy from the current target
          if(reqFieldNames==null) {
            reqFieldNames = new LinkedHashSet<>();
          }
          reqFieldNames.add(to); // don't rename our current target
        }
      }
    }
    augmenters.addTransformer( new RenameFieldTransformer( from, to, copy ) );
  }
  if (rename.size() > 0 ) {
    renameFields = rename.asShallowMap();
  }
  if( !_wantsAllFields && !globs.isEmpty() ) {
    // TODO??? need to fill up the fields with matching field names in the index
    // and add them to okFieldNames?
    // maybe just get all fields?
    // this would disable field selection optimization... i think that is OK
    fields.clear(); // this will get all fields, and use wantsField to limit
  }

  if( augmenters.size() == 1 ) {
    transformer = augmenters.getTransformer(0);
  }
  else if( augmenters.size() > 1 ) {
    transformer = augmenters;
  }
}