Hi Seshika,

This is an optional field. Since we support pagination, you can get sorted
records with multiple pages. This optional parameter is provided for
listing the records in the reversed order for a specific page.
For example, lets say we want to get the 2nd (2nd page) top 10 users who
has the highest success logins and we want that specific page to be
displayed in ascending order. Then we provide the parameters,"sortType
:DESC, reversed :true". This may not be much useful for ASC and DESC, but
DAS can also sort by the time at which the record was indexed (this is
different from the _timestamp in streams), and sort by search query
matching score.
Using those two sortTypes, we can get the records by least matching docs(
using "sortType": "DOC_SCORE", "reversed" :true) for a specific query or
most recently indexed docs ( using "sortType" : "INDEX_TIME", "reversed" :
true). I haven't added those two types yet. In those two types, "reversed"
parameter will be useful. "reversed" is an optional parameter and its
default value is false.

On Tue, Mar 29, 2016 at 11:13 AM, Seshika Fernando <[email protected]> wrote:

> Hi Gimantha,
>
> This is a very useful functionality. Thanks for adding this. I have 1
> question. Can you tell me the difference of result between the following 2
> combinations.
>
>     "sortType" : "DESC"
>     "reversed" : false
>
> and
>
>     "sortType" : "ASC"
>     "reversed" : true
>
> My query is, that if you can do either ASC or DESC, why do you need a
> separate parameter to reverse the order? What am I missing?
>
> seshi
>
> On Wed, Mar 16, 2016 at 6:21 PM, Gimantha Bandara <[email protected]>
> wrote:
>
>> Hi all,
>>
>> We have two methods in AnalyticsDataService namely "search" and
>> "getDrillDownRecords". These two methods returns record Ids sorted by the
>> Relevance score ( Relevance score is generated by Lucene at the search
>> time. Record ids that match most with the given search query will have a
>> higher score and will be the first records that comes first in the result
>> list). With the new sorting functionality, the matching records can be
>> retrieved either descending or ascending sort order of a specific field/s.
>>
>> Followings are the new search methods added to AnalyticsDataService.
>>
>> List<SearchResultEntry> search(int tenantId, String tableName, String
>> query, int start, int count, *List<SortByField> sortByFields*) throws
>> AnalyticsException
>> List<SearchResultEntry> drillDownSearch(int tenantId,
>> AnalyticsDrillDownRequest request) throws AnalyticsIndexException
>>
>> The last parameter to search method is srotByField. This is a list which
>> contains the fields by which the users wants to sort the records.
>> SortByField class will have the 3 attributes, fieldName, sortType,
>> isReversed.
>>
>> 1. *fieldName* is the field by which the records need to be sorted.
>> 2. *sortType* is either SORT.ASC or SORT.DESC (Denotes ascending or
>> descending)
>> 3. *isRevesed* says whether the sorted records need to be returned
>> reversed in order or not. (optional)
>>
>> Search APIs take a list of SortByFields, which means the records can be
>> sorted by multiple fields. Records will be sorted by the second SortByField
>> if the value for the first SortByField is same.
>>
>>
>>
>>
>> *REST APIs*
>>
>>
>> *Search*
>> Analytics REST call[1] now has an additional parameter call "sortBy" to
>> support sorting. A sample request payload will look like below.
>>
>> POST https://localhost:9443/analytics/search
>>
>> {
>>  "tableName" : "Students",
>>   "query" : "Grade:10",
>>  "start" : 0,
>>  "count" : 100,
>>   "sortBy" : [{
>>     "field" : "totalScore",
>>     "sortType" : "DESC" //can be DESC or ASC
>>     "reversed" : false //optional
>>   }]
>> }
>>
>> Above will return the matching records sorted by totalScore field in
>> descending order.
>>
>>
>>
>> *Drilldown*
>> Drilldown API[2] also supports sorting. Following is a sample request on
>> how to sort the students whose City is Colombo and who are in Grade 10 in
>> descending order.
>>
>> POST https://localhost:9443/analytics/drilldown
>>
>> {
>>    "tableName":"Students",
>>    "categories":[
>>       {
>>          "fieldName":"location",
>>          "path":["Sri Lanka", "Colombo]
>>       }
>>    ],
>>    "query":"Grade:10",
>>    "recordCount":100,
>>    "sortBy":[
>>       {
>>          "field":"totalScore",
>>          "sortType":"DESC"
>>       }
>>    ]
>> }
>>
>>
>>
>> *Javascript APIs*
>>
>> Javascript APIs is used at client side for custom development based on
>> DAS.
>>
>> *Search*
>>
>> Search method[3] in Javascript APIs has an additional parameter to pass
>> sort information to get sorted records. Following is a sample JS call to
>> get sorted records.
>>
>> var queryInfo = {
>>                tableName : "Students",
>>                searchParams : {
>>                    query : "Grade : 10",
>>                    start : 0,
>>                    count : 100,
>>                    sortBy : [
>>                      {
>>                        field : "totalScore",
>>                        sortType : "DESC", // This can be ASC, DESC
>>                        reversed : "false" //optional
>>                      }
>>                    ]
>>                }
>>            };
>>
>> client.search(queryInfo, function(data) {
>>         console.log (data["message"]);
>> }, function(error) {
>>         console.log("error occured: " + error["message"]);
>> });
>>
>>
>> *DrillDown*
>> Using DrillDown API[4] in JS APIs, we can achieve the same as REST
>> DrillDown API. Following is a sample request on how to sort the students
>> whose City is Colombo and who are in Grade 10 in descending order.
>>
>> var drillDownReq = {
>>                tableName : "Students",
>>                drillDownInfo : {
>>                    categories : [
>>                     {
>>                        fieldName : "location",
>>                        path : ["Srilanka", "Colombo"]
>>                    }]
>>                    query : "Grade : 10",
>>                    recordStart : 0,
>>                    recordCount : 100,
>>                    sortBy : [
>>                      {
>>                        field : "totalScore",
>>                        sortType : "DESC", // This can be ASC, DESC
>>                        reversed : "false" //optional
>>                      }
>>                    ]
>>                };
>>
>> client.drillDownSearch(drillDownReq, function(data) {
>>       console.log (data["message"]);
>> }, function(error) {
>>       console.log("error occured: " + error);
>> });
>>
>> Please note that the fields that you wants records to be sorted by, need
>> to be indexed beforehand.
>>
>> [1]
>> https://docs.wso2.com/display/DAS301/Retrieving+Specific+Records+through+a+Drill+Down+Search+via+REST+API
>> [2]
>> https://docs.wso2.com/display/DAS301/Retrieving+All+Records+Matching+the+Given+Search+Query+via+REST+API
>> [3]
>> https://docs.wso2.com/display/DAS301/Retrieving+All+Records+Matching+the+Given+Search+Query+via+JS+API
>> [4]
>> https://docs.wso2.com/display/DAS301/Retrieving+Specific+Records+through+a+Drill+Down+Search+via+JS+API
>>
>> --
>> Gimantha Bandara
>> Software Engineer
>> WSO2. Inc : http://wso2.com
>> Mobile : +94714961919
>>
>> _______________________________________________
>> Architecture mailing list
>> [email protected]
>> https://mail.wso2.org/cgi-bin/mailman/listinfo/architecture
>>
>>
>
> _______________________________________________
> Architecture mailing list
> [email protected]
> https://mail.wso2.org/cgi-bin/mailman/listinfo/architecture
>
>


-- 
Gimantha Bandara
Software Engineer
WSO2. Inc : http://wso2.com
Mobile : +94714961919
_______________________________________________
Architecture mailing list
[email protected]
https://mail.wso2.org/cgi-bin/mailman/listinfo/architecture

Reply via email to