Class SolrParams

java.lang.Object
org.apache.solr.common.params.SolrParams
All Implemented Interfaces:
Serializable, Iterable<Map.Entry<String,String[]>>, MapSerializable, MapWriter, NavigableObject, org.noggit.JSONWriter.Writable
Direct Known Subclasses:
DefaultSolrParams, MapSolrParams, ModifiableSolrParams, MultiMapSolrParams, RequiredSolrParams

public abstract class SolrParams extends Object implements Serializable, MapWriter, Iterable<Map.Entry<String,String[]>>
SolrParams is designed to hold parameters to Solr, often from the request coming into Solr. It's basically a MultiMap of String keys to one or more String values. Neither keys nor values may be null. Unlike a general Map/MultiMap, the size is unknown without iterating over each parameter name, if you want to count the different values for a key separately.
See Also:
  • Constructor Details

    • SolrParams

      public SolrParams()
  • Method Details

    • get

      public abstract String get(String param)
      Returns the first String value of a param, or null if not set. To get all, call getParams(String) instead.
    • getParams

      public abstract String[] getParams(String param)
      returns an array of the String values of a param, or null if no mapping for the param exists.
    • getParameterNamesIterator

      public abstract Iterator<String> getParameterNamesIterator()
      Returns an Iterator over the parameter names. If you were to call a getter for this parameter, you should get a non-null value. Since you probably want the value, consider using Java 5 for-each style instead for convenience since a SolrParams implements Iterable.
    • get

      public String get(String param, String def)
      returns the value of the param, or def if not set
    • writeMap

      public void writeMap(MapWriter.EntryWriter ew) throws IOException
      Description copied from interface: MapWriter
      Writes this object's entries out to ew.
      Specified by:
      writeMap in interface MapWriter
      Throws:
      IOException
    • iterator

      public Iterator<Map.Entry<String,String[]>> iterator()
      Returns an Iterator of Map.Entry providing a multi-map view. Treat it as read-only.
      Specified by:
      iterator in interface Iterable<Map.Entry<String,String[]>>
    • stream

      public Stream<Map.Entry<String,String[]>> stream()
      A Stream view over iterator() -- for convenience. Treat it as read-only.
    • required

      public RequiredSolrParams required()
      returns a RequiredSolrParams wrapping this
    • fpname

      protected String fpname(String field, String param)
    • getFieldParam

      public String getFieldParam(String field, String param)
      returns the String value of the field parameter, "f.field.param", or the value for "param" if that is not set.
    • getFieldParam

      public String getFieldParam(String field, String param, String def)
      returns the String value of the field parameter, "f.field.param", or the value for "param" if that is not set. If that is not set, def
    • getFieldParams

      public String[] getFieldParams(String field, String param)
      returns the String values of the field parameter, "f.field.param", or the values for "param" if that is not set.
    • getBool

      public Boolean getBool(String param)
      Returns the Boolean value of the param, or null if not set. Use this method only when you want to be explicit about absence of a value (null) vs the default value false .
      See Also:
    • getPrimitiveBool

      public boolean getPrimitiveBool(String param)
      Returns the boolean value of the param, or false if not set
    • getBool

      public boolean getBool(String param, boolean def)
      Returns the boolean value of the param, or def if not set
    • getFieldBool

      public Boolean getFieldBool(String field, String param)
      Returns the Boolean value of the field param, or the value for param, or null if neither is set. Use this method only when you want to be explicit about absence of a value (null ) vs the default value false.
      See Also:
    • getPrimitiveFieldBool

      public boolean getPrimitiveFieldBool(String field, String param)
      Returns the boolean value of the field param, or the value for param or the default value of boolean - false
    • getFieldBool

      public boolean getFieldBool(String field, String param, boolean def)
      Returns the boolean value of the field param, or the value for param, or def if neither is set.
    • getInt

      public Integer getInt(String param)
      Returns the Integer value of the param, or null if not set Use this method only when you want to be explicit about absence of a value (null) vs the default value for int - zero (0).
      See Also:
    • getPrimitiveInt

      public int getPrimitiveInt(String param)
      Returns int value of the param or default value for int - zero (0) if not set.
    • getInt

      public int getInt(String param, int def)
      Returns the int value of the param, or def if not set
    • getLong

      public Long getLong(String param)
      Returns the Long value of the param, or null if not set Use this method only when you want to be explicit about absence of a value (null) vs the default value zero (0 ).
      See Also:
    • getLong

      public long getLong(String param, long def)
      Returns the long value of the param, or def if not set
    • getFieldInt

      public Integer getFieldInt(String field, String param)
      Use this method only when you want to be explicit about absence of a value (null) vs the default value zero (0).
      Returns:
      The int value of the field param, or the value for param or null if neither is set.
      See Also:
    • getFieldInt

      public int getFieldInt(String field, String param, int def)
      Returns the int value of the field param, or the value for param, or def if neither is set.
    • getFloat

      public Float getFloat(String param)
      Returns the Float value of the param, or null if not set Use this method only when you want to be explicit about absence of a value (null) vs the default value zero (0.0f ).
      See Also:
    • getFloat

      public float getFloat(String param, float def)
      Returns the float value of the param, or def if not set
    • getDouble

      public Double getDouble(String param)
      Returns the Float value of the param, or null if not set Use this method only when you want to be explicit about absence of a value (null) vs the default value zero (0.0d ).
      See Also:
    • getDouble

      public double getDouble(String param, double def)
      Returns the float value of the param, or def if not set
    • getFieldFloat

      public Float getFieldFloat(String field, String param)
      Returns the float value of the field param. Use this method only when you want to be explicit about absence of a value (null) vs the default value zero (0.0f).
      See Also:
    • getPrimitiveFieldFloat

      public float getPrimitiveFieldFloat(String field, String param)
      Returns the float value of the field param or the value for param or the default value for float - zero (0.0f)
    • getFieldFloat

      public float getFieldFloat(String field, String param, float def)
      Returns the float value of the field param, or the value for param, or def if neither is set.
    • getFieldDouble

      public Double getFieldDouble(String field, String param)
      Returns the float value of the field param. Use this method only when you want to be explicit about absence of a value (null) vs the default value zero (0.0d).
      See Also:
    • getFieldDouble

      public double getFieldDouble(String field, String param, double def)
      Returns the float value of the field param, or the value for param, or def if neither is set.
    • wrapDefaults

      public static SolrParams wrapDefaults(SolrParams params, SolrParams defaults)
    • wrapAppended

      public static SolrParams wrapAppended(SolrParams params, SolrParams defaults)
    • toNamedList

      @Deprecated public NamedList<Object> toNamedList()
      Convert this to a NamedList of unique keys with either String or String[] values depending on how many values there are for the parameter.
    • toQueryString

      public String toQueryString()
      Returns this SolrParams as a proper URL encoded string, starting with "?", if not empty.
    • toLocalParamsString

      public String toLocalParamsString()
      Generates a local-params string of the form {! name=value name2=value2}, Protecting (without any quoting or escaping) any values that start with $ (param references).
    • toString

      public String toString()
      Like toQueryString(), but only replacing enough chars so that the URL may be unambiguously pasted back into a browser. This method can be used to properly log query parameters without making them unreadable.

      Characters with a numeric value less than 32 are encoded. &,=,%,+,space are encoded.

      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object obj)
      A SolrParams is equal to another if they have the same keys and values. The order of keys does not matter.
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • of

      public static SolrParams of()
      An empty, immutable SolrParams.
    • of

      public static SolrParams of(String k, String v)
      An immutable SolrParams holding one pair (not null).