Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6575431
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:23:10+00:00 2026-05-25T15:23:10+00:00

I have a strange sorting issue with my models. Given the following: I have

  • 0

I have a strange sorting issue with my models.

Given the following:

  • I have a model called Cv, which has many occupations and skills, and is linked to a country.
  • I also have a model called Vacancy, which has one occupation and many skills, and is also linked to a country.

In my controller, I have the following lines of code:

@occupations = Occupation.find params[:occupation_ids].split(' ')
@skills = Skill.find params[:skill_ids].split(' ')
@cv = Cv.find params[:cv_id]
@language = Language.resolve({:code => :en, :name => :en})
@vacancies = Vacancy.joins(:vacancy_skills).where('vacancy_skills.skill_id' => params[:skill_ids]).all.uniq.sort{ |x,y| (x.skills | @skills).length <=> (y.skills | @skills).length }

The idea is that all vacancies are beeing sorted by their relevance, which is calculated by the length of the union between the selected skills (@skils) and the skills of the vacancy in question.

When I run the code, I receive all vacancies, ordered by country and sorted by relevance, but I don’t want them ordered by country, instead I want them all mixed but sorted by relevance.

The current output is :

  • vacancy 1, 100% relevance, united kingdom
  • vacancy 2, 90% relevance, united kingdom
  • vacancy 3, 10% relevance, united kingdom
  • vacancy 4, 90% relevance, france
  • vacancy 5, 70% relevance, fance

The desired output should be like this:

  • vacancy 1, 100% relevance, united kingdom
  • vacancy 2, 90% relevance, united kingdom
  • vacancy 4, 90% relevance, france
  • vacancy 5, 70% relevance, france
  • vacancy 3, 10% relevance, united kingdom

What am I supposed to change/do to get it like that?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T15:23:11+00:00Added an answer on May 25, 2026 at 3:23 pm

    problem was in the sort algorithm.
    I used the | operator instead of the & operator.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I tried to draw a model with 197 polygons but i have strange black
I have a strange issue: I am using SPContext.Current.Web in a .aspx page, but
I have a strange, sporadic issue. I have stored procedure that returns back 5
I have this strange issue with my web app. You see, I'm using jQuery
I have strange JRUN issue. I have installed ColdFusion 9.0 on Amazon EC2 instance
I have an strange behavior, which looks lika an problem with (a)synchronous method calls?!?
I have strange problem for which I can't think of a solution. I have
I have strange problem. I have class which behaves similar dropdown list. package test.view;
I have strange problem. When I use @return Model\Article in the model-loading method then
I have strange issue with nested left-joins in postgresql... It's hard to explain, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.