Example #1
0
	static PostingJoinOperatorConfiguration get( value const &v )
	{
		PostingJoinOperatorConfiguration c;
		if( v.type( ) != is_object ) {
			throw bad_value_cast( );
		}		
		c.name = v.get<std::string>( "name" );
		c.description = v.get<std::string>( "description" );
		return c;
	}
Example #2
0
	static MetadataDefiniton get( value const &v )
	{
		MetadataDefiniton m;
		if( v.type( ) != is_object) {
			throw bad_value_cast( );
		}
		m.name = v.get<std::string>( "name" );
		m.type = v.get<std::string>( "type" );
		return m;
	}
Example #3
0
	static DocumentGetRequest get( value const &v )
	{
		DocumentGetRequest d;
		if( v.type( ) != is_object) {
			throw bad_value_cast( );
		}
		// TODO: should we also accept int, float? how can we fall back?
		d.docid = v.get<std::string>( "docid", "" );		
		
		return d;
	}
Example #4
0
	static SummarizerFunctionConfiguration get( value const &v )
	{
		SummarizerFunctionConfiguration c;
		if( v.type( ) != is_object ) {
			throw bad_value_cast( );
		}		
		c.name = v.get<std::string>( "name" );
		c.description = v.get<std::string>( "description" );
		c.parameter = v.get<std::vector<FunctionParameter> >( "parameter" );
		return c;
	}
Example #5
0
	static ServiceConfiguration get( value const &v )
	{
		ServiceConfiguration c;
		if( v.type( ) != is_object ) {
			throw bad_value_cast( );
		}		
		c.weighting_functions = v.get<std::vector<WeightingFunctionConfiguration> >( "weighting_functions", std::vector<WeightingFunctionConfiguration>( ) );
		c.summarizer_functions = v.get<std::vector<SummarizerFunctionConfiguration> >( "summarizer_functions", std::vector<SummarizerFunctionConfiguration>( ) );
		c.posting_join_operators = v.get<std::vector<PostingJoinOperatorConfiguration> >( "posting_join_operators", std::vector<PostingJoinOperatorConfiguration>( ) );
		return c;
	}
Example #6
0
	static StorageConfiguration get( value const &v )
	{
		StorageConfiguration c;
		if( v.type( ) != is_object) {
			throw bad_value_cast( );
		}		
		c.metadata = v.get<std::vector<struct MetadataDefiniton> >( "metadata", std::vector<struct MetadataDefiniton>( ) );
		c.attributes = v.get<std::vector<std::string> >( "attributes", std::vector<std::string>( ) );
		c.types = v.get<std::vector<std::string> >( "types", std::vector<std::string>( ) );
		return c;
	}
Example #7
0
	static std::pair<std::string, strus::NumericVariant> get( value const &v )
	{
		std::pair<std::string, strus::NumericVariant> p;
		
		if( v.type( ) != is_object) {
			throw bad_value_cast( );
		}
		
		p.first = v.get<std::string>( "key" );
		value val = v["value"];
		switch( val.type( ) ) {
			case is_boolean:
				// TODO: really? Do we allow this?
				p.second = ( v.get<bool>( "value" ) ) ? 1 : 0;
				break;
			
			case is_string:
				// TODO: really? Do we allow this?
			case is_number:
				if( is_of_type( val, p.second.variant.Int ) ) {
					p.second = v.get<BOOST_TYPEOF( p.second.variant.Int )>( "value" );
				} else if( is_of_type( val, p.second.variant.UInt ) ) {
					p.second = v.get<BOOST_TYPEOF( p.second.variant.UInt )>( "value" );
				} else if( is_of_type( val, p.second.variant.Float ) ) {
					p.second = v.get<BOOST_TYPEOF( p.second.variant.Float )>( "value" );
				} else {
					throw bad_value_cast( );
				}
				break;
				
			case is_undefined:
			case is_null:
				// TODO: how do we map absence
			case is_object:
			case is_array:	
			default:
				throw bad_value_cast( );
		}
				
		return p;
	}
Example #8
0
	static DocumentInsertRequest get( value const &v )
	{
		DocumentInsertRequest d;
		if( v.type( ) != is_object) {
			throw bad_value_cast( );
		}
		// TODO: should we also accept int, float? how can we fall back?
		d.docid = v.get<std::string>( "docid", "" );
		d.attributes = v.get<std::vector<std::pair<std::string, std::string> > >( "attributes" );
		d.metadata = v.get<std::vector<std::pair<std::string, strus::NumericVariant> > >( "metadata" );
		d.forward = v.get<std::vector<boost::tuple<std::string, std::string, strus::Index> > >( "forward" );
		d.search = v.get<std::vector<boost::tuple<std::string, std::string, strus::Index> > >( "search" );
		return d;
	}
Example #9
0
	static DocumentGetAnswer get( value const &v )
	{
		DocumentGetAnswer a;
		if( v.type( ) != is_object) {
			throw bad_value_cast( );
		}
		a.docno = v.get<strus::Index>( "docno" );
		a.attributes = v.get<std::vector<std::pair<std::string, std::string> > >( "attributes" );
		a.metadata = v.get<std::vector<std::pair<std::string, strus::NumericVariant> > >( "metadata" );
		a.forward = v.get<std::vector<boost::tuple<std::string, std::string, strus::Index> > >( "forward" );
		a.search = v.get<std::vector<boost::tuple<std::string, std::string, strus::Index> > >( "search" );

		return a;
	}
Example #10
0
	static FunctionParameter get( value const &v )
	{
		FunctionParameter p;
		if( v.type( ) != is_object ) {
			throw bad_value_cast( );
		}
		std::string s = v.get<std::string>( "type" );
		if( s.compare( "feature" ) == 0 ) {
			p.type = FUNCTION_TYPE_FEATURE;
		} else if( s.compare( "attribute" ) == 0 ) {
			p.type = FUNCTION_TYPE_ATTRIBUTE;
		} else if( s.compare( "metadata" ) == 0 ) {
			p.type = FUNCTION_TYPE_METADATA;
		} else if( s.compare( "numeric" ) == 0 ) {
			p.type = FUNCTION_TYPE_NUMERIC;
		} else if( s.compare( "string" ) == 0 ) {
			p.type = FUNCTION_TYPE_STRING;
		} else {
			throw bad_value_cast( );
		}
		p.name = v.get<std::string>( "name" );
		p.description = v.get<std::string>( "description" );
		return p;
	}
Example #11
0
	static boost::tuple<std::string, std::string, strus::Index> get( value const &v )
	{
		boost::tuple<std::string, std::string, strus::Index> t;

		if( v.type( ) != is_object) {
			throw bad_value_cast( );
		}
		
		t = boost::make_tuple(
			v.get<std::string>( "type" ),
			v.get<std::string>( "value" ),
			v.get<strus::Index>( "pos" )
		);
				
		return t;
	}
Example #12
0
    void operator()(std::ostream* v)
    {
        if(blob_ == bytea_type) 
        {
            unsigned char *val = (unsigned char*)PQgetvalue(res_, current_, fetch_col_);
            size_t len = 0;

            unsigned char *buf = PQunescapeBytea(val, &len);
            if(!buf)
                throw bad_value_cast();

            BOOST_SCOPE_EXIT((buf)) {
                PQfreemem(buf);
            } BOOST_SCOPE_EXIT_END

            v->write((char *)buf,len);
        }
Example #13
0
	static StorageCreateParameters get( value const &v )
	{
		StorageCreateParameters p;
		if( v.type( ) != is_object) {
			throw bad_value_cast( );
		}
		p.database = v.get<std::string>( "database", DEFAULT_DATABASE );
		p.compression = v.get<bool>( "compression", LEVELDB_DATABASE_DEFAULT_COMPRESSION );
		// TODO: we should introspect them via the database configuration for
		// the specific implementation
		p.cache_size = v.get<size_t>( "cache_size", LEVELDB_DATABASE_DEFAULT_LRU_CACHESIZE );
		p.max_open_files = v.get<size_t>( "max_open_files", LEVELDB_DATABASE_DEFAULT_MAX_OPEN_FILES );
		p.write_buffer_size = v.get<size_t>( "write_buffer_size", LEVELDB_DATABASE_DEFAULT_WRITE_BUFFER_SIZE );
		p.block_size = v.get<size_t>( "block_size", LEVELDB_DATABASE_DEFAULT_BLOCK_SIZE );		
		p.metadata = v.get<std::vector<struct MetadataDefiniton> >( "metadata", std::vector<struct MetadataDefiniton>( ) );
		return p;
	}
Example #14
0
	static void set( value &v, std::pair<std::string, strus::NumericVariant> const &p )
	{
		v.set( "key", p.first );
		switch( p.second.type ) {
			case strus::NumericVariant::Null:
				v.set( "value", cppcms::json::null( ) );
				break;
			
			case strus::NumericVariant::Int:
				v.set( "value", p.second.toint( ) );
				break;
				
			case strus::NumericVariant::UInt:
				v.set( "value", p.second.touint( ) );
				break;
				
			case strus::NumericVariant::Float:
				v.set( "value", p.second.tofloat( ) );
				break;
			
			default:
				throw bad_value_cast( );
		}
	}
Example #15
0
	static void set( value &v, FunctionParameter const &p )
	{
		switch( p.type ) {
			case FUNCTION_TYPE_FEATURE:
				v.set( "type", "feature" );
				break;
			case FUNCTION_TYPE_ATTRIBUTE:
				v.set( "type", "attribute" );
				break;
			case FUNCTION_TYPE_METADATA:
				v.set( "type", "metadata" );
				break;
			case FUNCTION_TYPE_NUMERIC:
				v.set( "type", "numeric" );
				break;
			case FUNCTION_TYPE_STRING:
				v.set( "type", "string" );
				break;
			default:
				throw bad_value_cast( );
		}				
		v.set( "name", p.name );
		v.set( "description", p.description );
	}