Index: src/java/org/apache/solr/request/PHPResponseWriter.java =================================================================== --- src/java/org/apache/solr/request/PHPResponseWriter.java (revision 0) +++ src/java/org/apache/solr/request/PHPResponseWriter.java (revision 0) @@ -0,0 +1,39 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.solr.request; + +import java.io.Writer; +import java.io.IOException; + +import org.apache.solr.util.NamedList; + +public class PHPResponseWriter implements QueryResponseWriter { + static String CONTENT_TYPE_PHP_UTF8="text/x-php;charset=UTF-8"; + + public void init(NamedList n) { + /* NOOP */ + } + + public void write(Writer writer, SolrQueryRequest req, SolrQueryResponse rsp) throws IOException { + PHPWriter w = new PHPWriter(writer, req, rsp); + w.writeResponse(); + } + + public String getContentType(SolrQueryRequest request, SolrQueryResponse response) { + return CONTENT_TYPE_TEXT_UTF8; + } +} Index: src/java/org/apache/solr/request/JSONResponseWriter.java =================================================================== --- src/java/org/apache/solr/request/JSONResponseWriter.java (revision 521990) +++ src/java/org/apache/solr/request/JSONResponseWriter.java (working copy) @@ -293,7 +293,7 @@ } - private static class MultiValueField { + protected static class MultiValueField { final SchemaField sfield; final ArrayList fields; MultiValueField(SchemaField sfield, Fieldable firstVal) { @@ -792,3 +792,254 @@ writer.write('\''); } } + +class PHPWriter extends JSONWriter { + public PHPWriter(Writer writer, SolrQueryRequest req, SolrQueryResponse rsp) { + super(writer, req, rsp); + } + + @Override + public void writeNull(String name) throws IOException { + writer.write("null"); + } + + @Override + protected void writeKey(String fname, boolean needsEscaping) throws IOException { + writeStr(null, fname, needsEscaping); + writer.write(" => "); + } + + @Override + public void writeStr(String name, String val, boolean needsEscaping) throws IOException { + + writer.write('\''); + if (needsEscaping) { + for (int i=0; i fields, Map otherFields) throws IOException { + boolean includeScore=false; + if (fields!=null) { + includeScore = fields.contains("score"); + if (fields.size()==0 || (fields.size()==1 && includeScore) || fields.contains("*")) { + fields=null; // null means return all stored fields + } + } + + int sz=ids.size(); + + writer.write("array("); + incLevel(); + writeKey("numFound",false); + writeInt(null,ids.matches()); + writer.write(','); + writeKey("start",false); + writeInt(null,ids.offset()); + + if (includeScore) { + writer.write(','); + writeKey("maxScore",false); + writeFloat(null,ids.maxScore()); + } + writer.write(','); + // indent(); + writeKey("docs",false); + writer.write("array("); + + incLevel(); + boolean first=true; + + SolrIndexSearcher searcher = req.getSearcher(); + DocIterator iterator = ids.iterator(); + for (int i=0; i repeats = new HashMap(4); + + boolean first=true; + for (int i=0; i fields, Set returnFields, Map pseudoFields) throws IOException { + writer.write("array("); + incLevel(); + + HashMap multi = new HashMap(); + + boolean first=true; + + for (Fieldable ff : fields) { + String fname = ff.name(); + if (returnFields!=null && !returnFields.contains(fname)) { + continue; + } + + // if the field is multivalued, it may have other values further on... so + // build up a list for each multi-valued field. + SchemaField sf = schema.getField(fname); + if (sf.multiValued()) { + MultiValueField mf = multi.get(fname); + if (mf==null) { + mf = new MultiValueField(sf, ff); + multi.put(fname, mf); + } else { + mf.fields.add(ff); + } + } else { + // not multi-valued, so write it immediately. + if (first) { + first=false; + } else { + writer.write(','); + } + indent(); + writeKey(fname,true); + sf.write(this, fname, ff); + } + } + + for(MultiValueField mvf : multi.values()) { + if (first) { + first=false; + } else { + writer.write(','); + } + + indent(); + writeKey(mvf.sfield.getName(), true); + + boolean indentArrElems=false; + if (doIndent) { + // heuristic... TextField is probably the only field type likely to be long enough + // to warrant indenting individual values. + indentArrElems = (mvf.sfield.getType() instanceof TextField); + } + + writer.write("array("); + boolean firstArrElem=true; + incLevel(); + + for (Fieldable ff : mvf.fields) { + if (firstArrElem) { + firstArrElem=false; + } else { + writer.write(','); + } + if (indentArrElems) indent(); + mvf.sfield.write(this, null, ff); + } + writer.write(')'); + decLevel(); + } + + if (pseudoFields !=null && pseudoFields.size()>0) { + writeMap(null,pseudoFields,true,first); + } + + decLevel(); + writer.write(')'); + } + @Override + public void writeArray(String name, Iterator val) throws IOException { + writer.write("array("); + incLevel(); + boolean first=true; + while( val.hasNext() ) { + if( !first ) indent(); + writeVal(null, val.next()); + if( val.hasNext() ) { + writer.write(','); + } + first=false; + } + decLevel(); + writer.write(')'); + } +} \ No newline at end of file Index: example/solr/conf/solrconfig.xml =================================================================== --- example/solr/conf/solrconfig.xml (revision 521990) +++ example/solr/conf/solrconfig.xml (working copy) @@ -398,6 +398,8 @@ 5 + +