[ 
https://issues.apache.org/jira/browse/LUCENE-10432?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17497405#comment-17497405
 ] 

Andriy Redko commented on LUCENE-10432:
---------------------------------------

Thanks [~jpountz] 

> I wonder if you have thought about how queries would know what name they 
> should return in their explanations. My expectation is that we'd be 
> introducing some form of query wrapper whose point would only be to be able 
> to set a name or tags in the produced explanations.

That could be an option but I would suggest to not change queries. For example, 
in most cases Opensearch / Elasticsearch queries / filters / functions are 
wrapped into composites, the names and other attributes are stored there.

> Then I worry that it would make some things more complicated for Lucene like 
> query rewriting, which relies on instanceof checks, or query caching, which 
> would consider the same queries with different names as different.

Certainly, if the we change queries but we don't need to, ability to pass 
structured (key/value) details into the Explanation would help the engines 
propagate the internal context back.

 

May be a bit more illustrative example of end-2-end flow, the request:
{noformat}
{
    "explain": true,
    "query": {
      "function_score": {
        "query": {
          "match_all": {
          "_name": "q1"
          }
        },
        "functions": [
          {
            "filter": {
              "terms": {
               "_name": "terms_filter",
                "abc": [
                  "1"
                ]
              }
            },
            "weight": 35
          }
        ],
        "boost_mode": "replace",
        "score_mode": "sum",
        "min_score": 0
      }
    }
}{noformat}
 

And this is how we return that back inside explanation description 
({*}"description" : "match filter(_name: terms_filter): abc:\{1}"{*}):
{noformat}
 {
    "value": 35.0,
    "description": "function score, product of:",
    "details": [
        {
            "value": 1.0,
            "description": "match filter(_name: terms_filter): abc:{1}",
            "details": []
        },
        {
            "value": 35.0,
            "description": "product of:",
            "details": [
                {
                    "value": 1.0,
                    "description": "constant score 1.0 - no function provided",
                    "details": []
                },
                {
                    "value": 35.0,
                    "description": "weight",
                    "details": []
                }
            ]
        }
    ]
}{noformat}
Does it address  your concerns? Thanks a lot for taking a look!

> Add optional 'name' property to org.apache.lucene.search.Explanation 
> ---------------------------------------------------------------------
>
>                 Key: LUCENE-10432
>                 URL: https://issues.apache.org/jira/browse/LUCENE-10432
>             Project: Lucene - Core
>          Issue Type: Improvement
>    Affects Versions: 9.0, 8.10.1
>            Reporter: Andriy Redko
>            Priority: Minor
>
> Right now, the `Explanation` class has the `description` property which is 
> used pretty much as placeholder for free-style, human readable summary of 
> what is happening. This is totally fine but it would be great to have a bit 
> more formal way to link the explanation with corresponding function / query / 
> filter if supported by the underlying engine.
> Example: Opensearch / Elasticseach has the concept of named queries / filters 
> [1]. This is not supported by Apache Lucene at the moment but it would be 
> helpful to propagate this information back as part of Explanation tree, for 
> example by introducing  optional 'name' property:
>  
> {noformat}
> {    
>     "value": 0.0,    
>     "description": "script score function, computed with script: ...",        
>  
>     "name": "script1",
>     "details": [        
>      {            
>          "value": 1.0,            
>          "description": "_score: ",            
>          "details": [                
>               {                    
>                   "value": 1.0,                    
>                   "description": "*:*",                    
>                   "details": []                
>                }            
>           ]        
>       }    
>     ]
> }{noformat}
>  
> From the other side, the `name` property may look like not belonging here, 
> the alternative suggestion would be to add support of `properties` /  
> `parameters` / `tags` key/value bag, for example:
>  
> {noformat}
> {    
>     "value": 0.0,    
>     "description": "script score function, computed with script: ...",        
>  
>     "tags": [
>        {  "name": "script1" }
>     ],
>     "details": [        
>      {            
>          "value": 1.0,            
>          "description": "_score: ",            
>          "details": [                
>               {                    
>                   "value": 1.0,                    
>                   "description": "*:*",                    
>                   "details": []                
>                }            
>           ]        
>       }    
>     ]
> }{noformat}
> The change should be non-breaking but quite useful for engines to enrich the 
> `Explanation` with additional context.
> [1] 
> https://www.elastic.co/guide/en/elasticsearch/reference/7.16/query-dsl-bool-query.html#named-queries
>  



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org
For additional commands, e-mail: issues-h...@lucene.apache.org

Reply via email to