Package org.apache.solr.request

Examples of org.apache.solr.request.SolrParams


     
      MultipartRequestParser multipart = new MultipartRequestParser( 1000000 );
      RawRequestParser raw = new RawRequestParser();
      StandardRequestParser standard = new StandardRequestParser( multipart, raw );
     
      SolrParams p = standard.parseParamsAndFillStreams( request, streams );
     
      assertEquals( "contentType: "+contentType, "hello", p.get("q") );
    }
  }
View Full Code Here


   * Check the request parameters and decide if it should commit or optimize.
   * If it does, it will check parameters for "waitFlush" and "waitSearcher"
   */
  public static boolean handleCommit( SolrQueryRequest req, SolrQueryResponse rsp, boolean force ) throws IOException
  {
    SolrParams params = req.getParams();
    if( params == null ) {
      params = new MapSolrParams( new HashMap<String, String>() );
    }
   
    boolean optimize = params.getBool( UpdateParams.OPTIMIZE, false );
    boolean commit   = params.getBool( UpdateParams.COMMIT,   false );
   
    if( optimize || commit || force ) {
      CommitUpdateCommand cmd = new CommitUpdateCommand( optimize );
      cmd.waitFlush    = params.getBool( UpdateParams.WAIT_FLUSH,    cmd.waitFlush    );
      cmd.waitSearcher = params.getBool( UpdateParams.WAIT_SEARCHER, cmd.waitSearcher );
      req.getCore().getUpdateHandler().commit( cmd );
     
      // Lets wait till after solr1.2 to define consistent output format
      //if( optimize ) {
      //  rsp.add( "optimize", true );
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( pint   , required.getFieldInt( "fff",  "int"      ) );
   
    // 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"      ) );
    assertEquals( new Integer(123)      , defaults.getInt"dint"     ) );
    // in params, overriding defaults
    assertEquals( pint                  , defaults.getInt(   "int"      ) );
    // in neither params nor defaults
    assertNull( defaults.get( "asagdsaga" ) );
  }
View Full Code Here

   *
   */
  public String request( String pathAndParams, String body ) throws Exception
  {
    String path = null;
    SolrParams params = null;
    int idx = pathAndParams.indexOf( '?' );
    if( idx > 0 ) {
      path = pathAndParams.substring( 0, idx );
      params = SolrRequestParsers.parseQueryString( pathAndParams.substring(idx+1) );
    }
    else {
      path= pathAndParams;
      params = new MapSolrParams( new HashMap<String, String>() );
    }
   
    // Extract the handler from the path or params
    SolrRequestHandler handler = core.getRequestHandler( path );
    if( handler == null ) {
      if( "/select".equals( path ) || "/select/".equalsIgnoreCase( path) ) {
        String qt = params.get( SolrParams.QT );
        handler = core.getRequestHandler( qt );
        if( handler == null ) {
          throw new SolrException( SolrException.ErrorCode.BAD_REQUEST, "unknown handler: "+qt);
        }
      }
View Full Code Here

   
    // TODO -- in the future, we could pick a different parser based on the request
   
    // Pick the parer from the request...
    ArrayList<ContentStream> streams = new ArrayList<ContentStream>(1);
    SolrParams params = parser.parseParamsAndFillStreams( req, streams );
    SolrQueryRequest sreq = buildRequestFrom( params, streams );

    // Handlers and loggin will want to know the path. If it contains a ':'
    // the handler could use it for RESTfull URLs
    sreq.getContext().put( "path", path );
View Full Code Here

TOP

Related Classes of org.apache.solr.request.SolrParams

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.