Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reproducer.. wt=phps incompatibility with /admin/luke still in doubts. .. #2114

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,15 @@
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;

import org.apache.lucene.document.Document;
import org.apache.lucene.util.ArrayUtil;
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.UnicodeUtil;
import org.apache.solr.common.SolrDocument;
import org.apache.solr.common.params.CommonParams;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.common.util.SimpleOrderedMap;
import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.search.ReturnFields;

Expand Down Expand Up @@ -84,9 +87,37 @@ public void writeResponse() throws IOException {

@Override
public void writeNamedList(String name, NamedList<?> val) throws IOException {
/*SimpleOrderedMap<Object> copy = new SimpleOrderedMap<>();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove me. wrong way

for (Map.Entry<String,?> tuple : val) {

Object entryVal = tuple.getValue();
if (entryVal!=null && (entryVal instanceof SolrDocument || entryVal instanceof Document)) {
entryVal = new Object[]{entryVal};
}
copy.add(tuple.getKey(), entryVal);
}*/
writeNamedListAsMapMangled(name, val);
}

@Override
public void writeVal(String name, Object val) throws IOException {
if (val==null) {
super.writeVal(name, val);
} else {
if (val instanceof Document || val instanceof SolrDocument) {
writeMapOpener(1); //
//writeKey(1, false); // Docs never appears standalone, but always in docList,
// unless it's reponded by /admin/luke where Lucene Document
// appears in SimpleOrderedMap
// commening this line fixes PHPS format
super.writeVal(""+0, val);
writeMapCloser();
} else {
super.writeVal(name, val);
}
}
}

@Override
public void writeStartDocumentList(
String name, long start, int size, long numFound, Float maxScore, Boolean numFoundExact)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@
import java.io.StringWriter;
import java.util.Arrays;
import java.util.LinkedHashMap;

import org.apache.lucene.document.*;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.common.SolrDocument;
import org.apache.solr.common.SolrDocumentList;
import org.apache.solr.common.util.SimpleOrderedMap;
import org.apache.solr.request.SolrQueryRequest;
import org.junit.BeforeClass;
import org.junit.Test;
Expand Down Expand Up @@ -94,4 +97,29 @@ public void testSolrDocuments() throws IOException {
buf.toString());
req.close();
}

@Test
public void testLuceneDocument() throws IOException {
SolrQueryRequest req = req("q", "*:*");
SolrQueryResponse rsp = new SolrQueryResponse();
QueryResponseWriter w = new PHPSerializedResponseWriter();
StringWriter buf = new StringWriter();

Document d = new Document();

d.add(new StringField("id", "2", Field.Store.YES));
d.add(new TextField("name", "foo bar", Field.Store.YES));
d.add(new IntField("cost", 5, Field.Store.YES));

SimpleOrderedMap<Object> val = new SimpleOrderedMap<>();
val.add("lucene doc", new Object[]{d});
rsp.add("map", val);

w.write(buf, req, rsp);
System.out.println(buf.toString());
assertEquals("I'm not sure what it is, but it can be handled by php",
"a:1:{s:3:\"map\";a:1:{s:10:\"lucene doc\";a:1:{i:0;a:1:{i:0;a:3:{s:2:\"id\";s:1:\"2\";s:4:\"cost\";s:1:\"5\";s:4:\"name\";a:1:{i:0;s:7:\"foo bar\";}}}}}}",
buf.toString());
req.close();
}
}
Loading