Problems with using hmset in Predis - php

I have a problem with using $predis->hmset(). What parameters i need use?
I try many variants, but without success.
$this->client()->hmset( $this->name, array( 1 => 3 ))
$this->client()->hmset( $this->name, array( 1, 3 ))

From the predis examples:
// Prepare an hash with some fields and their respective values.
$client->hmset('metavars', array('foo' => 'bar', 'hoge' => 'piyo', 'lol' => 'wut'));
Perhaps, make sure you use strings and not integers ...

Related

PHP SOAP - Passing parameters with same name

I'm calling an API using php and SOAP.
some parts of the request are like:
<fin:Customer>
<fin1:Address>
<fin1:City>City</fin1:City>
<fin1:Country>CA</fin1:Country>
</fin1:Address>
<fin:Customer>
Which is easy to do with arrays:
'Customer' => array(
'Address' => array (
'City' => $City,
'Country' => $Country,
),
But my challenge is for this part:
<fin:Criterions>
<fin:Criterion name="VALX">17</fin:Criterion>
<fin:Criterion name="VALOP">1</fin:Criterion>
<fin:Criterion name="VALLP">10</fin:Criterion>
<fin:Criterion name="TMS">3</fin:Criterion>
Because all tags have the same name, and they also have a name parameter and a value.
How can I pass that to SOAP API?
Is it possible to use arrays?
Thanks in advance!
The easiest way to construct a request, send it and handle the response is to use a WSDL to PHP generator as it'll normally generate each class for every parameter you need to send (in addition to the response objects and the operations classes)
Knowing this, you'll be able to easily see how to pass these "duplicated" tags as it is certainly an array of object that you must pass,
Try the PackageGenerator project which should work fine,
Solution:
'Criterions' => array(
'Criterion' => array(
array('name'=> 'VALX' , '_'=> '17' ),
array('name'=> 'VALOP' , '_'=> '1' ),
array('name'=> 'VALLP' , '_'=> '10' ),
array('name'=> 'TMS' , '_'=> '3' )
));
Be sure to use underscore ('_'), if other values (e.g. val, value, etc) didn't work.
Might save someone's time and effort.

Cakephp 2 update multiple records

i'm newbie in cakephp and i trying to update multiple rows in one transaction like:
$Model->saveMany($data, array('deep' => true));
... And the structure of the $data array is:
$data = array(
(int) 1 => array( 'Item' => array('id' => 2, 'name' => 'Name 1') ),
(int) 2 => array( 'Item' => array('id' => 3, 'name' => 'Name 2') ),
);
I Already tried with saveAll instruction and without deep parameter but nothing :( .... what's wrong?
Thanks for the help :)
The problem was that it had a required field in the validation that, although it was not compromised in the update, anyway it had to be passed in command
Thank you all!!
You can use this following code to insert data in Cake Php,
$this->request->data = Hash::insert($this->request->data);

PHP::MongoCollection->aggregate() Failures

I have a MongoDB query that is verified as 100% working ( Using MongoHub I have connected to the Replica Set and run the query and received results ), but when converting this query to PHP and attempting to run it through MongoCollection->aggregate(), I fail to get a return/result of any kind whatsoever ... not even an error.
Here is the query, as put into a PHP Array ( as MongoCollection requires ):
$query = array(
'$match' => array(
'$and' => array(
'make' => $props[0],
'model' => $props[1],
'makeYear' => (integer)$props[2],
'status' => 'Active'
)
),
'$group' => array(
'_id' => null,
'marketTotal' => array('$sum' => '$price'),
'count' => array('$sum' => 1)
)
);
The code to run the query is a simple one-liner calling aggregate.
As I don't get errors ... or a log showing any sort of error ... I'm kind of at a total loss here. Is anyone familiar with using PHP w/ MongoDB able to see what I might be doing wrong?
Turns out I was simply missing a layer of arrays ... wrapping each piece of the '$and' array in its own array ... so array('make' => $props[0]), etc ... made it work.
Fun stuff. MongoDB queries are easy. Translating them into PHP-compatible arrays is apparently very difficult and requires a lot of guesswork because it's not 1-to-1

understanding ElasticSearch routing

I am trying to use the elasticsearch routing mapping to speed up some queries, but I am not getting the expected result set (not worried about the query performance just yet)
I am using Elastic to set up my mapping:
$index->create(array('number_of_shards' => 4,
'number_of_replicas' => 1,
'mappings'=>array("country"=>array("_routing"=>array("path"=>"countrycode"))),
'analysis' => array(
'analyzer' => array(
'indexAnalyzer' => array(
'type' => 'keyword',
'tokenizer' => 'nGram',
'filter' => array('shingle')
),
'searchAnalyzer' => array(
'type' => 'keyword',
'tokenizer' => 'nGram',
'filter' => array('shingle')
)
)
) ), true);
If I understand correctly, what should happen is that each result should now have a field called "countrycode" with the value of "country" in it.
The results of _mapping look like this:
{"postcode":
{"postcode":
{"properties":
{
"area1":{"type":"string"},
"area2":{"type":"string"},
"city":{"type":"string",
"include_in_all":true},
"country":{"type":"string"},
"country_iso":{"type":"string"},
"country_name":{"type":"string"},
"id":{"type":"string"},
"lat":{"type":"string"},
"lng":{"type":"string"},
"location":{"type":"geo_point"},
"region1":{"type":"string"},
"region2":{"type":"string"},
"region3":{"type":"string"},
"region4":{"type":"string"},
"state_abr":{"type":"string"},
"zip":{"type":"string","include_in_all":true}}},
"country":{
"_routing":{"path":"countrycode"},
"properties":{}
}
}
}
Once all the data is in the index if I run this command:
http://localhost:9200/postcode/_search?pretty=true&q=country:au
it responds with 15740 total items
what I was expecting is that if I run the query like this:
http://localhost:9200/postcode/_search?routing=au&pretty=true
Then I was expecting it to respond with 15740 results
instead it returns 120617 results, which includes results where country is != au
I did note that the number of shards in the results went from 4 to 1, so something is working.
I was expecting that in the result set there would be an item called "countrycode" (from the rounting mapping) which there isn't
So I thought at this point that my understand of routing was wrong. Perhaps all the routing does is tell it which shard to look in but not what to look for? in other words if other country codes happen to also land in that particular shard, the way those queries are written will just bring back all records in that shard?
So I tried the query again, this time adding some info to it.
http://localhost:9200/postcode/_search?routing=AU&pretty=true&q=country:AU
I thought by doing this it would force the query into giving me just the AU place names, but this time it gave me only 3936 results
So I Am not quite sure what I have done wrong, the examples I have read show the queries changing from needing a filter, to just using match_all{} which I would have thought would only being back ones matching the au country code.
Thanks for your help in getting this to work correctly.
Almost have this working, it now gives me the correct number of results in a single shard, however the create index is not working quite right, it ignores my number_of_shards setting, and possibly other ones too
$index = $client->getIndex($indexname);
$index->create(array('mappings'=>array("$indexname"=>array("_routing"=>array("required"=>true))),'number_of_shards' => 6,
'number_of_replicas' => 1,
'analysis' => array(
'analyzer' => array(
'indexAnalyzer' => array(
'type' => 'keyword',
'tokenizer' => 'nGram',
'filter' => array('shingle')
),
'searchAnalyzer' => array(
'type' => 'keyword',
'tokenizer' => 'nGram',
'filter' => array('shingle')
)
)
) ), true);
I can at least help you with more info on where to look:
http://localhost:9200/postcode/_search?routing=au&pretty=true
That query does indeed translate into "give me all documents on the shard where documents for country:AU should be sent."
Routing is just that, routing ... it doesn't filter your results for you.
Also i noticed you're mixing your "au"s and your "AU"s .. that might mix things up too.
You should try setting required on your routing element to true, to make sure that your documents are actually stored with routing information when being indexed.
Actually to make sure your documents are indexed with proper routing explicitly set the route to lowercase(countrycode) when indexing documents. See if that helps any.
For more information try reading this blog post:
http://www.elasticsearch.org/blog/customizing-your-document-routing/
Hope this helps :)

Using multiple modifier operations in a single update in PHP with MongoDB?

Is it possible to use multipule modifier operations within a single update in PHP with MongoDB?
For example, if I created the following document:
$doc = array(
'one' => 1,
'tags' => array(),
);
And then wanted to add another field ('new') and add an element to the 'tags' array, I could use the following two lines:
$collection->update(array('_id'=>$doc['_id']), array('$set' => array('new'=>'value')));
and
$collection->update(array("_id" => $doc['_id']), array('$addToSet' => array('tags'=>'my tag')));
Does anyone know it's possible to do both of these two operations in one 'update' command?
Thanks,
Neil
I haven't used mongo in a while, but I believe you should be able to:
$collection->update(array('_id'=>$doc['_id']), array(
'$set' => array('new'=>'value'),
'$addToSet' => array('tags'=>'my tag')
));

Categories