Sorting parent documents based on a field from children

2015-08-31 Thread Florin Mandoc

Hi,

I am trying to model am index from a relational database and i have 3 
main entity types: products, buyers and sellers.
I am using nested documents for sellers and buyers, as i have many 
sellers and many buyers for one product:


{ "Active" : "true",
  "CategoryID" : 59,
  "CategoryName" : "Produce",
  "Id" : "227686",
  "ManufacturerID" : 322,
  "ManufacturerName" : "---",
  "Name" : "product name",
  "ProductID" : "227686",
  "SKU" : "DAFA2A1F047E438B8462667F987D80A5",
  "ShortDescription" : "s description",
  "type" : "product",
  "UOM" : "Unit",
  "UomSize" : "48",
  "_childDocuments_" : [ { "BuyerID" : 83,
"DisplayOrder" : 0,
"ProductID" : "227686",
"id" : "227686_83",
"type" : "buyer"
  },
  { "BuyerID" : 86,
"DisplayOrder" : 10,
"ProductID" : "227686",
"id" : "227686_86",
"type" : "buyer"
  },
  { "BuyerID" : 83,
"ProductID" : "227686",
"SellerID" : 84,
"SellerName" : "Seller 84",
"id" : "227686_83_84",
"type" : "seller"
  },
  { "BuyerID" : 83,
"ProductID" : "227686",
"SellerID" : 89,
"SellerName" : "Seller 89",
"id" : "227686_83_89",
"type" : "seller"
  }
],
  "_version_" : 1509403723402575872
}

To query i use:
http://localhost:8983/solr/dine/select?q=Name:"product 
name"&fq={!parent%20which=type:product v="type:buyer AND 
BuyerID=83"}&wt=json&indent=true&fl=*,[child%20parentFilter=type:product%20childFilter=%22((type:buyer%20AND%20BuyerSiteID:83)%20OR%20(type:seller%20AND%20BuyerSiteID:83))]&rows=1000


and i get the product, buyer and sellers details, but i want to have the 
products of BuyerID:83 sorted by DisplayOrder field.


Is this possible to achieve this, and how?

Thank you


Re: Sorting parent documents based on a field from children

2015-09-01 Thread Florin Mandoc

Hi,

I have tried the solution from your blog with my schema and with the 
example from the blog post, with solr-5.3.0 and with solr-5.4. 
0-2015-08-12 and i get this error:


"responseHeader":{
"status":500,
"QTime":32},
  "error":{
"msg":"child query must only match non-parent docs, but parent docID=2 matched 
childScorer=class org.apache.lucene.search.DisjunctionSumScorer",
"trace":"java.lang.IllegalStateException: child query must only match non-parent 
docs, but parent docID=2 matched childScorer=class 
org.apache.lucene.search.DisjunctionSumScorer\n\tat 
org.apache.lucene.search.join.ToParentBlockJoinQuery$BlockJoinScorer.nextDoc(ToParentBlockJoinQuery.java:311)\n\tat
 org.apache.lucene.search.Weight$DefaultBulkScorer.scoreAll(Weight.java:216)\n\tat 
org.apache.lucene.search.Weight$DefaultBulkScorer.score(Weight.java:169)\n\tat 
org.apache.lucene.search.BulkScorer.score(BulkScorer.java:39)\n\tat 
org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:772)\n\tat 
org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:486)\n\tat 
org.apache.solr.search.SolrIndexSearcher.buildAndRunCollectorChain(SolrIndexSearcher.java:200)\n\tat
 org.apache.solr.search.SolrIndexSearcher.getDocListNC(SolrIndexSearcher.java:1682)\n\tat 
org.apache.solr.search.SolrIndexSearcher.getDocListC(SolrIndexSearcher.java:1501)\n\tat 
org.apache.solr.search.SolrIndexSearcher.search(SolrIndexSearcher.java:555)\n\tat 
org.apache.solr.handler.component.QueryComponent.process(QueryComponent.java:522)\n\tat 
org.apache.solr.handler.component.SearchHandler.handleRequestBody(SearchHandler.java:277)\n\tat 
org.apache.solr.handler.RequestHandlerBase.handleRequest(RequestHandlerBase.java:143)\n\tat 
org.apache.solr.core.SolrCore.execute(SolrCore.java:2068)\n\tat 
org.apache.solr.servlet.HttpSolrCall.execute(HttpSolrCall.java:669)\n\tat 
org.apache.solr.servlet.HttpSolrCall.call(HttpSolrCall.java:462)\n\tat 
org.apache.solr.servlet.SolrDispatchFilter.doFilter(SolrDispatchFilter.java:210)\n\tat 
org.apache.solr.servlet.SolrDispatchFilter.doFilter(SolrDispatchFilter.java:179)\n\tat 
org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1652)\n\tat 
org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:585)\n\tat 
org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)\n\tat 
org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:577)\n\tat 
org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:223)\n\tat 
org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1127)\n\tat 
org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:515)\n\tat 
org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185)\n\tat 
org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1061)\n\tat 
org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)\n\tat 
org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:215)\n\tat
 org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:110)\n\tat 
org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)\n\tat 
org.eclipse.jetty.server.Server.handle(Server.java:499)\n\tat 
org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:310)\n\tat 
org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:257)\n\tat 
org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:540)\n\tat 
org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:635)\n\tat 
org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:555)\n\tat 
java.lang.Thread.run(Thread.java:745)\n",
"code":500}

The query is for your example
http://localhost:8983/solr/testscore/select?q={!parent%20which=type_s:product%20score=max}+color_s:Red^=0%20{!func}price_i&wt=json&indent=true&fl=score,*,[docid]

Do you have any idea why i get this error?

Thank you


On 31.08.2015 15:48, Mikhail Khludnev wrote:

Florin,

I disclosure some details in the recent post
http://blog.griddynamics.com/2015/08/scoring-join-party-in-solr-53.html.
Let me know if you have further questions afterwards.
I also notice that you use "obvious" syntax: BuyerID=83 but it's hardly
ever possible. There is a good habit of debugQuery=true, which allows to
reconcile query interpretation.

On Mon, Aug 31, 2015 at 2:40 PM, Florin Mandoc  wrote:


Hi,

I am trying to model am index from a relational database and i have 3 main
entity types: products, buyers and sellers.
I am using nested documents for sellers and buyers, as i have many sellers
and many buyers for one product:

{ "Active" : "true",
   "CategoryID" : 59,
   "CategoryName" 

Re: Sorting parent documents based on a field from children

2015-09-16 Thread Florin Mandoc

Hi,

Sorry for letting this thread hanging, I was out of office last week.

I have managed to make it work using this query:
http://localhost:8983/solr/testscoring/select?q={!parent%20which=type_s:product%20score=max}+color_s:Red^=0%20AND%20{!func}price_i&wt=json&indent=true&fl=score,*,[docid]&debugQuery=true
for the example in your blog, and the result is like this:

{
  "responseHeader":{
"status":0,
"QTime":2},
  "response":{"numFound":2,"start":0,"maxScore":300.0,"docs":[
  {
"id":"2",
"type_s":"product",
"name_s":"expensive red",
"_version_":1511105298931122176,
"score":300.0,
"[docid]":5},
  {
"id":"1",
"type_s":"product",
"name_s":"expensive blue",
"_version_":1511105298905956352,
"score":10.0,
"[docid]":2}]
  },
  "debug":{
"rawquerystring":"{!parent which=type_s:product score=max} color_s:Red^=0 AND 
{!func}price_i",
"querystring":"{!parent which=type_s:product score=max} color_s:Red^=0 AND 
{!func}price_i",
"parsedquery":"ToParentBlockJoinQuery(ToParentBlockJoinQuery 
(+ConstantScore(color_s:Red)^0.0 +int(price_i)))",
"parsedquery_toString":"ToParentBlockJoinQuery (+ConstantScore(color_s:Red)^0.0 
+int(price_i))",
"explain":{
  "2":"\n300.0 = Score based on child doc range from 3 to 4\n",
  "1":"\n10.0 = Score based on child doc range from 0 to 1\n"},
"QParser":"BlockJoinParentQParser",
"timing":{
  "time":2.0,
  "prepare":{
"time":0.0,
"query":{
  "time":0.0},
"facet":{
  "time":0.0},
"facet_module":{
  "time":0.0},
"mlt":{
  "time":0.0},
"highlight":{
  "time":0.0},
"stats":{
  "time":0.0},
"expand":{
  "time":0.0},
"debug":{
  "time":0.0}},
  "process":{
"time":1.0,
"query":{
  "time":0.0},
"facet":{
  "time":0.0},
"facet_module":{
  "time":0.0},
"mlt":{
  "time":0.0},
"highlight":{
      "time":0.0},
"stats":{
  "time":0.0},
"expand":{
  "time":0.0},
"debug":{
  "time":0.


Is possible to to also add "name_s:expensive" search term in q? I know i 
can add it to fq but I will have no score boost.


Thank you


On 01.09.2015 15:29, Mikhail Khludnev wrote:

I suspect URL encoding might mess with MUST (+) clause. Can you post
debugQuery=true output to make sure that the query parsed right.
Then make sure that chid query and parent filter are fully orthogonal. eg
+type_s:product +color_s:Red returns no result.
Last check to check, make sure that you don't have deleted document in the
index for a while. You can check in at SolrAdmin.

On Tue, Sep 1, 2015 at 1:42 PM, Florin Mandoc  wrote:


Hi,

I have tried the solution from your blog with my schema and with the
example from the blog post, with solr-5.3.0 and with solr-5.4. 0-2015-08-12
and i get this error:

"responseHeader":{
 "status":500,
 "QTime":32},
   "error":{
 "msg":"child query must only match non-parent docs, but parent docID=2
matched childScorer=class org.apache.lucene.search.DisjunctionSumScorer",
 "trace":"java.lang.IllegalStateException: child query must only match
non-parent docs, but parent docID=2 matched childScorer=class
org.apache.lucene.search.DisjunctionSumScorer\n\tat
org.apache.lucene.search.join.ToParentBlockJoinQuery$BlockJoinScorer.nextDoc(ToParentBlockJoinQuery.java:311)\n\tat
org.apache.lucene.search.Weight$DefaultBulkScorer.scoreAll(Weight.java:216)\n\tat
org.apache.lucene.search.Weight$DefaultBulkScorer.score(Weight.java:169)\n\tat
org.apache.lucene.search.BulkScorer.score(BulkScorer.java:39)\n\tat
org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:772)\n\tat
org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:486)\n\tat
org.apache.solr.search.SolrIndexSearcher.buildAndRunCollectorChain(SolrIndexSearcher.java:200)\n\tat
org.apache.

Re: Sorting parent documents based on a field from children

2015-09-17 Thread Florin Mandoc

Great, thank you very much for your help.


On 16.09.2015 13:07, Mikhail Khludnev wrote:

On Wed, Sep 16, 2015 at 12:15 PM, Florin Mandoc  wrote:


Is possible to to also add "name_s:expensive" search term in q? I know i
can add it to fq but I will have no score boost.


Sure you can. But beware of query syntax trap. It's explained by David
Smiley at comment
http://blog.griddynamics.com/2013/09/solr-block-join-support.html (sadly
linking a comment doesn't work)






Additional field in facet result

2015-11-20 Thread Florin Mandoc
Hi, I have a index that contains products and tags as nested children, 
like below:


{
"id":"413863",
"ProductID":"413863",
"type":"product",
"MainProductID":"",
"SKU":"8D68595B",
"Name":"mere",
"alltext":["mere",
  "",
  "",
  "test product"],
"CustomName":"",
"CategoryID":0,
"CategoryName":"",
"MasterCategoryID":"0",
"MasterCategoryName":"",
"ShortDescription":"test product",
"UomID":"",
"Uom":"dz",
"UomSize":"0.9",
"ImageName":"",
"AllowFractionOrdering":"false",
"DisplayOrder":0,
"InternalSku":"8D68595B",
"PrivateProduct":"true",
"GroupedProduct":"",
"ProductGroupID":"-1",
"UomSizeParentID":"",
"CustomerSiteID":"4553",
"CustomerAccountID":"2323",
"IsAccountProduct":"true",
"IsVariation":"",
"Tags":["1754ztag"],
"Vendors":["4554qw"],
"_version_":1518371006298718216,
"_childDocuments_":[
{
  "id":"413863_1754",
  "type":"tag",
  "TagID":1754,
  "TagName":"ztag",
  "ProductID":"413863"},
{
  "id":"413863_4554_qw",
  "type":"vendor",
  "VendorID":4554,
  "VendorSKU":"qw",
  "ProductID":"413863"}]}


I am using this query to get the products and facets for tags:

http://localhost:8983/solr/favsearch/select?q=*:*&wt=json&indent=true&start=0&rows=100&&fl=*,[child%20parentFilter=type:product]&fq=CustomerSiteID:4553&json.facet={tags:{type:%20terms,field:TagName,domain:%20{%20blockChildren%20:%20%22type:product%22%20}},categories:{type:%20terms,field:CategoryID}}

The facets response is:

"facets":{
"count":15,
"tags":{
  "buckets":[{
  "val":"vendor 1",
  "count":3},
{
  "val":"vendor 2",
  "count":3},
{
  "val":"ztag",
  "count":2}]},
"categories":{
  "buckets":[{
  "val":-1,
  "count":5}]}}}


Is it possible to get in the response the field TagID also?
Or if I add another facet field for tag ids, like this

"facets":{
"count":15,
"tagNames":{
  "buckets":[{
  "val":"vendor 1",
  "count":3},
{
  "val":"vendor 2",
  "count":3},
{
  "val":"ztag",
  "count":2}]},
"tagId":{
  "buckets":[{
  "val":1752,
  "count":3},
{
  "val":1753,
  "count":3},
{
  "val":1754,
  "count":2}]},
"categories":{
  "buckets":[{
  "val":-1,
  "count":5}]}}}

can I be sure that always the first bucket from tagNames corresponds to 
the first bucket of tagId?


Thank you,
Florin