MongoID: Group and Count - mongodb

Supposing I have a model Post, wich contains only the field desc.
The user can use hashtags, like #rails inside any posts...
How can I list and count the hashtags used, for example, in the last 10 days?
I'm do not know much about mongodb, but I see that I could use something called map_reduce.. have no idea why/how.
Thanks in advance.

You are right...this can be solved using mad/reduce function...
try this or this gem if you dont want to think a lot lol
https://github.com/jcoene/mongoid-mapreduce

Related

Select query for search with 2 or more words without double quotes against more than one field in solr

Please refer My previous question .
With respect to the this answer for my question, I could do with one filed.
I Could not able to do with multiple fields.
http://$solr_host:8983/solr/magazines/select&q=sport+education&df=title&q.op=OR - this is working for one field. How can I do it for multiple field.
What is the right way to achieve my objective. Thank you in advance.
Use Dismax/eDismax with qf (Query Fields) Parameter.
example:
http://$solr_host:8983/solr/magazines/select&q=sport+education&defType=edismax&qf=title name&q.op=OR
Check this here

How to query from ListColumn[String] in cassandra using phantom

I am new to cassandra (started learning on my own interest few days back) and looking for help for the below problem.
I have a Cassandra table "User" and a ListColumn "interests extends ListColumn[String]".
Now, I want to fetch all users with an interest, say "playing".
like: select from user where interests.contains("playing")!
I scanned through the ListColumn api but not able to find any. Also, searched in google but no such helpful posts.
Any help guys please... Thanks in Advance :)
So there is contains among operators and here is an example how to use it. It looks like that it should work as any other operator, so just go for database.userTable.select.where(_.interests contains "playing").fetch() - of course, depending on your conventions.
This is possible with a secondary index on a collection column, which only works with a Set column, and not with a List.
Bottom line:
object interests extends SetColumn[String](this) with Index[Set[String]]
And then you can execute the following:
select.where(_.interests contains "test").fetch()
You can also use multiple restrictions if you allow filtering.
select.where(_.interests contains "test")
.and(_.interests contains "test2")
.allowFiltering()
.fetch()
The above will only match if both interests are found in a record.

SharePoint REST API result not containing lookup field

I have a simple rest call on a lookup field:
_api/web/lists/getbytitle('Planning')/items(1)/?$select=Surveyor
however this returns 400, i know the field is definitely in the Planning list and it is a site column,
I do however, see SurveyorId, but i cant expand this.
Sorry for little information, thanks in advance.
does this field require expansion? if so make sure to try:
_api/web/lists/getbytitle('Planning')/items(1)/?$select=Surveyor/Title&$expand=Surveyor/Title

Sphinx: JSON meta attributes stopped working

I'm currently experimenting with sphinx realtime index. I inserted 4,5 millions documents.
Everything was working OK while my json meta attributes were like this:
{"result_type":"publications","publication_type":"essay"}
But yesterday, I wanted to add another value in 'publication_type' key and the json
resulted to:
{"result_type":"publications","publication_type":["essay","big_text"]}
Now I can't find document neither for 'essay', neither for 'big_text'.
The sphinxql query I'm using is like this:
select * from url where meta.publication_type='essay';
Sphinx version is Server version: 2.1.1-beta (rel21-r3701) running on Debian.
Hope you can help me. Is my json string wrong? Where is my mistake?
Thanks in advance.
SELECT *, ANY(x='essay' FOR x IN meta.publication_type) as p FROM url WHERE p=1;
Supported in 2.2.1-dev since r4217.
This was answered on the sphinx forum:
http://sphinxsearch.com/forum/view.html?id=11486
When store arrays, you access the values by index.
So could do
select * from url where meta.publication_type[0]='essay';
It doesnt appear to easy to search 'in any position'. So if essay was ever not the first index, it wouldnt work.
Note, I can't claim credit for figuring this out, just passing this information on.

how to select specific number of child entities instead of all in entity framework 3.5?

i am wondering how can i select specific number of child objects instead of taking them all with include?
lets say i have object 'Group' and i need to select last ten students that joined the group.
When i use '.Include("Students"), EF includes all students. I was trying to use Take(10), but i am pretty new to EF and programming as well, so i couldn't figure it out.
Any suggestions?
UPDATED:
ok, i have Group object already retrieved from db like this:
Group group = db.Groups.FirstOrDefault(x=>x.GroupId == id)
I know that i can add Include("Students") statement, but that would bring ALL students, and their number could be quite big whether i need only freshest 10 students. Can i do something like this: var groupWithStudents = group.Students.OrderByDescending(//...).Take(10);?
The problem with this is that Take<> no longer appears in intellisense. Is this clear enough? Thanks for responses
I believe Take(10) would be correct.
var Students= (from c in Groups
orderby c.DateAdded descending
select c).Take(10);
My experience with Take though is that it generates some awful sql.
EDIT:
see if this blog post helps, it talks of conditional includes.
http://blogs.msdn.com/b/alexj/archive/2009/10/13/tip-37-how-to-do-a-conditional-include.aspx
Couldn't make Gratzy's suggestion with conditional include work... and found the solution here: http://msdn.microsoft.com/en-us/library/bb896249.aspx
Query would look like this:
group.Students.Attach(group.Students
.CreateSourceQuery()
.OrderByDescending(x=>x.JoinDate)
.Take(10));
This is exactly what i was looking for!
Thanks for all responses anyway!