Package org.apache.solr.common.params

Examples of org.apache.solr.common.params.MapSolrParams


      assertU(commit());
     
      Map<String,String> args = new HashMap<String, String>();
      args.put( CommonParams.Q, "text_en:simple" );
      args.put( "indent", "true" );
      SolrQueryRequest req = new LocalSolrQueryRequest( core, new MapSolrParams( args) );
     
      assertQ("Make sure they got in", req
              ,"//*[@numFound='1']"
              ,"//result/doc[1]/int[@name='id'][.='10']"
              );
     
      args = new HashMap<String, String>();
      args.put( CommonParams.Q, "highlight:simple" );
      args.put( "indent", "true" );
      req = new LocalSolrQueryRequest( core, new MapSolrParams( args) );
      assertQ("dynamic source", req
              ,"//*[@numFound='1']"
              ,"//result/doc[1]/int[@name='id'][.='10']"
              ,"//result/doc[1]/arr[@name='highlight']/str[.='this is a simple test of ']"
              );

      args = new HashMap<String, String>();
      args.put( CommonParams.Q, "text_en:functionality" );
      args.put( "indent", "true" );
      req = new LocalSolrQueryRequest( core, new MapSolrParams( args) );
      assertQ("Make sure they got in", req
              ,"//*[@numFound='1']");
     
      args = new HashMap<String, String>();
      args.put( CommonParams.Q, "highlight:functionality" );
      args.put( "indent", "true" );
      req = new LocalSolrQueryRequest( core, new MapSolrParams( args) );
      assertQ("dynamic source", req
              ,"//*[@numFound='0']");
    }
View Full Code Here


    assertU(commit());
   
    Map<String,String> args = new HashMap<String, String>();
    args.put( CommonParams.Q, "title:test" );
    args.put( "indent", "true" );
    SolrQueryRequest req = new LocalSolrQueryRequest( core, new MapSolrParams( args) );
   
    assertQ("Make sure they got in", req
            ,"//*[@numFound='1']"
            ,"//result/doc[1]/int[@name='id'][.='10']"
            );
   
    args = new HashMap<String, String>();
    args.put( CommonParams.Q, "aaa_dynamic:aaa" );
    args.put( "indent", "true" );
    req = new LocalSolrQueryRequest( core, new MapSolrParams( args) );
    assertQ("dynamic source", req
            ,"//*[@numFound='1']"
            ,"//result/doc[1]/int[@name='id'][.='10']"
            );

    args = new HashMap<String, String>();
    args.put( CommonParams.Q, "dynamic_aaa:aaa" );
    args.put( "indent", "true" );
    req = new LocalSolrQueryRequest( core, new MapSolrParams( args) );
    assertQ("dynamic destination", req
            ,"//*[@numFound='1']"
            ,"//result/doc[1]/int[@name='id'][.='10']"
            );
    clearIndex();
View Full Code Here

      val = txt.substring(start);
      localParams.put(V, val);
    } else {
      // localParams.put(VAL_EXPLICIT, "true");
    }
    return new MapSolrParams(localParams);
  }
View Full Code Here

*/
public class PointType extends CoordinateFieldType implements SpatialQueryable {

  @Override
  protected void init(IndexSchema schema, Map<String, String> args) {
    SolrParams p = new MapSolrParams(args);
    dimension = p.getInt(DIMENSION, DEFAULT_DIMENSION);
    if (dimension < 1) {
      throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,
              "The dimension must be > 0: " + dimension);
    }
    args.remove(DIMENSION);
View Full Code Here

        // use the remainder of the string as the value
        valFollowedParams = true;
        val = qstr.substring(localParamsEnd);
        localMap.put(QueryParsing.V, val);
      }
      localParams = new MapSolrParams(localMap);
    }


    String type;
   
View Full Code Here

    assertEquals(p.getInt("i").intValue(), 555);
    assertEquals(p.getInt("i",5), 555);
    assertEquals(p.getInt("iii",5), 5);
    assertEquals(p.getFieldParam("field1","i"), "555");

    req.setParams(new DefaultSolrParams(p, new MapSolrParams(m)));
    p = req.getParams();
    assertEquals(req.getOriginalParams().get("s"), "bbb");
    assertEquals(p.get("i"), "555");
    assertEquals(p.getInt("i").intValue(), 555);
    assertEquals(p.getInt("i",5), 555);
View Full Code Here

    assertU(commit());
   
    Map<String,String> args = new HashMap<String, String>();
    args.put( CommonParams.Q, "title:test" );
    args.put( "indent", "true" );
    SolrQueryRequest req = new LocalSolrQueryRequest( core, new MapSolrParams( args) );
   
   
    assertQ("Make sure they got in", req
            ,"//*[@numFound='3']"
            );
View Full Code Here

    pmap.put( "f.fl.int"   , "100"      );
    pmap.put( "f.fl.float" , "10.6"     );
    pmap.put( "f.bad.bool" , "notbool"  );
    pmap.put( "f.bad.int"  , "notint"   );
    pmap.put( "f.bad.float", "notfloat" );
    final SolrParams params = new MapSolrParams( pmap );
   
    // Test the string values we put in directly
    assertEquals"string"   , params.get( "str"       ) );
    assertEquals"true"     , params.get( "bool"      ) );
    assertEquals"100"      , params.get( "int"       ) );
    assertEquals"10.6"     , params.get( "float"     ) );
    assertEquals"string"   , params.get( "f.fl.str"    ) );
    assertEquals"true"     , params.get( "f.fl.bool"   ) );
    assertEquals"100"      , params.get( "f.fl.int"    ) );
    assertEquals"10.6"     , params.get( "f.fl.float"  ) );
    assertEquals"notbool"  , params.get( "f.bad.bool"  ) );
    assertEquals"notint"   , params.get( "f.bad.int"   ) );
    assertEquals"notfloat" , params.get( "f.bad.float" ) );
   
    final String  pstr = "string";
    final Boolean pbool = Boolean.TRUE;
    final Integer pint = new Integer( 100 );
    final Float   pfloat = new Float( 10.6f );
   
    // Make sure they parse ok
    assertEquals( pstr   , params.get(      "str"      ) );
    assertEquals( pbool  , params.getBool"bool"     ) );
    assertEquals( pint   , params.getInt(   "int"      ) );
    assertEquals( pfloat , params.getFloat( "float"    ) );
    assertEquals( pbool  , params.getBool"f.fl.bool"  ) );
    assertEquals( pint   , params.getInt(   "f.fl.int"   ) );
    assertEquals( pfloat , params.getFloat( "f.fl.float" ) );
    assertEquals( pstr   , params.getFieldParam( "fl", "str"  ) );
    assertEquals( pbool  , params.getFieldBool"fl", "bool" ) );
    assertEquals( pint   , params.getFieldInt(   "fl", "int"  ) );
    assertEquals( pfloat , params.getFieldFloat( "fl", "float" ) );
   
    // Test field defaulting (fall through to non-field-specific value)
    assertEquals( pint   , params.getFieldInt( "fff""int"      ) );
   
    // test boolean parsing
    for( int i=0; i<3; i++ ) {
      // Must use Boolean rather than boolean reference value to prevent
      // auto-unboxing ambiguity
      assertEquals( Boolean.TRUE,  params.getBool( "true-"+i  ) );
      assertEquals( Boolean.FALSE, params.getBool( "false-"+i ) );
    }
   
    // Malformed params: These should throw a 400
    assertEquals( 400, getReturnCode( new Runnable() { public void run() { params.getInt(   "f.bad.int" ); } } ) );
    assertEquals( 400, getReturnCode( new Runnable() { public void run() { params.getBool"f.bad.bool" ); } } ) );
    assertEquals( 400, getReturnCode( new Runnable() { public void run() { params.getFloat( "f.bad.float" ); } } ) );
   
    // Ask for params that arent there
    assertNull( params.get( "asagdsaga" ) );
    assertNull( params.getBool( "asagdsaga" ) );
    assertNull( params.getInt( "asagdsaga" ) );
    assertNull( params.getFloat( "asagdsaga" ) );
   
    // Get things with defaults
    assertEquals( pstr                  , params.get(          "xxx", pstr   ) );
    assertEquals( pbool.booleanValue()  , params.getBool(      "xxx", pbool   ) );
    assertEquals( pint.intValue()       , params.getInt(       "xxx", pint   ) );
    assertEquals( pfloat.floatValue()   , params.getFloat(     "xxx", pfloat  ) );
    assertEquals( pbool.booleanValue()  , params.getFieldBool( "xxx", "bool", pbool ) );
    assertEquals( pint.intValue()       , params.getFieldInt"xxx", "int", pint  ) );
    assertEquals( pfloat.floatValue()   , params.getFieldFloat("xxx", "float", pfloat  ) );
    assertEquals( pstr                  , params.getFieldParam("xxx", "str", pstr  ) );

    // Required params testing uses decorator
    final SolrParams required = params.required();
   
    // Required params which are present should test same as above
    assertEquals( pstr   , required.get(      "str"      ) );
    assertEquals( pbool  , required.getBool"bool"     ) );
    assertEquals( pint   , required.getInt(   "int"      ) );
    assertEquals( pfloat , required.getFloat( "float"    ) );
   
    // field value present
    assertEquals( pbool  , required.getFieldBool"fl", "bool" ) );
    // field defaulting (fall through to non-field-specific value)
    assertEquals( pstr   , required.getFieldParams("fakefield", "str")[0] );
    assertEquals( pstr   , required.getFieldParam( "fakefield", "str"   ) );
    assertEquals( pbool  , required.getFieldBool"fakefield", "bool"  ) );
    assertEquals( pint   , required.getFieldInt(   "fakefield", "int"   ) );
    assertEquals( pfloat , required.getFieldFloat( "fakefield", "float" ) );
   
    // Required params which are missing: These should throw a 400
    assertEquals( 400, getReturnCode( new Runnable() { public void run() { required.get( "aaaa" ); } } ) );
    assertEquals( 400, getReturnCode( new Runnable() { public void run() { required.getInt(   "f.bad.int" ); } } ) );
    assertEquals( 400, getReturnCode( new Runnable() { public void run() { required.getBool"f.bad.bool" ); } } ) );
    assertEquals( 400, getReturnCode( new Runnable() { public void run() { required.getFloat( "f.bad.float" ); } } ) );
    assertEquals( 400, getReturnCode( new Runnable() { public void run() { required.getInt(   "aaa" ); } } ) );
    assertEquals( 400, getReturnCode( new Runnable() { public void run() { required.getBool"aaa" ); } } ) );
    assertEquals( 400, getReturnCode( new Runnable() { public void run() { required.getFloat( "aaa" ); } } ) );
    assertEquals( 400, getReturnCode( new Runnable() { public void run() { params.getFieldBool"bad", "bool" ); } } ) );
    assertEquals( 400, getReturnCode( new Runnable() { public void run() { params.getFieldInt(   "bad", "int"  ); } } ) );

    // Fields with default use their parent value:
    assertEquals(
        params.get(   "aaaa", "str" ),
        required.get( "aaaa", "str" ) );
    assertEquals(
        params.getInt(   "f.bad.nnnn", pint ),
        required.getInt( "f.bad.nnnn", pint ) );
   
    // Check default SolrParams
    Map<String,String> dmap = new HashMap<String, String>();
    // these are not defined in params
    dmap.put( "dstr"               , "default"   );
    dmap.put( "dint"               , "123"       );
    // these are defined in params
    dmap.put( "int"                , "456"       );
    SolrParams defaults = new DefaultSolrParams( params, new MapSolrParams( dmap ) );
 
    // in params, not in default
    assertEquals( pstr                  , defaults.get( "str"      ) );
    // in default, not in params
    assertEquals( "default"             , defaults.get( "dstr"      ) );
View Full Code Here

    args.put( CommonParams.Q, query );
    args.put( CommonParams.QT, "/elevate" );
    args.put( CommonParams.FL, "id,score" );
    args.put( "indent", "true" );
    //args.put( CommonParams.FL, "id,title,score" );
    SolrQueryRequest req = new LocalSolrQueryRequest( h.getCore(), new MapSolrParams( args) );
    IndexReader reader = req.getSearcher().getReader();
    QueryElevationComponent booster = (QueryElevationComponent)req.getCore().getSearchComponent( "elevate" );

    assertQ("Make sure standard sort works as expected", req
            ,"//*[@numFound='3']"
 
View Full Code Here

    SolrCore core = h.getCore();
   
    XmlUpdateRequestHandler handler = new XmlUpdateRequestHandler();
    handler.init( null );
   
    MapSolrParams params = new MapSolrParams( new HashMap<String, String>() );
    params.getMap().put(UpdateParams.UPDATE_CHAIN_DEPRECATED, "nonexistant");

    // Add a single document
    SolrQueryResponse rsp = new SolrQueryResponse();
    SolrQueryRequestBase req = new SolrQueryRequestBase( core, params ) {};
   
    // First check that the old param behaves as it should
    try {
      handler.handleRequestBody(req, rsp);
      assertFalse("Faulty update.processor parameter (deprecated but should work) not causing an error - i.e. it is not detected", true);
    } catch (Exception e) {
      assertEquals("Got wrong exception while testing update.chain", e.getMessage(), "unknown UpdateRequestProcessorChain: nonexistant");
    }
   
    // Then check that the new param behaves correctly
    params.getMap().remove(UpdateParams.UPDATE_CHAIN_DEPRECATED);
    params.getMap().put(UpdateParams.UPDATE_CHAIN, "nonexistant");   
    req.setParams(params);
    try {
      handler.handleRequestBody(req, rsp);
      assertFalse("Faulty update.chain parameter not causing an error - i.e. it is not detected", true);
    } catch (Exception e) {
View Full Code Here

TOP

Related Classes of org.apache.solr.common.params.MapSolrParams

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.