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

Benoit Tellier commented on JAMES-3421:
---------------------------------------

There is more work needed on this topic as mailbox/api SortClause have no 
support for flag based sorting - it is not just changes at the JMAP layer.

This means:

 - the mailbox/api SortClause needs to be adapted to a collection of POJO that 
could cary over the information on the underlying flag.
 - the flag sorting logic will need to be implemented for the scrolling, lucene 
and ElasticSearch search backends
 - the easy part is to add a 'keyword' field within the Comparator JMAP POJO, 
and pass it as an argument when generating the mailbox POJOs.

Some code samples... API proposal for SortClause evolution:


{code:java}
interface SortClause {}

class SentDateSortClause extends SortClause {}

...
class FlagSortClause extends SortClause {
    private final Flag flag;
}

class UserFlagSortClause extends SortClause {
    private final String userFlag;
}
{code}

The implementations would likely needs calls to instanceof to be matching 
SortClause with the underlying sort implementation (like we do for the query 
convertion?)

Here is how the JMAP bits would look like:

{code:java}
sealed trait SortProperty {
  def toSortClause(keyword: Option[Keyword]): Either[UnsupportedSortException, 
SortClause]
}
case object ReceivedAtSortProperty extends SortProperty {
  override def toSortClause(keyword: Option[Keyword]): 
Either[UnsupportedSortException, SortClause] = scala.Right(SortClause.Arrival)
}
//...
case object HasKeywordSortProperty extends SortProperty {
  override def toSortClause(keyword: Option[Keyword]): 
Either[UnsupportedSortException, SortClause] = {
    keyword.fold(
      () => Left(new InvalidArgumentException("keyword property of the 
comparator object is compulsary when using hasKeyword sort")),
      keywordValue => scala.Right(SortClause.keywordValue(keyword.asFlag))
    )
    Left(UnsupportedSortException("hasKeyword"))
  }
}

case class Comparator(property: SortProperty,
                      isAscending: Option[IsAscending],
                      collation: Option[Collation],
                      keyword: Option[Keyword]) {
  def toSort: Either[UnsupportedSortException, SearchQuery.Sort] =
    for {
      sortClause <- property.toSortClause(keyword)
    } yield new SearchQuery.Sort(sortClause, 
isAscending.getOrElse(ASCENDING).toSortOrder)
}
{code}


> Email/Query sort by hasKeyword
> ------------------------------
>
>                 Key: JAMES-3421
>                 URL: https://issues.apache.org/jira/browse/JAMES-3421
>             Project: James Server
>          Issue Type: Sub-task
>          Components: JMAP
>            Reporter: Benoit Tellier
>            Assignee: Antoine Duprat
>            Priority: Major
>
> = WHY 
> With the new specifications as an user i want to be able to sort the emails 
> by the presence of a given keyword
> `hasKeyword - This value MUST be considered true if the Email has the keyword 
> given as an additional keyword property on the Comparator object, or false 
> otherwise.
> `
> Here is the query to display first the emails containing the 'james' keyword.
> {code:java}
> [[ "Email/query",{
>   "accountId": "ue150411c",
>   "sort" : {
>       "property": "hasKeyword",
>       "keyword": "james",
>       "isAscending": true
> }
> }, "0" ]]
> {code}
> = HOW
> - accept the 'hasKeyword' value in the 'property' field of the sort field of 
> the request.
> = DOD
> - write an integration test demonstrating the sorting of the result by 
> 'hasKeyword' in both ascending and descending order



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to