To phrase your need more generically:

 * find all documents for userID=x, where userID=x has more than y
 documents in the index

Is that correct?

If it is, I'd probably do some work at index time. First guess, I'd keep
a separate core, which has a very small document per user, storing just:

 * userID
 * docCount

Then, when you add/delete a document, you use atomic updates to either
increase or decrease the docCount on that user doc.

Then you can use a pseudo join between these two cores relatively
easily.

q=user_id:x {!join fromIndex=user from=user_id to=user_id}+user_id:x
+doc_count:[y TO *]

Worst case, if you don't want to mess with your indexing code, I wonder
if you could use a ScriptUpdateProcessor to do this work - not sure if
you can have one add an entirely new, additional, document to the list,
but may be possible.

Upayavira

On Fri, Sep 27, 2013, at 09:50 PM, Matheus Salvia wrote:
> Sure, sorry for the inconvenience.
> 
> I'm having a little trouble trying to make a query in Solr. The problem
> is:
> I must be able retrieve documents that have the same value for a
> specified
> field, but they should only be retrieved if this value appeared more than
> X
> times for a specified user. In pseudosql it would be something like:
> 
> select user_id from documents
> where my_field="my_value"
> and
> (select count(*) from documents where my_field="my_value" and
> user_id=super.user_id) > X
> 
> I Know that solr return a 'numFound' for each query you make, but I dont
> know how to retrieve this value in a subquery.
> 
> My Solr is organized in a way that a user is a document, and the
> properties
> of the user (such as name, age, etc) are grouped in another document with
> a
> 'root_id' field. So lets suppose the following query that gets all the
> root
> documents whose children have the prefix "some_prefix".
> 
> is_root:true AND _query_:"{!join from=root_id
> to=id}requests_prefix:\"some_prefix\""
> 
> Now, how can I get the root documents (users in some sense) that have
> more
> than X children matching 'requests_prefix:"some_prefix"' or any other
> condition? Is it possible?
> 
> P.S. It must be done in a single query, fields can be added at will, but
> the root/children structure should be preserved (preferentially).
> 
> 
> 2013/9/27 Upayavira <u...@odoko.co.uk>
> 
> > Mattheus,
> >
> > Given these mails form a part of an archive that are themselves
> > self-contained, can you please post your actual question here? You're
> > more likely to get answers that way.
> >
> > Thanks, Upayavira
> >
> > On Fri, Sep 27, 2013, at 04:36 PM, Matheus Salvia wrote:
> > > Hello everyone,
> > > I'm having a problem regarding how to make a solr query, I've posted it
> > > on
> > > stackoverflow.
> > > Can someone help me?
> > >
> > http://stackoverflow.com/questions/19039099/apache-solr-count-of-subquery-as-a-superquery-parameter
> > >
> > > Thanks in advance!
> > >
> > > --
> > > --
> > >  // Matheus Salvia
> > > Desenvolvedor Mobile
> > > Celular: +55 11 9-6446-2332
> > > Skype: meta.faraday
> >
> 
> 
> 
> -- 
> --
>  // Matheus Salvia
> Desenvolvedor Mobile
> Celular: +55 11 9-6446-2332
> Skype: meta.faraday

Reply via email to