# Intelligent Searchform

**URL:** <https://www.ruby-forum.com/t/intelligent-searchform/194908>\
**Category:** Rails\
**Created:** [September 13, 2010, 4:27pm UTC](https://www.ruby-forum.com/t/intelligent-searchform/194908 "2010-09-13T16:27:41Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![coldie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/5f9b8f/32.png) [@coldie](https://www.ruby-forum.com/u/coldie)\
**Post date:** [September 13, 2010, 4:27pm UTC](https://www.ruby-forum.com/t/intelligent-searchform/194908/1 "2010-09-13T16:27:41Z")

</div>

Hi there,

i wrote an intelligent searchform, which is divided into categories.  
Just a short overview of the workflow. For every keyword, which is  
entered in the searchform the matches are checked. So we’ve got a rank  
in a hash.

[key of entry, relevance match]

For example:  
@hash = [123 =\> 5, 124 =\>2, 125 =\> 5, 126 =\> 1, etc…]

I ordered the Hash “by relevance” simply by ordering by the hash values:  
@hash.sort\_by {|a,b| b})

@hash = [123 =\> 5, 125 =\> 5, 124 =\>2, 126 =\> 1, etc…]

No I want to find my entries by the key values of the hash.

Thats not the problem:  
@entries = Entry.find(@hash)  
or  
@entries = Entry.find(@hash.keys)

The problem is, that the entries are (by standard) ordered by ID and not  
in order by the Hash-Keys I passed.  
Is there a possibility to order by my “relevance system” (even if there  
isn’t a coloumn in the Entries-Table.

Thank you 'till now  
Hans
