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
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%. -
<?php
-
# Set up data
-
$data = array(
-
array(
-
"Title" => "First title",
-
"Text" => "Text of the first element"
-
),
-
array(
-
"Title" => "Second title",
-
"Text" => "Text of the second element"
-
),
-
array(
-
"Title" => "Third title",
-
"Text" => "Text of the first element"
-
),
-
array(
-
"Title" => "Fourth title",
-
"Text" => "Text of the fourth element"
-
)
-
);
-
$searchWord = "first";
-
$titleRel = 0.75; # title weight percentage
-
$textRel = 0.25; # text weight percentage
-
-
# Find relevence for each entry and store it in a new
-
# array at the same index as the entry being searched.
-
$relTbl = array();
-
$index = 0;
-
foreach($data as $entry) {
-
$tmpRel = 0;
-
$bufferRel = 0;
-
# Add the title to the tmpRel
-
similar_text($searchWord, $entry['Title'], $bufferRel);
-
$tmpRel += $bufferRel * $titleRel;
-
# Add the text to the tmpRel
-
similar_text($searchWord, $entry['Text'], $bufferRel);
-
$tmpRel += $bufferRel * $textRel;
-
# Add the rel to the relTbl
-
$relTbl[$index] = $tmpRel;
-
$index++;
-
}
-
-
# Sort the refTbl by relevence
-
arsort($relTbl);
-
-
# Print the row in order by relevence
-
echo "<p><b>Data in order by relevence:</b>";
-
foreach($relTbl as $key => $value) {
-
echo "<br />". $data[$key]['Title'] ." (". round($value, 3) ."%)";
-
}
-
?>
-
Which prints out: - Data in order by relevence:
-
First title (45.833%)
-
Third title (36.458%)
-
Fourth title (22.486%)
-
Second title (22.486%)
-
I haven't tested this in any 'real' situation but this does seem to sort them correctly.
Hope this helps...
Dear Atli,
thank you very much for that. It looks very promising! I'll give it a try!
Stef
Sign in to post your reply or Sign up for a free account.
Similar topics |
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...
|
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...
|
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...
|
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
|
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...
| |
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,...
|
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...
|
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...
|
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,...
|
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...
|
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...
| |
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...
|
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...
| |