<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head> 
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 
        <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0"> 
        <base href="https://hibernate.atlassian.net"> 
        <title>Message Title</title> 
    </head> 
    <body class="jira" style="color: #333333; font-family: Arial, sans-serif; font-size: 14px; line-height: 1.429"> 
        <table id="background-table" cellpadding="0" cellspacing="0" width="100%" style="border-collapse: collapse; mso-table-lspace: 0; mso-table-rspace: 0; background-color: #f5f5f5; border-collapse: collapse; mso-table-lspace: 0; mso-table-rspace: 0" bgcolor="#f5f5f5"> 
            <!-- header here --> 
            <tbody>
                <tr> 
                    <td id="header-pattern-container" style="padding: 0; border-collapse: collapse; padding: 10px 20px"> 
                        <table id="header-pattern" cellspacing="0" cellpadding="0" border="0" style="border-collapse: collapse; mso-table-lspace: 0; mso-table-rspace: 0"> 
                            <tbody>
                                <tr> 
                                    <td id="header-avatar-image-container" valign="top" style="padding: 0; border-collapse: collapse; vertical-align: top; width: 32px; padding-right: 8px" width="32"> <img id="header-avatar-image" class="image_fix" src="cid:jira-generated-image-avatar-a85e6422-d5f9-42fa-9856-735ddac61e01" height="32" width="32" border="0" style="border-radius: 3px; vertical-align: top"> </td> 
                                    <td id="header-text-container" valign="middle" style="padding: 0; border-collapse: collapse; vertical-align: middle; font-family: Arial, sans-serif; font-size: 14px; line-height: 20px; mso-line-height-rule: exactly; mso-text-raise: 1px"> <a class="user-hover" rel="fenrhil" id="email_fenrhil" href="https://hibernate.atlassian.net/secure/ViewProfile.jspa?name=fenrhil" style="color:#6c797f;; color: #3b73af; text-decoration: none">Yoann Rodière</a> <strong>commented</strong> on <a href="https://hibernate.atlassian.net/browse/HSEARCH-1872" style="color: #3b73af; text-decoration: none"><img src="cid:jira-generated-image-avatar-4e39ea37-bccf-4a95-a791-e7c7c37efedc" height="16" width="16" border="0" align="absmiddle" alt="New Feature"> HSEARCH-1872</a> </td> 
                                </tr> 
                            </tbody>
                        </table> </td> 
                </tr> 
                <tr> 
                    <td id="email-content-container" style="padding: 0; border-collapse: collapse; padding: 0 20px"> 
                        <table id="email-content-table" cellspacing="0" cellpadding="0" border="0" width="100%" style="border-collapse: collapse; mso-table-lspace: 0; mso-table-rspace: 0; border-spacing: 0; border-collapse: separate"> 
                            <tbody>
                                <tr> 
                                    <!-- there needs to be content in the cell for it to render in some clients --> 
                                    <td class="email-content-rounded-top mobile-expand" style="padding: 0; border-collapse: collapse; color: #ffffff; padding: 0 15px 0 16px; height: 15px; background-color: #ffffff; border-left: 1px solid #cccccc; border-top: 1px solid #cccccc; border-right: 1px solid #cccccc; border-bottom: 0; border-top-right-radius: 5px; border-top-left-radius: 5px; height: 10px; line-height: 10px; padding: 0 15px 0 16px; mso-line-height-rule: exactly" height="10" bgcolor="#ffffff">&nbsp;</td> 
                                </tr> 
                                <tr> 
                                    <td class="email-content-main mobile-expand " style="padding: 0; border-collapse: collapse; border-left: 1px solid #cccccc; border-right: 1px solid #cccccc; border-top: 0; border-bottom: 0; padding: 0 15px 0 16px; background-color: #ffffff" bgcolor="#ffffff"> 
                                        <table class="page-title-pattern" cellspacing="0" cellpadding="0" border="0" width="100%" style="border-collapse: collapse; mso-table-lspace: 0; mso-table-rspace: 0"> 
                                            <tbody>
                                                <tr> 
                                                    <td style="vertical-align: top;; padding: 0; border-collapse: collapse; padding-right: 5px; font-size: 20px; line-height: 30px; mso-line-height-rule: exactly" class="page-title-pattern-header-container"> <span class="page-title-pattern-header" style="font-family: Arial, sans-serif; padding: 0; font-size: 20px; line-height: 30px; mso-text-raise: 2px; mso-line-height-rule: exactly; vertical-align: middle"> <a href="https://hibernate.atlassian.net/browse/HSEARCH-1872" style="color: #3b73af; text-decoration: none">Re: Create a proper API for sorting definitions</a> </span> </td> 
                                                </tr> 
                                            </tbody>
                                        </table> </td> 
                                </tr> 
                                <tr> 
                                    <td id="text-paragraph-pattern-top" class="email-content-main mobile-expand  comment-top-pattern" style="padding: 0; border-collapse: collapse; border-left: 1px solid #cccccc; border-right: 1px solid #cccccc; border-top: 0; border-bottom: 0; padding: 0 15px 0 16px; background-color: #ffffff; border-bottom: none; padding-bottom: 0" bgcolor="#ffffff"> 
                                        <table class="text-paragraph-pattern" cellspacing="0" cellpadding="0" border="0" width="100%" style="border-collapse: collapse; mso-table-lspace: 0; mso-table-rspace: 0; font-family: Arial, sans-serif; font-size: 14px; line-height: 20px; mso-line-height-rule: exactly; mso-text-raise: 2px"> 
                                            <tbody>
                                                <tr> 
                                                    <td class="text-paragraph-pattern-container mobile-resize-text " style="padding: 0; border-collapse: collapse; padding: 0 0 10px"> <p style="margin: 10px 0 0; margin-top: 0">Taking on the work of Emmanuel, I'm now working on this on my own branch (<a href="https://github.com/yrodiere/hibernate-search/tree/HSEARCH-1872" class="external-link" rel="nofollow" style="color: #3b73af; text-decoration: none">https://github.com/yrodiere/hibernate-search/tree/HSEARCH-1872</a>).<br> I just created <span class="jira-issue-macro" data-jira-key="HSEARCH-2320"> 
                                                                <!-- replace the span with an AUI template --> <a href="https://hibernate.atlassian.net/browse/HSEARCH-2320" class="jira-issue-macro-key issue-link" title="Add more specific sorts to the sort DSL" style="color: #3b73af; text-decoration: none"> <img class="icon" src="https://hibernate.atlassian.net/secure/viewavatar?size=xsmall&amp;avatarId=12151&amp;avatarType=issuetype"> HSEARCH-2320 </a> <span class="aui-lozenge aui-lozenge-subtle aui-lozenge-complete jira-macro-single-issue-export-pdf" style="background: #cccccc; border: 1px solid #cccccc; border-radius: 3px; color: #333333; display: inline-block; font-size: 11px; font-weight: bold; line-height: 99%; margin: 0; padding: 2px 5px; text-align: center; text-decoration: none; text-transform: uppercase; background-color: #ffffff; border-color: #cccccc; color: #333333" bgcolor="#ffffff">Open</span> </span> for everything that will be addressed later on (see the ticket for details). We can always create sub-tasks when the time comes to address those.</p> <p style="margin: 10px 0 0">Summing up, here is the remaining work:</p> 
                                                        <ul> 
                                                            <li>Making things work in -engine (the tests are failing right now)</li> 
                                                            <li>Ensuring things work in -elasticsearch</li> 
                                                            <li>Using proper exceptions</li> 
                                                            <li>Taking some decisions (see below)</li> 
                                                        </ul> <p style="margin: 10px 0 0">Below are the subjects on which we should take decisions.</p> <h3 style="margin: 10px 0 0; font-size: 16px; line-height: 1.563; margin: 30px 0 0"><a name="WhereisthisAPIgoing%3F" style="color: #3b73af; text-decoration: none"></a>Where is this API going?</h3> <p style="margin: 10px 0 0">Is this API going to be, on the long term:</p> 
                                                        <ol> 
                                                            <li>an independent way of building <tt>org.apache.lucene.search.Sort</tt> objects, that will later be provided when executing a query?</li> 
                                                            <li>an independent way of building <tt>HibernateSearch</tt>-defined sort objects (say, <tt>HSSort</tt>, like the <tt>HSQuery</tt>), that will later be provided when executing a <tt>HSQuery</tt>?</li> 
                                                        </ol> <p style="margin: 10px 0 0">Solution 1 seems workable, since the ElasticSearch module currently converts Sort objects to its internal representation, but <a href="https://github.com/hibernate/hibernate-search/pull/1132#discussion_r72257755" class="external-link" rel="nofollow" style="color: #3b73af; text-decoration: none">this discussion</a> makes me doubt that reliance on Lucene types is a long-term objective.<br> Solution 2 also seems workable, but would be part of a larger work on HibernateSearch APIs, which I'm not aware of (yet).</p> <h3 style="margin: 10px 0 0; font-size: 16px; line-height: 1.563; margin: 30px 0 0"><a name="IsthisAPIgoingtosupportnativesorts%3F" style="color: #3b73af; text-decoration: none"></a>Is this API going to support native sorts?</h3> <p style="margin: 10px 0 0">See the discussion here: <a href="https://github.com/hibernate/hibernate-search/pull/1132#discussion_r72258266" class="external-link" rel="nofollow" style="color: #3b73af; text-decoration: none">https://github.com/hibernate/hibernate-search/pull/1132#discussion_r72258266</a></p> <p style="margin: 10px 0 0">In my opinion, supporting native sorts in this API would be a bit annoying, because the API is currently returning <tt>org.apache.lucene.search.Sort</tt>, which is not at all a good fit for putting ElasticSearch JSON sort definitions in it. We could either work it around (having a specific <tt>SortField</tt> with a JSON string in it, and a dummy field name), which seems a bit messy, or convert the JSON to a <tt>SortField</tt>, which would defeat the purpose of allowing to provide native JSON in the first place, since it would prevent users from using ElasticSearch features not yet supported in HibernateSearch.</p> <p style="margin: 10px 0 0">Also, the API will IMO be less elegant, since we'll have a method that accept a parameter whose content (be it a plain String or an object) is not clearly constrained. That would normally be a good candidate for a type parameter (<tt>TNativeSort</tt>), but given the way we obtain the sort builder, we cannot have an implementation-dependent type parameter. So whatever we do, we won't be able to get much better than exposing a <tt>byNative(Object)</tt> method that tells close to nothing to the user. A shame for a <b>domain-specific</b> language.</p> <p style="margin: 10px 0 0">Maybe we should take the problem the other way around: somewhere in the ElasticSearch module, allow for concatenation of DSL-built sorts and plain JSON strings? Or, maybe, add setSort(Sort ... fields) methods to queries, and add something </p> <h3 style="margin: 10px 0 0; font-size: 16px; line-height: 1.563; margin: 30px 0 0"><a name="Shouldwekeep%7B%7BandByIndexOrder%7D%7D%2F%7B%7BandByScore%7D%7D" style="color: #3b73af; text-decoration: none"></a>Should we keep <tt>andByIndexOrder</tt>/<tt>andByScore</tt></h3> <p style="margin: 10px 0 0">Those should remain, IMO, because:</p> 
                                                        <ol> 
                                                            <li>Implementation is trivial (as long as Lucene supports that kind of sorts, which seems likely)</li> 
                                                            <li>They <b>might</b> be useful, particularly <tt>andByScore</tt>. I've provided a use case in the tests: sorting first by a field for which many documents have the same value (a category), and only then by relevance. So you'll have blocks of results, with the elements in each block being sorted by relevance. Granted, it's exotic, but business users are definitely able to come up with such a use case. And when business users want that kind of things in their whole application, it's frustrating being prevented from using the DSL for such a minor detail.</li> 
                                                            <li>Removing them would go against the principle of least surprise. If everything we provide as <tt>by*</tt> method is also provided as <tt>andBy*</tt> method, why not those two?</li> 
                                                        </ol> <h3 style="margin: 10px 0 0; font-size: 16px; line-height: 1.563; margin: 30px 0 0"><a name="Shouldwekeep%7B%7Bin%28Unit%29%7D%7D" style="color: #3b73af; text-decoration: none"></a>Should we keep <tt>in(Unit)</tt></h3> <p style="margin: 10px 0 0">I'd say we should not keep this in the DSL, since it's not supported out-of-the-box for vanilla Lucene queries. All methods in the DSL should be implemented for every backend.<br> Maybe we can create another ticket for adding that kind of feature to locale Lucene indexes. Anyone find this useful?</p> <h3 style="margin: 10px 0 0; font-size: 16px; line-height: 1.563; margin: 30px 0 0"><a name="Isthe%7B%7BbyDistanceFromSpatialQuery%28Query%29%7D%7Dmethodmakingsense" style="color: #3b73af; text-decoration: none"></a>Is the <tt>byDistanceFromSpatialQuery(Query)</tt> method making sense</h3> <p style="margin: 10px 0 0">The point of this method would be to take a query distance (distance to these coordinates must be below 1km, for instance), extract the point from it, and create a sort by distance to this point.</p> <p style="margin: 10px 0 0">On the plus side, this relieves the user from passing the reference coordinates twice.<br> On the minus side, the method could break at runtime: we ask for a <tt>Query</tt>, which may or may not have a distance filter, and as such introduces new ways for users to make things explode.</p> <p style="margin: 10px 0 0">I wonder if it's such a great pain to provide the coordinates twice. Isn't it how it's done almost everywhere? I mean, when you write an ElasticSearch query by hand, or a SolR query, you also have to provide these coordinates twice. Besides, we're only changing the thing to provide twice, here: instead of providing the coordinates to HS twice, we provide the <b>query</b> to HS twice...</p> <p style="margin: 10px 0 0">I don't see any way to do it better than this, so I'd say we drop it. It's not implemented yet, anyway.</p> <h3 style="margin: 10px 0 0; font-size: 16px; line-height: 1.563; margin: 30px 0 0"><a name="Dowewanttosupportsortingonunmappedfields" style="color: #3b73af; text-decoration: none"></a>Do we want to support sorting on unmapped fields</h3> <p style="margin: 10px 0 0">When querying multiple indices at once, it may happen that some field we're sorting on is absent from one of the indices. In that case, ElasticSearch requires that <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-sort.html#_ignoring_unmapped_fields" class="external-link" rel="nofollow" style="color: #3b73af; text-decoration: none">type information be provided</a>.<br> So in that case, we may have to retrieve type information from the metamodel. Problem: the <tt>QueryBuilder</tt>, from which we start building the sort, is only aware of <b>one</b> entity we're working on. This might be something to fix, because queries built this way may (and will) still be ran against multiple indices, but that's another matter.<br> So, let's say the user is querying two indices: <tt>A</tt>(fields: <tt>z</tt>, <tt>a1</tt>, <tt>a2</tt>), <tt>B</tt> (fields: <tt>z</tt>, <tt>b1</tt>, <tt>b2</tt>), and he wants to sort on <tt>z</tt>, then <tt>a1</tt>, then <tt>b1</tt>. The user won't be able to build his sort with the <tt>QueryBuilder</tt>, since whichever entity he chooses to bind his <tt>QueryBuilder</tt> to, there would be some missing type information at some point (for either the <tt>a1</tt> field or the <tt>b1</tt> field).</p> <p style="margin: 10px 0 0">Now, we can decide either to drop support for that kind of sort in the DSL (and that should be documented), or to provide support for {{QueryBuilder}}s spanning multiple types (say, they would use the first type definition they find on any of the entities they would be bound to). Or both.</p> <p style="margin: 10px 0 0">Any thoughts would be greatly appreciated!</p> </td> 
                                                </tr> 
                                            </tbody>
                                        </table> </td> 
                                </tr> 
                                <tr> 
                                    <td class="email-content-main mobile-expand " style="padding: 0; border-collapse: collapse; border-left: 1px solid #cccccc; border-right: 1px solid #cccccc; border-top: 0; border-bottom: 0; padding: 0 15px 0 16px; background-color: #ffffff" bgcolor="#ffffff"> 
                                        <table id="actions-pattern" cellspacing="0" cellpadding="0" border="0" width="100%" style="border-collapse: collapse; mso-table-lspace: 0; mso-table-rspace: 0; font-family: Arial, sans-serif; font-size: 14px; line-height: 20px; mso-line-height-rule: exactly; mso-text-raise: 1px"> 
                                            <tbody>
                                                <tr> 
                                                    <td id="actions-pattern-container" valign="middle" style="padding: 0; border-collapse: collapse; padding: 10px 0 10px 24px; vertical-align: middle; padding-left: 0"> 
                                                        <table align="left" style="border-collapse: collapse; mso-table-lspace: 0; mso-table-rspace: 0"> 
                                                            <tbody>
                                                                <tr> 
                                                                    <td class="actions-pattern-action-icon-container" style="padding: 0; border-collapse: collapse; font-family: Arial, sans-serif; font-size: 14px; line-height: 20px; mso-line-height-rule: exactly; mso-text-raise: 0; vertical-align: middle"> <a href="https://hibernate.atlassian.net/browse/HSEARCH-1872#add-comment" target="_blank" title="Add Comment" style="color: #3b73af; text-decoration: none"> <img class="actions-pattern-action-icon-image" src="cid:jira-generated-image-static-comment-icon-1be5fa67-79a0-4040-8641-f4fe2fc34b5f" alt="Add Comment" title="Add Comment" height="16" width="16" border="0" style="vertical-align: middle"> </a> </td> 
                                                                    <td class="actions-pattern-action-text-container" style="padding: 0; border-collapse: collapse; font-family: Arial, sans-serif; font-size: 14px; line-height: 20px; mso-line-height-rule: exactly; mso-text-raise: 4px; padding-left: 5px"> <a href="https://hibernate.atlassian.net/browse/HSEARCH-1872#add-comment" target="_blank" title="Add Comment" style="color: #3b73af; text-decoration: none">Add Comment</a> </td> 
                                                                </tr> 
                                                            </tbody>
                                                        </table> </td> 
                                                </tr> 
                                            </tbody>
                                        </table> </td> 
                                </tr> 
                                <!-- there needs to be content in the cell for it to render in some clients --> 
                                <tr> 
                                    <td class="email-content-rounded-bottom mobile-expand" style="padding: 0; border-collapse: collapse; color: #ffffff; padding: 0 15px 0 16px; height: 5px; line-height: 5px; background-color: #ffffff; border-top: 0; border-left: 1px solid #cccccc; border-bottom: 1px solid #cccccc; border-right: 1px solid #cccccc; border-bottom-right-radius: 5px; border-bottom-left-radius: 5px; mso-line-height-rule: exactly" height="5" bgcolor="#ffffff">&nbsp;</td> 
                                </tr> 
                            </tbody>
                        </table> </td> 
                </tr> 
                <tr> 
                    <td id="footer-pattern" style="padding: 0; border-collapse: collapse; padding: 12px 20px"> 
                        <table id="footer-pattern-container" cellspacing="0" cellpadding="0" border="0" style="border-collapse: collapse; mso-table-lspace: 0; mso-table-rspace: 0"> 
                            <tbody>
                                <tr> 
                                    <td id="footer-pattern-text" class="mobile-resize-text" width="100%" style="padding: 0; border-collapse: collapse; color: #999999; font-size: 12px; line-height: 18px; font-family: Arial, sans-serif; mso-line-height-rule: exactly; mso-text-raise: 2px"> This message was sent by Atlassian JIRA <span id="footer-build-information">(v1000.245.0#100009-<span title="7349d1fc3a9a977533e445e375df6c80ccb95983" data-commit-id="7349d1fc3a9a977533e445e375df6c80ccb95983}">sha1:7349d1f</span>)</span> </td> 
                                    <td id="footer-pattern-logo-desktop-container" valign="top" style="padding: 0; border-collapse: collapse; padding-left: 20px; vertical-align: top"> 
                                        <table style="border-collapse: collapse; mso-table-lspace: 0; mso-table-rspace: 0"> 
                                            <tbody>
                                                <tr> 
                                                    <td id="footer-pattern-logo-desktop-padding" style="padding: 0; border-collapse: collapse; padding-top: 3px"> <img id="footer-pattern-logo-desktop" src="cid:jira-generated-image-static-footer-desktop-logo-e7bf042a-69c8-42e0-8334-fc4a4d11cfc1" alt="Atlassian logo" title="Atlassian logo" width="169" height="36" class="image_fix"> </td> 
                                                </tr> 
                                            </tbody>
                                        </table> </td> 
                                </tr> 
                            </tbody>
                        </table> </td> 
                </tr> 
            </tbody>
        </table>   
    </body>
</html>