Search in sources :

Example 1 with RenameFieldTransformer

use of org.apache.solr.response.transform.RenameFieldTransformer in project lucene-solr by apache.

the class SolrReturnFields method parseFieldList.

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))) {
                    // copy from the current target
                    rename.setName(j, to);
                    if (reqFieldNames == null) {
                        reqFieldNames = new LinkedHashSet<>();
                    }
                    // don't rename our current target
                    reqFieldNames.add(to);
                }
            }
        }
        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
        // this will get all fields, and use wantsField to limit
        fields.clear();
    }
    if (augmenters.size() == 1) {
        transformer = augmenters.getTransformer(0);
    } else if (augmenters.size() > 1) {
        transformer = augmenters;
    }
}
Also used : DocTransformers(org.apache.solr.response.transform.DocTransformers) NamedList(org.apache.solr.common.util.NamedList) RenameFieldTransformer(org.apache.solr.response.transform.RenameFieldTransformer)

Aggregations

NamedList (org.apache.solr.common.util.NamedList)1 DocTransformers (org.apache.solr.response.transform.DocTransformers)1 RenameFieldTransformer (org.apache.solr.response.transform.RenameFieldTransformer)1