please look up
Get-Variable | Sort-Object -property Value
at your PowerShell prompt. You'll likely see that the values are all but sorted. There is kind of sorting, some blocks appear to have been sorted, but in between there are - at least in my PowerShell (V4) many items located at completely absurd positions.
Can anyone shed a light on why the Sort-Object fails in this case?
Thx
Armin.
The order between two objects of different types is not defined (unless explicitely defined). Thus, when you try to sort objects, you can’t really expect them to follow what you believe makes sense, or even any real logic.
If you convert them to a common type, e.g. by converting them to a string first, you will get a proper order:
Get-Variable | sort { [string] $_.Value }
The reason it has a hard time sorting the results of this as you would expect is because the values all have different data types. Even though what you are seeing is string values, each of these values has a specific data type such as string, integer, boolean and lots more. There is no consistent set of rules that will sort all of these values correctly. If you do the same with the variable names rather than with the values, you'll see a consistent sort - this is because the variable names are essentially string values and can easily be sorted alphabetically.
Related
Is there any way to ignore "stop words" while sorting.
For example:
I have words like
dixit
singla
the marklogic
On sorting in descending order the result should be
singla, the marklogic, dixit
As in the above example the is ignored.
Any way to achieve this?
Update:
Stop word can occur at any place.
for example
the MarkLogic
MarkLogic is the best
the MarkLogic is awesome
while sorting should not consider any stop word in the text.
Above is just a small example to describe the problem.
In actual I am using search:search API.
For sorting, I am using sort-order search options.
The element on which I have to perform sorting is dynamic. There are approx 30-35 elements.
Is there any way to customize the collation at this level like to configure some words (stop words) which will be ignored while sorting.
There is no standard collation URI that is going to do this for you (at least none that I've ever seen). You can do it dynamically, of course, by sorting on the result of a function invocation, but if you want it done efficiently at scale (and available to search:search), then you need to materialize the sortable string into your document. I've often done this as an attribute on the element:
<title sortable="Great Gatsby, The">The Great Gatsby</title>
Then you put a range index on the title/#sortable attribute.
You can also use the "envelope pattern" where materialized metadata like this is maintained in its own section of the document with the original kept in its own section. For things like this, I think it's a bit more elegant to decorate the elements directly, to keep the context.
If I understand your question correctly you're trying to get rid of the definite article when sorting your result-set.
In order to do this you need to use some additional functions and create a 'sort' criteria. My solution would look like this (I'm also including some sample documents so that you can test this just by copy-pasting):
(:
xdmp:document-insert("/peter.xml", <person><firstName>Peter</firstName><lastName>O'Toole</lastName><age>60</age></person>);
xdmp:document-insert("/john.xml", <person><firstName>John</firstName><lastName>Adams</lastName><age>18</age></person>);
xdmp:document-insert("/simon.xml", <person><firstName>Simon</firstName><lastName>Petrov</lastName><age>22</age></person>);
xdmp:document-insert("/mark.xml", <person><firstName>Mark</firstName><lastName>the Lord</lastName><age>25</age></person>);
:)
for $person in /person
let $sort := fn:reverse(fn:tokenize($person/lastName, ' '))[1]
order by $sort
(: return $person :)
return $person/lastName/text()
Notice that now the sort order is going to be
- Adams
- the Lord
- O'Toole
- Petrov
I hope this will help.
I am trying to understand the query plan of MonetDB.
Is there a documentation anywhere where I can find what each instruction stays for?
If not, can anybody tell me what are returning
sql.projectdelta(X_15,X_23,X_25,r1_30,X_27)
and
sql.subdelta(X_246,X_4,X_10,X_247,X_249), for example?
In my query I am sorting the result by two attributes (e.g., by A,B). Can you tell me why the second sort has more parameters than the first?
(X_29,r1_36,r2_36) := algebra.subsort(X_28,false,false);
(X_33,r1_40,r2_40) := algebra.subsort(X_22,r1_36,r2_36,false,false);
Is algebra.subsort returning (oid, columnType) pairs, or just oid?
Thank you!!
Understanding output of the explain SQL statement requires knowledge of the MonetDB Assembly-like Language (MAL).
Concerning functions sql.projectdelta, sql.subdelta, and algebra.subsort, you'll find their signature and a (brief) description in the monetdb lib folder. Ex :
[MonetDB_install_folder]\MonetDB5\lib\monetdb5\sql.mal for all sql functions
[MonetDB_install_folder]\MonetDB5\lib\monetdb5\algebra.mal for all algebra functions
Concerning the different number of parameters for algebra.subsort :
(X_29,r1_36,r2_36) := algebra.subsort(X_28,false,false);
is described as :
Returns a copy of the BAT sorted on tail values, a BAT that specifies
how the input was reordered, and a BAT with group information.
The input and output are (must be) dense headed.
The order is descending if the reverse bit is set.
This is a stable sort if the stable bit is set.
(X_33,r1_40,r2_40) := algebra.subsort(X_22,r1_36,r2_36,false,false);
is described as:
Returns a copy of the BAT sorted on tail values, a BAT that specifies
how the input was reordered, and a BAT with group information.
The input and output are (must be) dense headed.
The order is descending if the reverse bit is set.
This is a stable sort if the stable bit is set.
MAL functions can be overloaded bassed on their return value. algebra.subsort can return 1, 2 or 3 values depending on what you're asking for. Checl algebra.mal for the different possibilities.
If I have a Data.Text value that I want to sort, should I just unpack it to a String and use sort or some other function on it? It seems like it would be tough to write a fast sorting function for Text values when cons and append are both O(n).
Depends on what you mean by "sorting" Text. Much of the value of the Text type is tied up in it handling weird human language inconsistencies correctly. Probably the best way to sort while taking those variants into account is to use the text-icu
import Data.Text.ICU
import qualified Data.Text as T
-- | Uses the Unicode Collation Algorithm. Others can be chosen by picking
-- something other than `uca` as your Collator.
sortText :: [T.Text] -> [T.Text]
sortText = sortBy (sortKey uca)
If you do what you suggested in your question—unpack to a string then compare strings by lexicographic character order—you'll possibly be slower (String is a much bulkier type than Text) but you'll certainly open up possibilities of weird sort orders and weird re-packing if you have Unicode Text values.
I'm trying to come up with a way to approach typehead in such a way that uniq substrings are given priority. For example, lets say I have the following:
foo.bar
foo.bar.baz
foo.bar.biz
foo.bar.bat
foo.bar.bat.art
foo.bar.bat.zap
...
foo.dog.alt
foo.dog.rar
...
foo.zed
foo.zed.rarg
Due to the drill down nature of the data, as the users types, the best thing to see what be the next unique option (since the list below the typeahead box would limited in length). So for example if someone where too type foo, they would see foo.bar, .foo.dog.alt, and foo.zed.
Any suggestions on how to approach this?
How to compare with case sensitive in find function?
Like
stringtxt = Range("A1:A10").Find(What:=stringtxt , Lookat:=xlWhole,MatchCase:=False)
Here suppose stringtxt="ABCD (abcd)"
AND in range one of the cells may have value like "ABCD (ABCD)"
I have to compare this with contents in range specified.
I tried adding like "UCase".Didn`t work.MatchCase i tried with both true and false values.Didnt work though.
Suggest me some better answers to compare.
One of the parameters to the Find method is a MatchCase parameter, as follows:
Think that should help you solve this problem.