sorting

Elastic search wildcard query to get sorted results

笑着哭i 提交于 2020-03-03 13:05:13
问题 I have a Elastic Search server setup where am storing company names to be used for for company search, the way it works is: From company name, spaces and dots will be removed and stored in ES in a field called trimmedcompanyname, { "companyName" : "RECKON INFOSYSTEM PRIVATE LIMITED", "trimmedCompanyName" : "reckoninfosystemprivatelimited", "id" : "1079" } now when search comes to my server i remove the spaces and dots and then make request to ES server. The ES request in query format is: GET

Is it possible to usort a multidimensional array in PHP to be ordered by alternative values, i.e 1/0/1/0/1/0

你离开我真会死。 提交于 2020-03-03 07:40:58
问题 If you have this PHP array: $args = array( 'a' => array( 'order' => 1, ), 'b' => array( 'order' => 0, ), 'c' => array( 'order' => 0, ), 'd' => array( 'order' => 0, ), 'e' => array( 'order' => 1, ), ); Is there a way to use usort (or other) method that can order it by multidimensional key's value, but instead of being "incremental" (0,0,0,1,1), they would alternate (0,1,0,1,0). So using the array above as an example, the desired order output is for the keys to be ordered by alternate "order"

Sorting a list in c# based on dependant values in another list

别来无恙 提交于 2020-03-03 06:02:47
问题 I'm trying to sort a list of items based on the order of the occurrence in another list. Below is the basic structure: public class ItemList { public List<Item> items; public ItemList(string myValue) { items = new List<Item>(); } public void addItem (string myValue) { var newItem = new Item(myValue); items.Add(newItem); } public class Item { public List<string> myLinkedValues; public string myValue; public Item(string myValue) { myLinkedValues = new List<string>(); } public void addLinkedItem

How to group list of tuples?

混江龙づ霸主 提交于 2020-03-02 19:33:07
问题 Note : I know how I can do this of course in an explicit for loop but I am looking for a solution that is a bit more readable. If possible, I'd like to solve this by using some of the built-in functionalities. Best case scenario is something like result = [ *groupby logic* ] Assuming the following list: import numpy as np np.random.seed(42) N = 10 my_tuples = list(zip(np.random.choice(list('ABC'), size=N), np.random.choice(range(100), size=N))) where my_tuples is [('C', 74), ('A', 74), ('C',

Sort multidimensional hash by values and print the highest

五迷三道 提交于 2020-03-01 05:30:19
问题 I have a stored multidimensional hash ( %info ) with following structure: $info{$os}{$id}=$length; foreach $os (keys %info){ foreach $id (keys %{$info{$os}}){ print "$os $id => " . $info{$os}{$id} ."\n" if (keys %info > 100); } } With this, I can read the hash and print only those $os with more than 100 occurrences, but now I would like to print only the $id with highest $length (i.e., values). So I would like to sort the hash by values and print only $os and $id with highest value. Any help?

Sort multidimensional hash by values and print the highest

淺唱寂寞╮ 提交于 2020-03-01 05:29:51
问题 I have a stored multidimensional hash ( %info ) with following structure: $info{$os}{$id}=$length; foreach $os (keys %info){ foreach $id (keys %{$info{$os}}){ print "$os $id => " . $info{$os}{$id} ."\n" if (keys %info > 100); } } With this, I can read the hash and print only those $os with more than 100 occurrences, but now I would like to print only the $id with highest $length (i.e., values). So I would like to sort the hash by values and print only $os and $id with highest value. Any help?

Sort multidimensional hash by values and print the highest

余生颓废 提交于 2020-03-01 05:29:46
问题 I have a stored multidimensional hash ( %info ) with following structure: $info{$os}{$id}=$length; foreach $os (keys %info){ foreach $id (keys %{$info{$os}}){ print "$os $id => " . $info{$os}{$id} ."\n" if (keys %info > 100); } } With this, I can read the hash and print only those $os with more than 100 occurrences, but now I would like to print only the $id with highest $length (i.e., values). So I would like to sort the hash by values and print only $os and $id with highest value. Any help?

Sort a list by presence of items in another list

百般思念 提交于 2020-03-01 04:27:14
问题 Suppose I have two lists: a = ['30', '10', '90', '1111', '17'] b = ['60', '1201', '30', '17', '900'] How would you sort this most efficiently, such that: list b is sorted with respect to a . Unique elements in b should be placed at the end of the sorted list. Unique elements in a can be ignored. example output: c = ['30', '17', '60', '1201', '900'] Sorry, it's a simple question. My attempt is stuck at the point of taking the intersection. intersection = sorted(set(a) & set(b), key = a.index)

How can I sort my string array from .GetFiles() in order of date last modified in asp.net-webpages?

二次信任 提交于 2020-02-28 10:53:25
问题 I have seen a really close example here: Sorting Files by date But I am new to LINQ and couldn't get it to work (not sure I understand the DirectoryInfo or FileInfo classes). Here are the necessary code snippets: (When assigning the array): string[] files = Directory.GetFiles(Server.MapPath("~/User_Saves/" + WebSecurity.CurrentUserName), "*.xml"); for(int i = 0; i < files.Length; i++) { files[i] = files[i].Substring(files[i].LastIndexOf("\\") + 1); files[i] = files[i].Substring(0, files[i]

mongodb sort result of aggregate query and display day name

老子叫甜甜 提交于 2020-02-28 09:43:27
问题 I have the following aggregation query db.orders.aggregate( { "$project" : { _id : 0, "dateDay" : {"$concat" : [ {"$substr" : [{"$dayOfMonth" : "$timestamp"}, 0, 2]}, "-", {"$substr" : [{"$month" : "$timestamp"}, 0, 2]}, "-", {"$substr" : [{"$year" : "$timestamp"}, 0, 4]} ] } } }, { "$group" : { "_id" : "$dateDay", "Count" : { "$sum" : 1 } } }, { $sort : { "Count : 1 } } ); which returns something like: { "_id" : "3-9-2014", "Count" : 81 }, { "_id" : "14-12-2014", "Count" : 10 }, { "_id" : "2