I'm having trouble figuring if there is a better way to filter array collection
.
This is my code:
$searchResults = $this->get('app.user.repository')->getUsersBySearchData($searchDetails);
$searchResults->filter(
function($user) use ($searchDetails){
$distance = $this->get('app.distance.calculator')->calculateDistance($user->getCity(), $searchDetails->getCity());
$distanceToTravel = $user->getDistanceToTravel();
if($distance < $distanceToTravel)
return true;
return false;
}
);
This returns all users from $searchResults filtered from already fetched collection.
I need to fetch all users form database whose location is not beyond distance which user enters in his profile and city entered in search form. To determine if that distance is not exceeded i have to calculate distance between location entered in search form to location of user and compare that distance to user profile distance.
Is it possible to do this kind of filtering on database level? I looked into Criteria API but couuldn't figure out how to do it.
Since you use an external module for filtering this is not possible. You should somehow be able to move filtering to database level. Since you need to add support for filtering to different locations I would suggest you store the locations in the database in a way that you can use them for filtering. Simply adding the name of the city will not be enough information.
I would like to suggest that you add longitude (location_longitude) and latitude (location_latitude) of your cities in the database and use this in your SQL query for filtering.
Check also this question for reference
You could also make a custom location mapping inside doctrine for making things work a bit smoother. Check the doctrine documentation chapter Advanced field value conversion using custom mapping types for an example.
This example is explaining a DBAL type a where a location (point) is stored in latitude and longitude values in the database.
Related
I'm quite new to DynamoDB, but have some experience in Cassandra. I'm trying to adapt a pattern I followed in Cassandra, where each column represented a timestamped event, and wondering if it will carry over gracefully into DynamoDB or if I need to change my approach.
My goal is to query a set of documents within a date range by using the milliseconds-since-epoch timestamp as an Attribute name. I'm successfully storing the following as each report is generated with each new report being added under its own column:
{ PartitionKey:customerId,
SortKey:reportName_yyyymm,
'#millis_1#':{'report':doc_1},
'#millis_2#':{'report':doc_2},
. . .
'#millis_n#':{'report':doc_n}
}
My question is, given a millisecond-based date range, and the accompanying Partition and Sort keys, is it possible to query the set of Attributes that fall within that range or must I retrieve all columns for the matching keys and filter them at the client?
Welcome to the most powerful NoSQL database ;)
To kick off with the positive news, there is no way to query out specific attributes. You can project certain attributes in a query. But you would have to write your own logic to determine which attributes or columns should be included in the projected query. To get close to your solution you could use a map attribute inside an item with the milliseconds as a key. But there is another thing you have to be aware of when starting on this path.
There is a maximum total item size of 400KB for each item in DynamoDB, including key and attribute names.(Limits in DynamoDB Items) This means you can only store so many attributes in an item. This is especially true if you intend to put the actual report inside of the attribute. Which I would advise against, also because you will be burning up read capacity units every time you get one attribute out of the whole item. You would be better of putting this data in a separate table with the keys in the map. But truthfully in DynamoDB I would split this whole thing up, just add the milliseconds to the sort key and make every document its own item. That way you can directly query to these items and you can use the "between" where clause to select specific date-time ranges. Please let me you meant something else.
am trying to get the value from db without using serviceHub and vault.but i couldn't. what my logic is, when i pass the country name, it should return the id's(PK)of that country which is in one table.using those id's, it should return the values related to those id's from other table.it could be possible in flow class.but am trying to do in api class where servicehub couldn't import. Please help me out.
Only the node has access to the ServiceHub. The API runs outside of the node in a separate process, so it is limited to interacting with the node via the operations offered by CordaRPCOps.
Either you need to store the data you want to access in a separate database outside of the node, or you need to find some way to programatically log into the node's database from the API, using JDBC as described here: https://docs.corda.net/node-database.html.
I am very much new to riak and I am currently using it with an API. So, let me explain my scenario.
There is an account - say example#riaktest.com created under accounts bucket.
So, on doing
localhost:8098/buckets/accounts/keys?keys=true it returns {{"keys":["example#riaktest.com"]}}
So, i basically have one 'key' with other data fields inside.
Now, I have a functionality that a user can join a particular group. Lets say, 'group1'.
He logs in, joins group1. I give the snowflake generated ID of the account as the index.
Question is:
How do I see a particular key's list of index?
localhost:8098/riak/group/group1 will give me the values and the main account it is tied to.
I am building a social website and I am laying out how the feed will work. I want to use the answer here: How to implement the activity stream in a social network and implement the database design mentioned:
id
user_id (int)
activity_type (tinyint)
source_id (int)
parent_id (int)
parent_type (tinyint)
time (datetime but a smaller type like int would be better)
The problem is I don't know how I would map the source_id based off activity_type. If a user registers, I want the source_id to be the user that registered. If someone creates a group the source_id will be the group. I know I can just use simple IDs without keys I just wanted to know if Symfony had some sort of way to do this built in.
If I fetch the feed and the activity_type is user_register I would like to be able to do this to get the source (user) without running an additional query:
$feedEntity->getSource()->getUsername(); //getSource() being the User entity
And if the source_typeis "user_post":
$feedEntity->getSource()->getMessage(); //getSource() being the UserPost entity
I basically just want to find the best way to store this data and make it the fastest.
Not easy to deal with doctrine and i think it cannot achieved 100% automatically
However, the keyword is table inheritance
http://docs.doctrine-project.org/en/2.0.x/reference/inheritance-mapping.html#single-table-inheritance
I think you could achieve your goal by doing something like this :
You create a discriminator map by the type column of the table which tells doctrine to load this entity a UserSource (for example)
This UserSource can be an own entity (can be inherited from a base class if you want) where you can decide to map the source_id column to the real User Entity
You can use instanceof matching against the namespace of the different entities mapped inside your discriminator map to define different behaviours for the different sources
I am trying to create an index in raven that will (to all intents and purposes) project all comments on all blog-posts that were created by a specific user. At present I have managed a map statement, which only returns the posts that have comments.
from post in docs.Posts
from comment in Hierarchy(post, "Comments")
select new { comment.User, comment.Text }
At the end of this, I will want to page through the comments, so I need to get a flat list of all matching items.
Thanks
What is the problem that you have run to?
You are projecting the comment data out, you need to tell RavenDB to store the fields, but you can now query it just fine.