473,320 Members | 1,990 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Use Relevancy Algorythym

59
Hi
This is a script which combines many different video feeds together, at the moment you can see that it [PHP]shuffle($all);[/PHP] instead of an algorithm to sort the records, i would like to change it so that it is sorted by relevancy to a string which i could specify. Here is the whole code for the page, and bellow that is an algoryhtym which i tried to implement into the code but would not work. Can anyone either help me implement this algorithm or write one that will work with this code? [PHP]<?
function getall($searchterms) {
require("yt.php");
require("gv.php");
require("dm.php");
require("mc.php");

$yt = yt($searchterms);
$gv = gv($searchterms);
$dm = dm($searchterms);
$mc = mc($searchterms);

$all = array_merge($yt,$gv,$dm,$mc);
if(count($all)) {
include_once "latest.php";
updatelatest(str_replace("+","-",$searchterms));
}
$bannedwords = "bannedwords.txt";
$fp = fopen($bannedwords, "r");
$wordstmp = fread($fp, filesize($bannedwords));
fclose($fp);
$words = explode("\n",$wordstmp);
$words = array_map("strtolower",$words);

foreach($all as $index=>$arr) {
$arrtitle = $arr['title'];
foreach($words as $index2=>$word) {
if(strstr(strtolower($arrtitle),strtolower(str_rep lace("\n","",str_replace("\r","",$word))))) {
unset($all[$index]);
break;
}
}
}

srand((float)microtime() * 1000000);
shuffle($all);
foreach($all as $j=>$k) {
if(!trim($k['title'])||!trim($k['link']))
unset($all[$j]);
}

return $all;
}

?>[/PHP]

This is the sort of algorythym

[PHP]usort($multifeed,'funnySort');

function funnySort($a,$b)
{
// assign numerical value so we can sort on
// whether "term" is in title or content or neither

$term = 'funny';

$x = 0;
if (stripos($a->get_title(),$term))
$x = 2;
elseif (stripos($a->get_content(),$term))
$x = 1;

$y = 0;
if (stripos($b->get_title(),$term))
$y = 2;
elseif (stripos($b->get_content(),$term))
$y = 1;

return $x <= $y
}[/PHP]


i also tried to use this code on this site http://www.webmastersherpa.com/tools/search.txt


Please can someone either help me adapt either of these algorithms or help me write one that will work with my code.
Feb 17 '08 #1
2 1706
ronverdonk
4,258 Expert 4TB
Is it is the algoritm that does not return a value at all times?
Then use the ternary operator in your return statement, like
[php]return ($x <= $y) ? $x : $y;[/php]
that will either return the lowest of the $x or the $y value.

Ronald
Feb 17 '08 #2
ojsimon
59
Is it is the algoritm that does not return a value at all times?
Then use the ternary operator in your return statement, like
[php]return ($x <= $y) ? $x : $y;[/php]
that will either return the lowest of the $x or the $y value.

Ronald
Thanks but i am trying to make it so that all the records are given a score by their relevance to the score and then sorted descendingly, thats what the 2 algorythyms i provided are meant to do, but when i trey to implement these 2 they do not work in my code provided, please could you help me implement them so that the code works.

thanks
Feb 17 '08 #3

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

Similar topics

2
by: Phil Powell | last post by:
Relevancy scores are normally defined by a MySQL query on a table that has a fulltext index. The rules for relevancy scoring will exclude certain words due to their being too short (minimum...
0
by: Phil Powell | last post by:
The table already has a fulltext index and from there I can use the MySQL fulltext search query to get results as well as the relevancy score. The problem I have is that MySQL has a default...
0
by: Phil Powell | last post by:
I have a rather complicated query with a combination of LEFT JOINs and two MATCHES where the first match is non-boolean to get the accurate score, the second to search as boolean: SELECT...
0
by: dtSearch | last post by:
Press Contact: Belinda Banks S&S Public Relations (212) 946-2823 Belinda@sspr.com Announcing New dtSearch® Product Line Version Release Adds Broader Spider Capabilities to dtSearch Desktop,...
90
by: Bret Pehrson | last post by:
This message isn't spam or an advertisement or trolling. I'm considering farming some of my application development to offshore shops (I'm in the US). I have absolutely *no* experience w/ this,...
21
by: thomson | last post by:
Hi folks, Does any one have any idea which platform does GMAIL works, whether its JSP, ASPX or any other Regards thomson
0
by: dtsearch | last post by:
New release expands-through a .NET Spider API, to Linux, and to OpenOffice-dtSearch's ability to index over a terabyte of text in a single index, with indexed search time typically less than a...
0
Niheel
by: Niheel | last post by:
A few month's back I ran into this site called "Digg". Of course, by now every techie knows about it. At that time, I was just amazed by the way it worked. Right away it got me thinking, these guys...
0
by: dtsearch | last post by:
A new beta build offers 64-bit developer access to dtSearch's "terabyte indexer," and preliminary MS Word 2007 and Excel 2007 support (in both 64-bit and 32-bit versions) BETHESDA, MD (July 22,...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.