How can I order result set by function?
I would like order by
query({!dismax qf=ProfessionName v='"data scientist"~3'}) desc, SaveDate desc
SortOrder should use only for fields.
You must use SolrNet from github. SolrNet on Nuget was updated some years ago.
Related
My documents have these 2 fields:
status
open
upcoming
ended
end_date
Right now I'm sorting this way:
status_int ASC, end_date ASC (status_int is just a way to easily order by status open -> upcoming -> ended)
For open and upcoming events, I want to show the ones that end the soonest first, that's why I have end_date ASC. The issue is that it doesn't work well for ended events, as the user will get the events from 2010 for instance before the ones that ended in 2020.
So, I'd like to order by end_date ASC for documents that dont have the ended status, and end_date DESC for the ended ones.
Is it possible to change the order based on a document attribute?
On top of my head, an easy solution is to use streaming expressions, although the usability of them depends on some technical details (Solr version, your client implementation details etc.)
Start two search streams, one for documents which don't have the ended status, and one for others. You can specify different sort criterias for two different streams. Then merge those two streams. Something like:
list(
search(
yourCollection,
q="yourQuery",
qt="/export", //or "/select" based on your needs
fq="*:* AND NOT status:ended",
sort="end_date asc"
),
search(
yourCollection,
q="yourQuery",
qt="/export", //or "/select" based on your needs
fq="status:ended",
sort="end_date desc"
)
)
this will first return not-ended ones sorted by end_date asc, and after them status=ended ones sorted by end_date desc. You can also sort them again based on some other condition, or merge them differently based on your requirements.
Another simpler solution could be using function queries and pseudo fields, something along the lines of:
&fl=sortonthis:if(not(status=ended),rord(end_date),ord(end_date))&sort=sortonthis
asc
I didn't test but it should work with some tweaks.
If end_date is always in the future for events that haven't ended, you can probably make it work by using abs(ms(NOW, end_date)) - it'll give you a value that represents how far from the current date the end date is.
In my eloquent model, I have a location row. It holds 5 potential answers such as:
Hotel
Accommodation
Library
rest of the values
I want to perform an orderBy and want them to be listed as this order. Is there a way to achieve it with orderBy? Something like:
People::orderBy('location', ['Hotel, 'Library', 'Accommodation']);
What is the best way to achieve this?
So, you can achieve that by using:
People::orderByRaw("FIELD(location , 'Hotel, 'Library', 'Accommodation') ASC")
Of course, you may choose ASC or DESC.
I am trying to get all the orders under user. I am using below XPTAH query.
/jcr:root/home/users/a/admin/commerce/orders//element(*)[#orderId] this result below records :
/home/users/a/admin/commerce/orders/order-2014-Apr-12
/home/users/a/admin/commerce/orders/order-2015-Apr-15
/home/users/a/admin/commerce/orders/order-2015-Apr-13
Now i have requirements that order should be in the sorted order as per booked(that i am looking for) , Other is i will have dynamic parameter which will I pass through the method in which i have the XPTH query executed e.g. 6 or ALL . 6 will display the last 6 months order only (that i am looking for). For all orders i can use the query with sort condition /jcr:root/home/users/a/admin/commerce/orders//element(*)[#orderId] order by #orderPlaced descending . I have orderPlaced property of Date type 2014-04-12T17:05:35.085+05:30. So want to put condition result will include last 6 months.
Thanks
try the query-debugger located at /libs/cq/search/content/querydebug.html
it shows the query in different formats including xpath-syntax. for instance you get the ordering syntax by running this url:
querydebugger
This solved my problem :
type=unstructured
path=/home/users/a/admin/commerce/orders
path.flat=true
orderby=#orderPlaced
orderby.sort=desc
1_relativedaterange.property=orderPlaced
1_relativedaterange.lowerBound=-6M
1_relativedaterange.upperBound=0
This question already has answers here:
LINQ : Dynamic select
(12 answers)
Closed 8 years ago.
I'm working with dynamic queries using LINQ on Entity Framework.
To query some tables by user input filters, we are using PredicateBuilder to create conditional WHERE sections. That works really great, but the number of columns returned are fixed.
Now, if we need the user to select which columns he needs in their report, besides their filters, we are in trouble, as we don't know how to do dynamic myQuery.Select( x => new { ... }) as we do for Where clause.
How can we achieve something like this?
A bit of searching reveals that this is tricky. Anonymous types are created at compile time, so it is not easy to create one dynamically. This answer contains a solution using Reflection.emit.
If possible, I would recommend just returning something like a IDictionary<,> instead.
How would I sort a DataTable using Linq? I've tried the following but received the error:
InvalidCastException was unahndled by user code. Specified cast is not allowed.
var query = from c in allFiles.AsEnumerable() orderby c.Field<DateTime>(1)
descending select c;
That would suggest that for at least some row, field 1 isn't a DateTime. If it may be null, you might want to try DateTime? instead. Or check that it really is that field in the first place... maybe use a name instead of a number?
The table was dynamically generated and had no actual specified column dataType. When I created the column and specified the dataType the issue was resolved.
I'm not sure why I didn't realize the dataType wasn't defined until after I posted this question.