Solr
  1. Solr
  2. SOLR-446

TextResponseWriter should be able to work with SolrDocument and SolrDocumentList

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.3
    • Fix Version/s: 1.3
    • Component/s: None
    • Labels:
      None

      Description

      ResponseWriters should be able to write SolrDocuments the same way they write Documents. This will be useful for SOLR-303 or other RequestHandlres that modify a SolrDocument and return the result.

        Issue Links

          Activity

          Hide
          Ryan McKinley added a comment -

          code extracted from SOLR-303 and added a small interface to reuse some code

          Show
          Ryan McKinley added a comment - code extracted from SOLR-303 and added a small interface to reuse some code
          Hide
          Yonik Seeley added a comment -

          looks good on a quick scan, go for it!

          Show
          Yonik Seeley added a comment - looks good on a quick scan, go for it!
          Hide
          Hoss Man added a comment -

          sorry, i just noticed something ... in commit r610156 the new "writeDoc(String name, SolrDocument doc, Set<String> returnFields, boolean includeScore)" methods all seem to be ignoring the "returnFields" param completely.

          doesn't that mean any handler using SolrDocument's won't respect the "fl" param?

          Show
          Hoss Man added a comment - sorry, i just noticed something ... in commit r610156 the new "writeDoc(String name, SolrDocument doc, Set<String> returnFields, boolean includeScore)" methods all seem to be ignoring the "returnFields" param completely. doesn't that mean any handler using SolrDocument's won't respect the "fl" param?
          Hide
          Ryan McKinley added a comment -

          good catch Hoss!

          Looking at it again, the 'score' bit is weird too – you would get duplicate 'score' fields if you chained this (i think)

              if (includeScore) {
                writeVal("score", doc.getFirstValue("score"));
              }
          

          perhaps it should be:

          Index: src/java/org/apache/solr/request/XMLWriter.java
          ===================================================================
          --- src/java/org/apache/solr/request/XMLWriter.java     (revision 610424)
          +++ src/java/org/apache/solr/request/XMLWriter.java     (working copy)
          @@ -342,11 +342,14 @@
               startTag("doc", name, false);
               incLevel();
          
          -    if (includeScore) {
          -      writeVal("score", doc.getFirstValue("score"));
          +    if (includeScore && returnFields != null ) {
          +      returnFields.add( "score" );
               }
          
               for (String fname : doc.getFieldNames()) {
          +      if (returnFields!=null && !returnFields.contains(fname)) {
          +        continue;
          +      }
                 Object val = doc.getFieldValue(fname);
          
                 if (val instanceof Collection) {
          
          Show
          Ryan McKinley added a comment - good catch Hoss! Looking at it again, the 'score' bit is weird too – you would get duplicate 'score' fields if you chained this (i think) if (includeScore) { writeVal( "score" , doc.getFirstValue( "score" )); } perhaps it should be: Index: src/java/org/apache/solr/request/XMLWriter.java =================================================================== --- src/java/org/apache/solr/request/XMLWriter.java (revision 610424) +++ src/java/org/apache/solr/request/XMLWriter.java (working copy) @@ -342,11 +342,14 @@ startTag( "doc" , name, false ); incLevel(); - if (includeScore) { - writeVal( "score" , doc.getFirstValue( "score" )); + if (includeScore && returnFields != null ) { + returnFields.add( "score" ); } for ( String fname : doc.getFieldNames()) { + if (returnFields!= null && !returnFields.contains(fname)) { + continue ; + } Object val = doc.getFieldValue(fname); if (val instanceof Collection) {

            People

            • Assignee:
              Ryan McKinley
              Reporter:
              Ryan McKinley
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development