sort by date in caml query - sharepoint

I want to sort my list items by date:
I m using
<OrderBy><FieldRef Name='SortDate' Ascending='True'/></Order By>
but its giving me results randomly.Is it possible to sort by date in CAML if not then if there is any other way to retrieve list items sorted on the basis of date....

Yes you can sort by date using CAML. To test it out try sorting on the Modified field to see if that gets you better results. Is your SortDate field an actual DateTime field, or is it something else like a string?

Related

solr query to sort result in descending order on basis of price

I am very beiginer in Solr and I am trying to do query on my data. I am trying to find data with name=plant and sort it by maximum price
my schema for both name and price is text type.
for eg let say data is
name:abc, price:25;
name:plant, price:35;
name:plant,price:45; //1000 other data
My Approach
/query?q=(name:"Plant")&stopwords=true
but above is giving me result of plants but I am not sure how to sort result using price feild
Any help will be appreciated
You can use the sort param for achieving the sorting.
Your query would be like q=(name:"Plant")&sort=price desc
The sort parameter arranges search results in either ascending (asc)
or descending (desc) order. The parameter can be used with either
numerical or alphabetical content. The directions can be entered in
either all lowercase or all uppercase letters (i.e., both asc or ASC).
Solr can sort query responses according to document scores or the
value of any field with a single value that is either indexed or uses
DocValues (that is, any field whose attributes in the Schema include
multiValued="false" and either docValues="true" or indexed="true" – if
the field does not have DocValues enabled, the indexed terms are used
to build them on the fly at runtime), provided that:
the field is non-tokenized (that is, the field has no analyzer and its
contents have been parsed into tokens, which would make the sorting
inconsistent), or
the field uses an analyzer (such as the KeywordTokenizer) that
produces only a single term.

CouchDB view collation sorted by date

I am using a couchDB database.
I can get all documents by category and paginate results with a key like ["category","document_id"]and a query likestartkey=["category","document_id"]&endkey=["category",{}]`
Now I want to sort those results by date to have latest documents first.
I tried a lot of keys such as ["category","date","document_id"]
but nothing works (or I can't get it working).
I would use something like
startkey=["queried_category","queried_date","queried_document_id"]&endkey=["queried_category"]
but ignore the "queried_date" key part (sort but do not take documents where "document_id" > "queried_document_id")
EDIT:
Example :
With a key like :
startkey=["apple","2012-12-27","ZZZ"]&endkey=["apple",{}]&descending=true
I will have (and it is the normal behavior)
"apple","2012-12-27","ABC"
"apple","2012-05-01","EFG"
...
"apple","2012-02-13","ZZZ"
...
But the result set I want should start with
"apple","2012-02-13","ZZZ"
Emit the category and the timestamp (you don't need the document_id):
emit(category, timestamp);
And then filter on the category:
?startkey=[":category"]&endkey=[":category",{}]
You must understand that this is only a sort, so you need the startkey to be before the first row, and the endkey to be after the last row.
Last but not least, don't forget to have a representation for the timestamp that is adequate to the sort.
The problem with pagination with timestamp instead of doc ID is that timestamp is not unique. That's why you will have problem with paging Aurélien's solution.
I would stay with what you tried but use timestamp as the number (standard UNIX milliseconds since 1970). You can reverse the order of single numeric field just by multiplying by -1:
emit(category, -timestamp, doc_id)
This way result sorted lexicographically (ascending) will be ordered according to your needs:
first dates descending,
then document id's ascending.

How to sort by date in SOLR?

I want to sort the results and scores returning from SOLR search,how I can get scores based on date like below:
Suppose for keywords "football"
12-10-2012 - 3.2
13-10-2012 - 1.5
My solr date filed lis like below:
<field name="published_date" datetimeformat="dd-MM-yyyy" type="date" indexed="true" stored="true"/>
I checked this docs but couldn't find that.
Thanks.
You can pass the sort parameter in the URL
e.g. sort=published_date desc for documents by published date in descending order.
If you want to sort by score and date you can use sort=score desc, published_date desc
taken from the wiki
Although not technically a Syntax difference, please note that if you use
the Solr "DateField" type, any queries on those fields (typically range queries)
should use either the Complete ISO 8601 Date syntax that field supports,
or the DateMath Syntax to get
relative dates. Examples:
timestamp:[* TO NOW]
createdate:[1976-03-06T23:59:59.999Z TO *]
createdate:[1995-12-31T23:59:59.999Z TO 2007-03-06T00:00:00Z]
pubdate:[NOW-1YEAR/DAY TO NOW/DAY+1DAY]
createdate:[1976-03-06T23:59:59.999Z TO 1976-03-06T23:59:59.999Z+1YEAR]
createdate:[1976-03-06T23:59:59.999Z/YEAR TO 1976-03-06T23:59:59.999Z]
NOTE:TO must be uppercase, or Solr will report a 'Range Goop' error.
combine that with this and the job is done :) it's pretty easy, it just requires some tries in the beginning
a little edit: this method allows you to retrieve values based on a date range and apply a score boost to them according to their values. apparently you were asking help on how to retrieve sort on base score and date, so my answer isn't the 100% correct one

SharePoint - Auto-increment dates in new records?

I have a list that's going to be updated with relatively static data weekly, and I wanted to create a workflow to do this automatically. The only field I'm having trouble with is Start Date.
I want the new Start Date to be exactly one week after the previous week's (row's) Start Date, but I can't figure out how to capture this. I can't seem to find an easy way to get the value of the previous row.
Now, theoretically, I could just have the workflow run once a week on a given day and use [Today] as the value for the field; however, a requirement is that the list can be populated a few weeks in advance if needed.
Thanks in advance for any help you can provide!
You could solve this problem by creating a custom Field type that queries its parent list for the most recent item and set itself to be the desired date. MSDN has a number of decent references for how to create custom field types.
I recently did something akin to this: I created a "Unique Number" field type that will ensure that no two rows contain the same numerical value in the same column.
Why not just query the list and order by date descending. The first row returned is the previous week's date?
The CAML Query would look something like this:
<Query>
<OrderBy>
<FieldRef Name='Modified' Ascending='False' />
</OrderBy>
</Query>
I use U2U CAML Query Builder for syntax help...

Get Max Date Using CAML Query From alist

how can i get max Date and Min Date from a list Date Column
The brute force approach is to create two queries that will retrieve the list content sorted by date asc and desc. I know that this sucks but at least you can move on with you project and refine the query later on.
If only it was possible to retrieve top 1 then it might even work in production.

Resources