-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathjioq1qaszzzxdaqlop.php
101 lines (87 loc) · 3.32 KB
/
jioq1qaszzzxdaqlop.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<?php
include("config.php");
/** This File is the main search result provider.
In this file the data is taken from the database using MySQL and then send to the search.php file to show the search results**/
// Remove unnecessary words from the search term and return them as an array
function filterSearchKeys($term){
$term = trim(preg_replace("/(\s+)+/", " ", $term));
$words = array();
// expand this list with your words.
$list = array("in","it","a","the","of","or","I","you","he","me","us","they","she","to","but","that","this","those","then");
$c = 0;
foreach(explode(" ", $term) as $key){
if (in_array($key, $list)){
continue;
}
$words[] = $key;
if ($c >= 15){
break;
}
$c++;
}
return $words;
}
// limit words number of characters
function limitChars($term, $limit = 200){
return substr($term, 0,$limit);
}
function search($term){
$term = trim($term);
if (mb_strlen($term)===0){
// no need for empty search right?
return false;
}
$term = limitChars($term);
// Weighing scores
$scoreFullTitle = 6;
$scoreTitleKeyword = 5;
$scoreFullDescription = 5;
$scoreDescriptionKeyword = 4;
$scoreKeywords = 3;
$scoreUrlKeyword = 1;
$keywords = filterSearchKeys($term);
$escQuery = DB::escape($term); // see note above to get db object
$titleSQL = array();
$desSQL = array();
$urlSQL = array();
/** Matching full occurences **/
if (count($keywords) > 1){
$titleSQL[] = "if (title LIKE '%".$escQuery."%',{$scoreFullTitle},0)";
$desSQL[] = "if (description LIKE '%".$escQuery."%',{$scoreFullDescription},0)";
}
/** Matching Keywords **/
foreach($keywords as $key){
$titleSQL[] = "if (title LIKE '%".DB::escape($key)."%',{$scoreTitleKeyword},0)";
$desSQL[] = "if (description LIKE '%".DB::escape($key)."%',{$scoreDescriptionKeyword},0)";
$urlSQL[] = "if (url LIKE '%".DB::escape($key)."%',{$scoreUrlKeyword},0)";
$categorySQL[] = "if ((SELECT count(keywords.tag_id) FROM keywords JOIN keywords ON keywords.tag_id = keywords.tag_id WHERE keywords.post_id = id AND keywords.name = '".DB::escape($key)."') > 0,{$scoreKeywords},0)";
}
// Just incase it's empty, add 0
if (empty($titleSQL)){
$titleSQL[] = 0;
}
if (empty($sumSQL)){
$desSQL[] = 0;
}
if (empty($urlSQL)){
$urlSQL[] = 0;
}
if (empty($tagSQL)){
$tagSQL[] = 0;
}
$sql = "SELECT FROM sites WHERE id,title,url,description,keywords,((-- title scores".implode(" + ", $titleSQL).")+(-- description".implode(" + ", $desSQL)." )+(-- keywords".implode(" + ", $categorySQL).")+(-- url".implode(" + ", $urlSQL)."))";
$results .= "<div class='resultContainer'>
<h3 class='title'>
<a class='result' href='$url' data-linkId='$id'>
$titleSQL
</a>
</h3>
<span class='url'>$urlSQL</span>
<span class='description'>$sumSQL</span>
</div>";
if (!$results){
return false;
}
return $results;
}
?>