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 SuperMattio86 <ma...@gmail.com> on 2018/02/04 19:56:02 UTC
Matching parent docs when two child docs match different criteria
Hello.
As a toy example, let's assume I have documents that looks like this:
{
"id": "1",
"_childDocuments_": [
{
"id": "1_2",
"_path_": "p.1",
"size": "M",
"color": "red"
},
{
"id": "23lk4d23lkj",
"_path_": "p.2",
"size": "L",
"color": "blue"
}
]
}
Is it possible to construct a query that will match a parent doc that has a
child doc that say matches 'size:L' and a DIFFERENT child that matches
'size:M'? Is such a query possible? What would it look like? Or would I need
to implement a custom query parser to do this?
I can currently do this without sub-documents, by indexing those values as
arrays, and creating a custom scorer/collector that collects positions in
addition to docs, but since I am now switching to a version of Solr that has
sub-documents, I was hoping for a better solution that more intuitively
models my data structures.
--
Sent from: http://lucene.472066.n3.nabble.com/Solr-User-f472068.html
Re: Matching parent docs when two child docs match different criteria
Posted by Mikhail Khludnev <mk...@apache.org>.
Matt, I don't really follow the new sample and the query, but you've got
the first idea, I believe.
Then, this requirement is not really boolean logic. So, it's obviously not
easy to achieve.
The second idea is
- to use size:(M L)^=1 for children clause, then
- use score=total in parent level and then
- cutoff weaker scored parents with {!frange l=2}
yeah. it's cumbersome.
On Tue, Feb 6, 2018 at 3:12 AM, SuperMattio86 <ma...@gmail.com>
wrote:
> Thank you! That is interesting. But I think I failed to fully outline the
> requirements I have, since I can still contrive an example where this might
> not work. If I changed the document as follows:
>
> {
> "id":"3",
> "_level_":0,
> "_version_":1591607734461005824,
> "_childDocuments_":[
> {
> "id":"3_1",
> "_path_":["p.1"],
> "size":"M",
> "color":"red",
> "_level_":1,
> "_version_":1591607734461005824,
> "_path__str":["p.1"]}]}]
> }
> ]}
>
> And I made a query similar to what you did: _query_:"{!parent
> which=_level_:0}size:M" AND _query_:"{!parent which=_level_:0}size:M"
>
> This document would match. So I'm asking for a different scenario here, but
> with the same operation in mind: How do I construct a query that will match
> a parent document that has two _different_ child docs, each with size:M.
>
> Or, in the more general case, how can I construct a query that contains _n_
> clauses, where each of the _n_ clauses must match a _different_ child
> document.
>
>
>
> --
> Sent from: http://lucene.472066.n3.nabble.com/Solr-User-f472068.html
>
--
Sincerely yours
Mikhail Khludnev
Re: Matching parent docs when two child docs match different
criteria
Posted by SuperMattio86 <ma...@gmail.com>.
Thank you! That is interesting. But I think I failed to fully outline the
requirements I have, since I can still contrive an example where this might
not work. If I changed the document as follows:
{
"id":"3",
"_level_":0,
"_version_":1591607734461005824,
"_childDocuments_":[
{
"id":"3_1",
"_path_":["p.1"],
"size":"M",
"color":"red",
"_level_":1,
"_version_":1591607734461005824,
"_path__str":["p.1"]}]}]
}
]}
And I made a query similar to what you did: _query_:"{!parent
which=_level_:0}size:M" AND _query_:"{!parent which=_level_:0}size:M"
This document would match. So I'm asking for a different scenario here, but
with the same operation in mind: How do I construct a query that will match
a parent document that has two _different_ child docs, each with size:M.
Or, in the more general case, how can I construct a query that contains _n_
clauses, where each of the _n_ clauses must match a _different_ child
document.
--
Sent from: http://lucene.472066.n3.nabble.com/Solr-User-f472068.html
Re: Matching parent docs when two child docs match different criteria
Posted by Mikhail Khludnev <mk...@apache.org>.
q=+{!parent .. v=$m} +{!parent .. v=$l}&m=size:(+M -L)&l=size:(+L -M)
On Sun, Feb 4, 2018 at 10:56 PM, SuperMattio86 <ma...@gmail.com>
wrote:
> Hello.
>
> As a toy example, let's assume I have documents that looks like this:
>
> {
> "id": "1",
> "_childDocuments_": [
> {
> "id": "1_2",
> "_path_": "p.1",
> "size": "M",
> "color": "red"
> },
> {
> "id": "23lk4d23lkj",
> "_path_": "p.2",
> "size": "L",
> "color": "blue"
> }
> ]
> }
>
> Is it possible to construct a query that will match a parent doc that has a
> child doc that say matches 'size:L' and a DIFFERENT child that matches
> 'size:M'? Is such a query possible? What would it look like? Or would I
> need
> to implement a custom query parser to do this?
>
> I can currently do this without sub-documents, by indexing those values as
> arrays, and creating a custom scorer/collector that collects positions in
> addition to docs, but since I am now switching to a version of Solr that
> has
> sub-documents, I was hoping for a better solution that more intuitively
> models my data structures.
>
>
>
>
>
>
> --
> Sent from: http://lucene.472066.n3.nabble.com/Solr-User-f472068.html
>
--
Sincerely yours
Mikhail Khludnev