Solr
  1. Solr
  2. SOLR-928

SolrDocument/SolrInputDocument could extend/implement Map<String,Object>

    Details

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

      Description

      The existing SolrDocument and SolrInputDocuments are backed by Map<String,Object>, however the Map interface is not available to end users.

      Exposing the Map<String,Object> interface enables users to automatically plug into existing code that support Map<>. In particular many GUI "bean" editors and viewers that support Map<> out of the box.

      1. SOLR-928-SolrDocument-Map.patch
        5 kB
        Ryan McKinley
      2. SOLR-928-SolrDocument-Map.patch
        8 kB
        Ryan McKinley

        Activity

        Hide
        Ryan McKinley added a comment -

        For background – I know we kept the Map implementation hidden since I wanted the option to switch various implementations for slightly different behavior (TreeMap, HashMap, LinkedHashMap).

        We could either extend on of the Map implementation directly or implement Map and wrap each call.

        In practice, it seems unlikely we will change the underlying implementation, so i think the cleaner option is to just extend HashMap or LinkedHashMap.

        Show
        Ryan McKinley added a comment - For background – I know we kept the Map implementation hidden since I wanted the option to switch various implementations for slightly different behavior (TreeMap, HashMap, LinkedHashMap). We could either extend on of the Map implementation directly or implement Map and wrap each call. In practice, it seems unlikely we will change the underlying implementation, so i think the cleaner option is to just extend HashMap or LinkedHashMap.
        Hide
        Ryan McKinley added a comment -

        Here is a patch that has each class extend LinkedHashMap<String,Object>

        In general, most of the internal changes look like this:

        public SolrInputField getField( String field )
        {
        -   return _fields.get( field );
        +   return get( field );
        }
        
        Show
        Ryan McKinley added a comment - Here is a patch that has each class extend LinkedHashMap<String,Object> In general, most of the internal changes look like this: public SolrInputField getField( String field ) { - return _fields.get( field ); + return get( field ); }
        Hide
        Erik Hatcher added a comment -

        you're a saint! thank you thank you thank you.

        Show
        Erik Hatcher added a comment - you're a saint! thank you thank you thank you.
        Hide
        Hoss Man added a comment -

        We could either extend on of the Map implementation directly or implement Map and wrap each call.

        I would prefer implementing the interface via composition instead of inheritance ... even if we don't anticipate ever changing he underlying datastructure there's no reason to lock ourselves into a contract for no reason.

        Show
        Hoss Man added a comment - We could either extend on of the Map implementation directly or implement Map and wrap each call. I would prefer implementing the interface via composition instead of inheritance ... even if we don't anticipate ever changing he underlying datastructure there's no reason to lock ourselves into a contract for no reason.
        Hide
        Ryan McKinley added a comment -

        Here is a new patch where Solr

        {Input}

        Document implements Map<String,Object> rather then extends

        for each function it calls something like:

        +  @Override
        +  public Set<String> keySet() {
        +    return _fields.keySet();
        +  }
        
        Show
        Ryan McKinley added a comment - Here is a new patch where Solr {Input} Document implements Map<String,Object> rather then extends for each function it calls something like: + @Override + public Set< String > keySet() { + return _fields.keySet(); + }
        Hide
        Ryan McKinley added a comment -

        This makes the class description look like this:

        public class SolrDocument implements Map<String,Object>, Iterable<Map.Entry<String, Object>>, Serializable
        
        public class SolrInputDocument implements Map<String,SolrInputField>, Iterable<SolrInputField>, Serializable
        
        Show
        Ryan McKinley added a comment - This makes the class description look like this: public class SolrDocument implements Map< String , Object >, Iterable<Map.Entry< String , Object >>, Serializable public class SolrInputDocument implements Map< String ,SolrInputField>, Iterable<SolrInputField>, Serializable
        Hide
        Ryan McKinley added a comment -

        any other thoughts on this?

        I'd like to commit soon...

        Show
        Ryan McKinley added a comment - any other thoughts on this? I'd like to commit soon...
        Hide
        Grant Ingersoll added a comment -

        Bulk close Solr 1.4 issues

        Show
        Grant Ingersoll added a comment - Bulk close Solr 1.4 issues

          People

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

            Dates

            • Created:
              Updated:
              Resolved:

              Development