473,804 Members | 3,204 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Ranking Search Results (Levenshtein)?

97 New Member
Hi there,

I would like to achieve some kind of rating of the results of a query. As it searches in different fields of the (metadata) database, matching keywords of the field of the "data variable names" are more important than matching keywords in the "descriptio n" field...

I've read about the Levenshtein function, but a) I am not sure if this is the right track; and b) I don't really know how to implement this for the given need.

Can anyone give me a hint or two?

Thanks for any advice!

Stef
Sep 26 '07 #1
2 2236
Atli
5,058 Recognized Expert Expert
Hi Stef.

I'm not sure this will work for you, but I have a simple way of searching 'blog-like' data, that is; an array containing a title and text for each entry, by ranking each of them, by using the similar_text() function, and using that to create a combined rank for the entry, where the title will weighs more than the text...

This takes four imaginary blog-entries and give each of them a score out of a 100, where the title weighs 75% and the text 25%.
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. # Set up data
  3. $data = array(
  4.     array(
  5.         "Title" => "First title",
  6.         "Text" => "Text of the first element"
  7.     ),
  8.     array(
  9.         "Title" => "Second title",
  10.         "Text" => "Text of the second element"
  11.     ),
  12.     array(
  13.         "Title" => "Third title",
  14.         "Text" => "Text of the first element"
  15.     ),
  16.     array(
  17.         "Title" => "Fourth title",
  18.         "Text" => "Text of the fourth element"
  19.     )
  20. );
  21. $searchWord = "first";
  22. $titleRel = 0.75; # title weight percentage
  23. $textRel = 0.25; # text weight percentage
  24.  
  25. # Find relevence for each entry and store it in a new
  26. # array at the same index as the entry being searched.
  27. $relTbl = array();
  28. $index = 0;
  29. foreach($data as $entry) {
  30.     $tmpRel = 0;
  31.     $bufferRel = 0;
  32.     # Add the title to the tmpRel
  33.     similar_text($searchWord, $entry['Title'], $bufferRel);
  34.     $tmpRel += $bufferRel * $titleRel;
  35.     # Add the text to the tmpRel
  36.     similar_text($searchWord, $entry['Text'], $bufferRel);
  37.     $tmpRel += $bufferRel * $textRel;
  38.     # Add the rel to the relTbl
  39.     $relTbl[$index] = $tmpRel;
  40.     $index++;
  41. }
  42.  
  43. # Sort the refTbl by relevence
  44. arsort($relTbl);
  45.  
  46. # Print the row in order by relevence
  47. echo "<p><b>Data in order by relevence:</b>";
  48. foreach($relTbl as $key => $value) {
  49.     echo "<br />". $data[$key]['Title'] ." (". round($value, 3) ."%)";
  50. }
  51. ?>
  52.  
Which prints out:
Expand|Select|Wrap|Line Numbers
  1. Data in order by relevence:
  2. First title (45.833%)
  3. Third title (36.458%)
  4. Fourth title (22.486%)
  5. Second title (22.486%)
  6.  
I haven't tested this in any 'real' situation but this does seem to sort them correctly.

Hope this helps...
Sep 27 '07 #2
luftikus143
97 New Member
Dear Atli,

thank you very much for that. It looks very promising! I'll give it a try!

Stef
Sep 28 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

11
4238
by: Petre Huile | last post by:
I have designed a site for a client, but they have hired an internet marketing person to incrase their search engine ranking and traffic. He wants to put extra-large fonts on every page which will make the design looks a bit rediculous. He also said that the big text cannot be hidden. I am just trying to find a compromise. Here are the questions: (1) Is it true that a page with an <H1> tag and very big font size will make a search...
8
1774
by: Ben Fidge | last post by:
Hi I'm working on a site which requires the users to specify a hotel at which they're staying in London. The complete list of hotels comes to something like 1600 records. Each record consists of Hotel Name, Street Address and Postcode. We need to make it as simple as possible for users to pick their hotel, but I don't want to put 1600 hotel names in a drop-down list, and we have to consider the fact that not every user is going to...
3
1447
by: Michael Fesser | last post by:
..oO(Jerry Stuckle) I prefer third-party search engines or my own. A simple index-based engine with ranking is not that hard to write. Of course it's not that powerful than a professional engine, but usually enough to start with. A while ago I used the Google Search via their SOAP API - it was a pain. The results where often not up-to-date, the response from the server was slow and the API allowed only to get up to 10 search results...
8
4755
by: twomcfly | last post by:
Hi I have a SQL Server 2005 database with a list of results for a variety of people over time. i would like to be able to look at any row and from that row know the last 3 results for that person the columns are like this date ----- person ----- result i would like to be able to add in columns which would show
0
9706
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9579
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10578
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10332
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10321
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9152
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7620
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5522
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
2991
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.