You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by mertens <lm...@gmail.com> on 2014/04/02 10:50:29 UTC

Re: Block Join Parent Query across children docs

Hi Mikhail,

Thanks for your response. Here is an example of what I'm trying to do. If I
had the following documents:

    <doc>
      <field name="id">10</field>
      <field name="type_s">parent</field>
      <field name="name_s">User1</field>
      <doc>
        <field name="id">11</field>
        <field name="search_s">item1, item6</field>
      </doc>
      <doc>
        <field name="id">12</field>
        <field name="search_s">item2, item7</field>
      </doc>
      <doc>
        <field name="id">13</field>
        <field name="search_s">item3, item8</field>
      </doc>
    </doc>
    <doc>
      <field name="id">20</field>
      <field name="type_s">parent</field>
      <field name="name_s">user2</field>
      <doc>
        <field name="id">21</field>
        <field name="search_s">item1, item6</field>
      </doc>
      <doc>
        <field name="id">22</field>
        <field name="search_s">item2, item7</field>
      </doc>
      <doc>
        <field name="id">23</field>
        <field name="search_s">item8</field>
      </doc>
    </doc>

I would like to do a search for users with item1 and item2 and not item3,
and that query should only return user2. I have tried this with a block
join query with solr 4.6.1 and it does not work the way I need it to. If
you have any ideas let me know.

Thanks,
Luke


On Sat, Mar 29, 2014 at 1:46 PM, Mikhail Khludnev [via Lucene] <
ml-node+s472066n4127896h95@n3.nabble.com> wrote:

> Hello Luke,
>
> If I get you right, you need to combine parent (block join) queries e.g
> users who have a record with item1 AND users who have a record with item2.
>
> Does it make sense? If it does, do you need to figure out a syntax?
> 28.03.2014 14:19 пользователь "mertens" <[hidden email]<http://user/SendEmail.jtp?type=node&node=4127896&i=0>>
> написал:
>
> > Hello Solr Users,
> >
> > In my system I have multiple records belonging to users, and I need to
> > perform a query to find users who have records that meet the criteria of
> > that query. For example, if my record has the field "search" and I query
> > for
> > search:((item1 AND item2) NOT item3), I want to find all users that have
> > one
> > or more records with item1 and one or more records with item2 but no
> > records
> > containing item3.
> >
> > I have investigated the block join parent query which comes close to the
> > functionality that I need, but it appears to apply the entire query to
> each
> > individual child document, rather than across all child documents.
> >
> > At the moment the only solutions I can think of are to combine all the
> user
> > records into one giant document for each user or do some sort of OR
> query
> > to
> > get all documents with partial matches for each user and then manually
> > verify that my result document set satisfies my criteria. Neither of
> these
> > solutions sounds very attractive to me. Does anyone else have any advice
> or
> > recommendations for this scenario?
> >
> > Thanks,
> > Luke
> >
> >
> >
> > --
> > View this message in context:
> >
> http://lucene.472066.n3.nabble.com/Block-Join-Parent-Query-across-children-docs-tp4127637.html
> > Sent from the Solr - User mailing list archive at Nabble.com.
> >
>
>
> ------------------------------
>  If you reply to this email, your message will be added to the discussion
> below:
>
> http://lucene.472066.n3.nabble.com/Block-Join-Parent-Query-across-children-docs-tp4127637p4127896.html
>  To unsubscribe from Block Join Parent Query across children docs, click
> here<http://lucene.472066.n3.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=4127637&code=bG1lcnRlbnNAZ21haWwuY29tfDQxMjc2Mzd8LTU0NDAxMzQzMw==>
> .
> NAML<http://lucene.472066.n3.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>




--
View this message in context: http://lucene.472066.n3.nabble.com/Block-Join-Parent-Query-across-children-docs-tp4127637p4128554.html
Sent from the Solr - User mailing list archive at Nabble.com.

Re: Block Join Parent Query across children docs

Posted by mertens <lm...@gmail.com>.
Yeah, that works also for me. Thanks Mikhail.


On Mon, Apr 7, 2014 at 12:42 PM, Mikhail Khludnev [via Lucene] <
ml-node+s472066n4129604h43@n3.nabble.com> wrote:

> for sake of completeness, here is the same query w/o fq
>
> q=+{!parent which=type_s:parent}search_t:item1 +{!parent
> which=type_s:parent}search_t:item2 -{!parent
> which=type_s:parent}search_t:item3
>
> here is more detail about the first symbol magic
> http://www.mail-archive.com/solr-user@.../msg96796.html<http://www.mail-archive.com/solr-user@lucene.apache.org/msg96796.html>
>
>
>
> On Mon, Apr 7, 2014 at 1:23 PM, mertens <[hidden email]<http://user/SendEmail.jtp?type=node&node=4129604&i=0>>
> wrote:
>
> > Thanks Hoss, with the filter queries it works. I was trying to use a
> normal
> > query from Mikhail's blog that looked like this:
> >
> > q={!parent which=type_s:parent}+search_t:item1 +search_t:item2
> > -search_t:item3
> >
> > That query doesn't work for me but the filter query does just what I
> want.
> >
> > ps last years stump the chump was great, and it looks like you're still
> not
> > stumped.
> >
> > Cheers,
> > Luke
> >
> >
> > On Thu, Apr 3, 2014 at 1:39 AM, Chris Hostetter-3 [via Lucene] <
> > [hidden email] <http://user/SendEmail.jtp?type=node&node=4129604&i=1>>
> wrote:
> >
> > >
> > > : Thanks for your response. Here is an example of what I'm trying to
> do.
> > > If I
> > > : had the following documents:
> > >
> > > what you are attempting is fairly trivial -- you want to query for all
> > > parent documents, then kapply 3 filters:
> > >
> > >  * parent of a child matching item1
> > >  * parent of a child matching item2
> > >  * not a parent of a chile matching item3
> > >
> > > Part of your problem may be that (in your example you posted
> anywayway)
> > > you appear to be trying to use a *string* field for listing multiple
> > terms
> > > with commas and then seem to want to match on those individual terms
> --
> > > that's not going to work.  either make your string field a true
> > > multivalued field, or use a text field with tokenization.
> > >
> > > With the modified example data you provided below (using search_t
> instead
> > > of search_s) this query seems to do exactly waht you want...
> > >
> > >
> > http://localhost:8983/solr/select?p_filt=type_s:parent&q=*:*&fq={!parent%20which=$p_filt}search_t:item2&fq={!parent%20which=$p_filt}search_t:item1&fq=-{!parent%20which=$p_filt}search_t:item3
>
> > >
> > >
> > >      q = *:*
> > > p_filt = type_s:parent
> > >     wt = json
> > >     fq =  {!parent which=$p_filt}search_t:item2
> > >     fq =  {!parent which=$p_filt}search_t:item1
> > >     fq = -{!parent which=$p_filt}search_t:item3
> > >
> > >
> > > -Hoss
> > > http://www.lucidworks.com/
> > >
> > >
> > > ------------------------------
> > >  If you reply to this email, your message will be added to the
> discussion
> > > below:
> > >
> > >
> >
> http://lucene.472066.n3.nabble.com/Block-Join-Parent-Query-across-children-docs-tp4127637p4128734.html
> > >  To unsubscribe from Block Join Parent Query across children docs,
> click
> > > here<
> >
> >
> > > .
> > > NAML<
> >
> http://lucene.472066.n3.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml
>
> > >
> > >
> >
> >
> >
> >
> > --
> > View this message in context:
> >
> http://lucene.472066.n3.nabble.com/Block-Join-Parent-Query-across-children-docs-tp4127637p4129588.html
>
> > Sent from the Solr - User mailing list archive at Nabble.com.
> >
>
>
>
> --
> Sincerely yours
> Mikhail Khludnev
> Principal Engineer,
> Grid Dynamics
>
> <http://www.griddynamics.com>
> <[hidden email] <http://user/SendEmail.jtp?type=node&node=4129604&i=2>>
>
>
> ------------------------------
>  If you reply to this email, your message will be added to the discussion
> below:
>
> http://lucene.472066.n3.nabble.com/Block-Join-Parent-Query-across-children-docs-tp4127637p4129604.html
>  To unsubscribe from Block Join Parent Query across children docs, click
> here<http://lucene.472066.n3.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=4127637&code=bG1lcnRlbnNAZ21haWwuY29tfDQxMjc2Mzd8LTU0NDAxMzQzMw==>
> .
> NAML<http://lucene.472066.n3.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>




--
View this message in context: http://lucene.472066.n3.nabble.com/Block-Join-Parent-Query-across-children-docs-tp4127637p4129609.html
Sent from the Solr - User mailing list archive at Nabble.com.

Re: Block Join Parent Query across children docs

Posted by Mikhail Khludnev <mk...@griddynamics.com>.
for sake of completeness, here is the same query w/o fq

q=+{!parent which=type_s:parent}search_t:item1 +{!parent
which=type_s:parent}search_t:item2 -{!parent
which=type_s:parent}search_t:item3

here is more detail about the first symbol magic
http://www.mail-archive.com/solr-user@lucene.apache.org/msg96796.html


On Mon, Apr 7, 2014 at 1:23 PM, mertens <lm...@gmail.com> wrote:

> Thanks Hoss, with the filter queries it works. I was trying to use a normal
> query from Mikhail's blog that looked like this:
>
> q={!parent which=type_s:parent}+search_t:item1 +search_t:item2
> -search_t:item3
>
> That query doesn't work for me but the filter query does just what I want.
>
> ps last years stump the chump was great, and it looks like you're still not
> stumped.
>
> Cheers,
> Luke
>
>
> On Thu, Apr 3, 2014 at 1:39 AM, Chris Hostetter-3 [via Lucene] <
> ml-node+s472066n4128734h73@n3.nabble.com> wrote:
>
> >
> > : Thanks for your response. Here is an example of what I'm trying to do.
> > If I
> > : had the following documents:
> >
> > what you are attempting is fairly trivial -- you want to query for all
> > parent documents, then kapply 3 filters:
> >
> >  * parent of a child matching item1
> >  * parent of a child matching item2
> >  * not a parent of a chile matching item3
> >
> > Part of your problem may be that (in your example you posted anywayway)
> > you appear to be trying to use a *string* field for listing multiple
> terms
> > with commas and then seem to want to match on those individual terms --
> > that's not going to work.  either make your string field a true
> > multivalued field, or use a text field with tokenization.
> >
> > With the modified example data you provided below (using search_t instead
> > of search_s) this query seems to do exactly waht you want...
> >
> >
> http://localhost:8983/solr/select?p_filt=type_s:parent&q=*:*&fq={!parent%20which=$p_filt}search_t:item2&fq={!parent%20which=$p_filt}search_t:item1&fq=-{!parent%20which=$p_filt}search_t:item3
> >
> >
> >      q = *:*
> > p_filt = type_s:parent
> >     wt = json
> >     fq =  {!parent which=$p_filt}search_t:item2
> >     fq =  {!parent which=$p_filt}search_t:item1
> >     fq = -{!parent which=$p_filt}search_t:item3
> >
> >
> > -Hoss
> > http://www.lucidworks.com/
> >
> >
> > ------------------------------
> >  If you reply to this email, your message will be added to the discussion
> > below:
> >
> >
> http://lucene.472066.n3.nabble.com/Block-Join-Parent-Query-across-children-docs-tp4127637p4128734.html
> >  To unsubscribe from Block Join Parent Query across children docs, click
> > here<
> http://lucene.472066.n3.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=4127637&code=bG1lcnRlbnNAZ21haWwuY29tfDQxMjc2Mzd8LTU0NDAxMzQzMw==
> >
> > .
> > NAML<
> http://lucene.472066.n3.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml
> >
> >
>
>
>
>
> --
> View this message in context:
> http://lucene.472066.n3.nabble.com/Block-Join-Parent-Query-across-children-docs-tp4127637p4129588.html
> Sent from the Solr - User mailing list archive at Nabble.com.
>



-- 
Sincerely yours
Mikhail Khludnev
Principal Engineer,
Grid Dynamics

<http://www.griddynamics.com>
<mk...@griddynamics.com>

Re: Block Join Parent Query across children docs

Posted by mertens <lm...@gmail.com>.
Thanks Hoss, with the filter queries it works. I was trying to use a normal
query from Mikhail's blog that looked like this:

q={!parent which=type_s:parent}+search_t:item1 +search_t:item2
-search_t:item3

That query doesn't work for me but the filter query does just what I want.

ps last years stump the chump was great, and it looks like you're still not
stumped.

Cheers,
Luke


On Thu, Apr 3, 2014 at 1:39 AM, Chris Hostetter-3 [via Lucene] <
ml-node+s472066n4128734h73@n3.nabble.com> wrote:

>
> : Thanks for your response. Here is an example of what I'm trying to do.
> If I
> : had the following documents:
>
> what you are attempting is fairly trivial -- you want to query for all
> parent documents, then kapply 3 filters:
>
>  * parent of a child matching item1
>  * parent of a child matching item2
>  * not a parent of a chile matching item3
>
> Part of your problem may be that (in your example you posted anywayway)
> you appear to be trying to use a *string* field for listing multiple terms
> with commas and then seem to want to match on those individual terms --
> that's not going to work.  either make your string field a true
> multivalued field, or use a text field with tokenization.
>
> With the modified example data you provided below (using search_t instead
> of search_s) this query seems to do exactly waht you want...
>
> http://localhost:8983/solr/select?p_filt=type_s:parent&q=*:*&fq={!parent%20which=$p_filt}search_t:item2&fq={!parent%20which=$p_filt}search_t:item1&fq=-{!parent%20which=$p_filt}search_t:item3
>
>
>      q = *:*
> p_filt = type_s:parent
>     wt = json
>     fq =  {!parent which=$p_filt}search_t:item2
>     fq =  {!parent which=$p_filt}search_t:item1
>     fq = -{!parent which=$p_filt}search_t:item3
>
>
> -Hoss
> http://www.lucidworks.com/
>
>
> ------------------------------
>  If you reply to this email, your message will be added to the discussion
> below:
>
> http://lucene.472066.n3.nabble.com/Block-Join-Parent-Query-across-children-docs-tp4127637p4128734.html
>  To unsubscribe from Block Join Parent Query across children docs, click
> here<http://lucene.472066.n3.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=4127637&code=bG1lcnRlbnNAZ21haWwuY29tfDQxMjc2Mzd8LTU0NDAxMzQzMw==>
> .
> NAML<http://lucene.472066.n3.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>




--
View this message in context: http://lucene.472066.n3.nabble.com/Block-Join-Parent-Query-across-children-docs-tp4127637p4129588.html
Sent from the Solr - User mailing list archive at Nabble.com.

Re: Block Join Parent Query across children docs

Posted by Chris Hostetter <ho...@fucit.org>.
: Thanks for your response. Here is an example of what I'm trying to do. If I
: had the following documents:

what you are attempting is fairly trivial -- you want to query for all 
parent documents, then kapply 3 filters:

 * parent of a child matching item1
 * parent of a child matching item2
 * not a parent of a chile matching item3

Part of your problem may be that (in your example you posted anywayway) 
you appear to be trying to use a *string* field for listing multiple terms 
with commas and then seem to want to match on those individual terms -- 
that's not going to work.  either make your string field a true 
multivalued field, or use a text field with tokenization.

With the modified example data you provided below (using search_t instead 
of search_s) this query seems to do exactly waht you want...

http://localhost:8983/solr/select?p_filt=type_s:parent&q=*:*&fq={!parent%20which=$p_filt}search_t:item2&fq={!parent%20which=$p_filt}search_t:item1&fq=-{!parent%20which=$p_filt}search_t:item3

     q = *:*
p_filt = type_s:parent
    wt = json
    fq =  {!parent which=$p_filt}search_t:item2
    fq =  {!parent which=$p_filt}search_t:item1
    fq = -{!parent which=$p_filt}search_t:item3


-Hoss
http://www.lucidworks.com/