solrnet – Sorting solrnet query results

Hi, I'm just trying to sort the results of my query alphabetically. The returned data looks like this:

"FacetFilters": (
                    {
                        "Id": 0,
                        "Name": "small",
                        "ResultCount": 47,
                        "IsSelected": false,
                        "Hide": false
                    },
                    {
                        "Id": 0,
                        "Name": "n/a",
                        "ResultCount": 1,
                        "IsSelected": false,
                        "Hide": false
                    },
                    {
                        "Id": 0,
                        "Name": "medium",
                        "ResultCount": 79,
                        "IsSelected": false,
                        "Hide": false
                    },
                    {
                        "Id": 0,
                        "Name": "large",
                        "ResultCount": 4,
                        "IsSelected": false,
                        "Hide": false
                    }
                )

I was able to solve this post-query problem by inverting the list with the help of: FacetFilters.Reverse();but I would rather just get the results in the right order thanks to the query. Can someone tell me what is the best way to fix it? Thank you. For the record, I use the solrnet package for .Net.

sorting – Canonical classification of the days of the week

The entities representing the days of the week are listed in alphabetical order:

Sort({Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday})

(* {Friday, Monday, Saturday, Sunday, Thursday, Tuesday, Wednesday} *)

(Note that these are not strings.)

Is there a better way to sort than using the following?

SortBy(PositionIndex({Monday, Tuesday, Wednesday, Thursday, Friday}))

An alternative algorithm for sorting a stack using a single extra stack

From "Cracking the Coding Interview":

Write a program to sort a stack in ascending order (with the largest items at the top). You can use up to one additional stack to hold items, but you can not copy items to another data structure (such as an array). The battery supports push, pop, is_empty, and peek

So, the classic solution I found online for this (and the one in the book) looks like this:

Algo # 1 (classic)

def sort_stack(primary):
  secondary = ()
  while primary:
    tmp = primary.pop()
    while (secondary and secondary(-1) > tmp):
      primary.append(secondary.pop())
    secondary.append(tmp)
  return secondary

In summary, we will return our secondary / auxiliary battery after sorting via time O (n ^ 2).

However, this is not what my original approach was and I think this approach has some interesting qualities:

Algo # 2 (mine)

def sort_stack(primary):
  did_sort = False
  secondary = ()
  while not did_sort:
    # move from primary to secondary, pushing larger elements first when possible
    desc_swap(primary, secondary)
    # move from secondary back to primary, pushing smaller elements first when possible. Set did_sort = True if we're done and can exit.
    did_sort = asc_swap(secondary, primary)
  return primary

def asc_swap(full, empty):
  temp = None
  did_sort = True
  yet_max = None

  while full:
    if not temp:
      temp = full.pop()
    if full:
      if full(-1) < temp:
        insert = full.pop()
        if insert < yet_max:
          did_sort = False
        yet_max = insert
        empty.append(insert)
      else:
        empty.append(temp)
        temp = None
  if temp:
    empty.append(temp)
  return did_sort


def desc_swap(full, empty):
  temp = None
  while full:
    if not temp:
      temp = full.pop()
    if full:
      if full(-1) > temp:
        empty.append(full.pop())
      else:
        empty.append(temp)
        temp = None
  if temp:
    empty.append(temp)

Now, obviously, it is not as clean or elegant, but it could be with some help functions that dynamically choose our comparator and choose the element to push, etc.

Basically, what he does is this:

# Start with stack in wrong order (worst case)
primary:   4 3 2 1
secondary:  

# Swap to secondary, pushing larger elements first (1 is held in temp until the end because it is smaller than the following elements)
primary:    
secondary: 2 3 4 1

# Swap back to primary, pushing smaller elements first
primary:   1 3 2 4
secondary:  

# back to secondary 
primary:   
secondary: 4 3 2 1

# Back to primary, finished
primary:   1 2 3 4
secondary:

This strategy has a compromise between the best and the worst case.
Algo # 1 actually performs worst when the stack is already sorted and better when sorted in the wrong order and algo # 2 does the opposite.

Questions

  • What are your thoughts? I think it's just an interesting way to sort out what I've never seen before.
  • Is there a name for this kind of sorting? I could not find similar algos but I am sure they are there and would like to be able to describe / recognize it better. Thank you!

nt.number theory – Sorting natural numbers according to a Jaccard metric?

I asked this question on mathstackexchange (https://math.stackexchange.com/questions/3357151/sorting-natural-numbers-based-on-metric) but I did not get an answer.
I hope that it will go to ask it here:

Let

$$ d ^ J_k (a, b) = 1- frac { sigma_k ( gcd (a, b))} { sigma_k (a) + sigma_k (b) – sigma_k ( gcd (a, b ))} $$ for $ a, b $ two natural numbers $ k $ 0 $.
Then, it is a metric (Jaccard) on natural numbers.
Consider $ d (a, b) = d ^ J (a, b) = sum_ {k = 0} ^ infty frac {1} {2 ^ k} d ^ J_k (a, b) $ and define $ a unlhd b $ Yes Yes $ d (a, 1) the d (b, 1) $

Questions:

  1. Yes $ a unlhd b $ and $ c $ is a natural number, so $ ac unlhd bc $?

  2. Yes $ a unlhd b $ and $ b illhd a $then $ a = b $?

  3. Yes $ a unlhd b $ and $ c unlhd e $then $ ac unlhd be $?

  4. Yes $ gcd (a, c) = gcd (b, c) = $ 1 then $ d (a, b) = d (ca, cb) $. (It's easy to prove, since $ sigma_k $ is multiplicative.)

It seems that the command is lexicographic. I mean, build the vector:

$$ V (a) = (d_0 (a, 1), d_1 (a, 1), d_2 (a, 1) ldots d_k (a, 1) ldots) $$

Then, it seems that $ a unlhd b $ Yes Yes $ V (a) the V (b) $ or $ the $ is the lexicographic order of the given vectors.

Some Sage scripts:

def dd(a,b,k):
    return 1-sigma(gcd(a,b),k)/(sigma(a,k)+sigma(b,k)-sigma(gcd(a,b),k))

def dvec(a,K=10):
    return (dd(a,1,k).n() for k in range(K+1))

def d(a,b,K=10):
    return sum((1/(2.0**k)*dd(a,b,k) for k in range(K+1)))

sorted(( (d(a,1,10),a) for a in range(1,100)))    

((0.000000000000000, 1),
 (1.26352353560690, 2),
 (1.34364319712592, 3),
 (1.40497170796791, 5),
 (1.43113204316485, 7),
 (1.45520927484247, 11),
 (1.46177941791487, 13),
 (1.47035738224924, 17),
 (1.47331411564775, 19),
 (1.47770790490320, 23),
 (1.48205464375133, 29),
 (1.48313429769773, 31),
 (1.48568055948408, 37),
 (1.48696820697958, 41),
 (1.48752307533606, 43),
 (1.48849243175490, 47),
 (1.48967436265919, 53),
 (1.49061769251944, 59),
 (1.49089119792606, 61),
 (1.49161439830309, 67),
 (1.49202905783214, 71),
 (1.49221945289014, 73),
 (1.49273313109042, 79),
 (1.49303455213995, 83),
 (1.49343614594272, 89),
 (1.49389469153245, 97),
 (1.58038164357392, 4),
 (1.62430622092945, 9),
 (1.64916894831869, 25),
 (1.65681510482431, 49),
 (1.70181166355779, 6),
 (1.71251996065963, 8),
 (1.71920616143290, 10),
 (1.72714814044250, 14),
 (1.72719187491448, 15),
 (1.73288513480220, 21),
 (1.73471402834227, 22),
 (1.73621232562853, 27),
 (1.73681810775224, 26),
 (1.73839844837180, 33),
 (1.73841153706667, 35),
 (1.73958889336088, 34),
 (1.73994574914563, 39),
 (1.74054992940204, 38),
 (1.74198349871905, 46),
 (1.74199186845917, 51),
 (1.74199942675375, 55),
 (1.74270372005527, 57),
 (1.74301404059068, 65),
 (1.74340792482690, 58),
 (1.74376265890517, 62),
 (1.74376756472425, 69),
 (1.74377384596954, 77),
 (1.74436044828411, 85),
 (1.74452957378555, 91),
 (1.74460070007059, 74),
 (1.74482689550047, 87),
 (1.74483006361155, 95),
 (1.74502525419037, 82),
 (1.74509104929573, 93),
 (1.74520835591782, 86),
 (1.74552845631242, 94),
 (1.78213363982812, 16),
 (1.79485710740475, 81),
 (1.81324507872647, 12),
 (1.81896789031508, 18),
 (1.81998016814039, 20),
 (1.82318502936399, 28),
 (1.82423371804470, 32),
 (1.82583952513618, 45),
 (1.82630550851183, 44),
 (1.82690273055893, 50),
 (1.82718391487045, 52),
 (1.82749364950621, 63),
 (1.82828582492105, 75),
 (1.82834711474068, 68),
 (1.82875220479996, 76),
 (1.82912899954912, 99),
 (1.82935797699558, 92),
 (1.82941227603807, 98),
 (1.85218308685392, 64),
 (1.86538817693823, 24),
 (1.86688267571898, 30),
 (1.86835304078615, 40),
 (1.86871364331448, 42),
 (1.86979510882916, 54),
 (1.86979732014398, 56),
 (1.87050985618865, 66),
 (1.87051243084219, 70),
 (1.87101760800471, 78),
 (1.87122139031876, 88),
 (1.88228470237312, 36),
 (1.89491690092618, 48),
 (1.89630685447653, 80),
 (1.91266763629169, 60),
 (1.91309339654707, 72),
 (1.91343397284113, 84),
 (1.91353207281394, 90),
 (1.91368754226931, 96))


# checking numerically if lexicographic sorting:
(x(1) for x in sorted(((dvec(a),a) for a in range(1,100)))) == (x(1) for x in sorted(((d(a,1),a) for a in range(1,100))))    

True

Also a related question:

How are the sequences called in a metric space where the distance between two consecutive points converges? (For Cauchy sequences, this distance converges to 0). (We could call them Cauchy-like)

I ask this question because it seems that with the metric above, if we have a sequence $ a_1 unlhd a_2 unlhd ldots a_n ldots $ as for each $ n $ there are no natural numbers $ x $ with $ a_n unlhd x unlhd a_ {n + 1} $. We could call such a "complete" sequence. It now seems (numerically) that each "complete" sequence of this type with the given metric resembles that of Cauchy. For example, it seems that prime numbers are complete sequences of Cauchy type.

Of course, if anyone had a proof or glimpse of the above statements, it would be very interesting!

Web Development – The Most Effective Way to Return Results to a Web Page with a Sorting Algorithm

Recently, I created a search page where the user can enter his search criteria and the server will use a scoring and sorting algorithm to return the "best" results first. The flow of current is as follows:

  1. The user enters his search criteria.
  2. The server-side code (PHP) creates a query to retrieve all the results that match this criteria.
  3. The server uses a function to assign a "score" to each result.
  4. The server scans all the results and ranks the results from the highest score to the lowest score using a "quick sort" algorithm.
  5. The table is spliced ​​in order to take only the 15 best results. These are then passed to the web page to be displayed as results.

At the bottom of the results is a "Load More" button. When you click on it, the process is identical to the one described above (via AJAX), but instead shifts the array to a certain amount, but again, it only takes the following 15 results and returns them to the web page in JSON format, before adding them to the results. via JavaScript.

After review, this seems really ineffective. I ask the database to match the results each time the page is loaded or the user clicks "Load more", noting then sorting each one of them, only to take than 15 of these results.

Of course, I have to query all the corresponding results in order to provide the "best" results for the whole table, rather than on this one.

I thought maybe a better way to do it is to sort and score the entire table via a cronjob and give each line a "position ranking". When the user comes to load the web page, he can simply query the database to obtain the corresponding results in the same SQL statement, classify them in the "position evaluation" column, and then limit the results to 15 ( and use offset for the AJAX request). .

Would this process be much faster? The only drawback I can think of is that the ratings would be out of date, depending on how often the cronjob sorted the results.

Is it worth it to move to this new process or is my concern for efficiency unfounded?

Unity – Why are particle effects always rendered after the IU when they have the same sorting layer and sort order?

Why are particle effects always rendered after the IU when they have the same sorting layer and the same sort order? I've been looking for a lot of information about this, everyone says that the effect and the UI are controlled by the sort order and the sorting layer. If the UI sorting layer is like for the effects "and the sort order is larger than the effects", the user interface then restores and the result is this effect of UI cover. But what will they do if they have the same sorting layer and the same sort order? I've found this alway effect to cover the user interface in this case. I think that's because the effect is rendered after the user interface. But why?
I hope everyone can answer me. Thank you.

The Woocommerce sorting does not work properly after adding the hook & # 39; woocommerce_product_query & # 39; and changing the query parameters post__not_in or post__in

I therefore have a code that filters my message based on my custom field. This code filters my posts based on the role of the user and the selected custom field. I managed to filter my post with this code. But it destroyed my sort when sorting by price or other sorting parameters.

function hideProductDependingOnVisibility( $q ) {

// Get all product IDs
$products_IDs = new WP_Query( array(
    'post_type' => 'product',
    'posts_per_page' => -1,
));

$array_of_product_id = array();
$retailerIds = array();
$wholesalerIds = array();

$user = wp_get_current_user();

while ($products_IDs->have_posts() ) : $products_IDs->the_post();
    $postId = get_the_id();
    $productVisibilities = get_field('show_product_for_accounts', $postId);

    array_push($array_of_product_id, $postId);

    foreach ($productVisibilities as $productVisibility) {
        if ($productVisibility == "retailer") {
            array_push($retailerIds, $postId);
        }

        if ($productVisibility == "wholesale") {
            array_push($wholesalerIds, $postId);
        }
    }

endwhile;


$nonWholeSaleIds = array_diff($array_of_product_id,$wholesalerIds);
$nonRetailerIds = array_diff($array_of_product_id,$retailerIds);

if ( $user->roles(0) == "wholesaler" ) {
    $q->set( 'post__in', $nonWholeSaleIds );
} else {
    $q->set( 'post__in', $nonRetailerIds );
}

}
add_action( 'woocommerce_product_query', 'hideProductDependingOnVisibility' );

I've also tried removing all the code and statically changing the products being polled with just this code:

$ q-> set (& # 39; post__in & # 39 ;, & quot; certain product identifiers & quot;);

Still, it still does not sort the products properly.

Is there a problem using post__in and order for WP_Query? or am I having something wrong here?

Merge Attach SSIS Error Despite Sorting and Matching Meta

I'm trying to merge Join two data sources. I made sure that the metadata matched and that the sort key was present in the metadata, but it still gives me the following error:

Both entries of the transformation must contain at least one sorted column and these metadata must have the corresponding metadata. "

All support articles and related forum questions all mention metadata and sorting. I even type the right dataset to match the one on the left … I do not know what to do here. The flow and the metadata are illustrated. The first is the left join, the second is the right join. The last entry is the column I want to join in both metadata tables.

Data flow
Input metadata1
Input2 metadata

javascript – Questions about sorting HTML DOM with the help of jQuery

I have below the code that works perfectly to sort DOM.

HTML:

CSS

li::before {
    content: attr(data-order);
    display: block;
}

Javascript with jQuery:

const sortList = function(a, b) {
    return (+a.dataset.order) - (+b.dataset.order) > 0 ? 1: - 1;
};

$('button').click(() => {
    $('#list li').sort(sortList).appendTo('#list');
});

Or you can check it on codepen:
https://codepen.io/EdmondWang/pen/pozeyXb

I have 2 questions.

Thanks for the help in advance!

Number of swaps and comparisons in sorting algorithms

I was reading the comparison algorithms (bubble, insertion and selection). I've followed this link link1, but if any one ask what is the number of comparison and exchange in these algorithms, what should I say?

for a size n chart, please refer to the attached photo, help me understand the number of comparisons and conversions.

pic1