Trying to work out how to do a mongoid query to return Documents with a range of embeded documents
e.g.
class Question
embeds_many :question_response,
get questions that have only 1,2 or 3 responses
Question.between(:question_response.count, 1, 3)
Any ideas?
For those who wanted to know.
with_size worked.
Thanks
Related
No body answer this question
So I ask it again
Given solr has these documents:
'Danniel Wellington'
'George Wellington'
'Wellington'
when I search for : "Danniel Wellington"
I want to get the result as below:
'Danniel Wellington'
'Wellington'
Which means we want to get subset of specified string
Is there any existing analyzer which can achieve the above
Thanks a lot in advance
I have found type of document in solr database. Out of those 4, one is general document, second news, third books and fourth poetry. Now I want to query solr so that it should return 10 results. out of those 7 result should be from general documents, 1 from news, 1 from books and 1 from poetry. I am using solr in cloud mode.
Is it possible. if yes then how if not then why ?
Basically, I want to get all these in one query.
You can use result grouping. Based on this documentation your request should be
http://localhost:8983/solr/techproducts/select?wt=json&indent=true&
q=you_query_string&group=true&group.field=type&group.limit=7
After search you should take seven items from group with general type, and by one item from others groups.
All:
[UPDATE] Thanks for Andrea's answer, currently I am using this way:
If you send also a facet.mincount=1 then the start bound is just an
indication because Solr will return only those values (i.e. ranges)
that have at least 1 document inside. So for instance you could
indicate a very low value as start.
Note: This is only proved works for my case, so use your judgement
&facet=true&facet.range=createDate&facet.range.gap=%2B2DAY&facet.range.end=NOW&facet.range.start=NOW-1000DAY&facet.mincount=1
I am pretty new to Solr facet. Suppose that I have some documents which has createDate:
"2015-03-23T17:59:00Z",
"2015-03-23T22:13:00Z",
"2015-03-17T20:48:00Z",
"2015-03-19T17:43:00Z",
"2015-03-19T21:58:00Z",
"2015-03-16T19:13:00Z",
"2015-03-16T22:26:00Z",
"2015-03-13T21:33:00Z",
"2015-03-13T21:39:00Z",
"2015-03-13T23:27:00Z",
"2015-03-16T16:46:00Z",
"2015-03-18T17:44:00Z",
"2015-03-18T18:10:00Z",
"2015-03-18T18:11:00Z"
.......
My questions are :
[1] How to get the result range by DAY?
[2] How to get facet result grouped by WEEK( or let us say 7 days)?
Thanks
It is called range faceting. I suggest you to read the Solr wiki but in the meantime:
facet.range=(field name)
facet.range.start=(start date or value)
facet.range.end=(end date or value)
facet.range.gap=(interval value or expression)
In your case you should use +1DAY or +7DAYS as facet.range.gap.
There are also other parmeters so it's better if you have a look at the wiki
I am struggling with a little problem where I have to display relevant information about the resultset returned from SolR but can't figure out how to calculate it without iterating the results (bad).
Basically I am storing my documents with a state field and while the search is supposed to return all documents, the UI has to show "Found 15 entities, 5 are in state A, 3 in state B and 8 in C".
At the moment I am using a rather brittle approach of running the query 3 times with additional scoping by type, but I'd rather get that information from the one query I am displaying. (There have been some edge cases where the numbers don't add up and since SolR can return facets I guess there has to be a way to use that functionality in this case)
I am using SolR 3.5 from Rails with the sunspot gem
As you mention yourself, you can use facets for this by setting
facet=true&facet.field=state
I'm not familiar with the sunspot gem, but by looking at the documentation you can use
facets like this(Assuming Entity is your searchable):
Entity.search do:
facet :state
end
This should return the states of all entities returned by your query with the number of entities in this state. The Sunspot documentation tells me you can read these facets in the following way:
search.facet(:state).rows.each do |facet|
puts "State #{facet.value} has #{facet.count} entities"
end
Essentially there are three main sets of functions you can use to garner stats from solr.
The first is faceting:
http://wiki.apache.org/solr/SimpleFacetParameters
There is also grouping (field collapsing):
https://wiki.apache.org/solr/FieldCollapsing
And the stats package:
https://cwiki.apache.org/confluence/display/solr/The+Stats+Component
Although the stats, facet and group may be replaced by the analytic package known as olap which is aimed to be in solr V 5.0.0:
https://issues.apache.org/jira/browse/SOLR-5302
Good luck.
I'm unclear on this point from the documentation. Is it possible to give Solr X document IDs and tell it that I want documents similar to those?
Example:
The user is browsing 5 different articles
I send Solr the IDs of these 5 articles so I can present the user other similar articles
I am not clear about sending the document IDs, nor whether MoreLikeThis can operate on multiple documents as in this example.
you can try passing multiple Ids with the Query q=id:(document_id1 OR document_id2 OR document_id3) :-
e.g.
http://localhost:8080/solr/select/?qt=mlt&q=id:(document_id1 OR document_id2 OR document_id3)&mlt.fl=[field1],[field2],[field3]&fl=id&rows=10