Search Duplicating Bugs
<p>Still having issues with the word above duplicating, not sure why. </p>
<p><img style="display: block; margin-left: auto; margin-right: auto;" src="https://i.imgur.com/zU8zufI.png" /></p>
<h3>Search Page</h3>
<h4>PHP - Get Search Value</h4>
<pre><code class="php hljs">$searchvalueencoded = htmlentities($searchvalue);</code></pre>
<p>Check for Search value, and then list all items matching that value.</p>
<pre><code class="php hljs">if($searchvalue > "") {
$pagecontent .= $class->listall(
$start = $startval,
$max = $pagestep,
"search",
$templatefilename,
$searchterm = $searchvalue
);
}</code></pre>
<p>List type is search</p>
<h4>PHP</h4>
<pre><code class="php hljs">if($listtype == "search") {
$searchtermurlenc = rawurlencode($searchterm);
$searchtermurlenc = "searchtext:::" . $searchtermurlenc;
$searchsql = "";
foreach($this->loadarray as $loadvar) {
$searchsql .= "$loadvar like '%$searchterm%' or ";
}
$searchsql = rtrim($searchsql,"or ");
/ -- old search sql
$sql = "select from $dbtablename where
title like '%$searchterm%' or
additional like '%$searchterm%' or
category like '%$searchterm%' or
uid like '%$searchterm%'
order by insdate desc limit $start,$max";
/
$sql = "select from $dbtablename where
$searchsql
order by insdate desc limit $start,$max
";
}</code></pre>
<p>Add search function, i think there might be an issue here</p>
<h4>PHP</h4>
<pre><code class="php hljs">/ add search result /
if( $out > "" ) {
// record search term if enabled
if($listtype == "search") {
global $recordsearches;
$recordsearchval = true;
// if the search value is from comments and its 5 then its a uid so dont record it.
if($dbtablename == "comments") {
if(strlen($searchterm) <= 5) {
$recordsearchval = false; // skip the uid search recording
}
}
if($recordsearches && $recordsearchval) {
$searches = new searches;
$searches->start();
if($searches->loadfromtitle($this->dbtablename . " " . $searchterm)) {
// update existing
$searches->searchnumber = $searches->searchnumber + 1;
$searches->update();
} else {
// add search
$searches->title = $this->dbtablename . " " . $searchterm;
$searches->searchterm = $searchterm;
$searches->searchclass = $this->dbtablename;
$searches->searchnumber = 1;
$searches->add();
}
}
}
}
/ add search result /</code></pre>
<p>I think the load from title may be an issue here, may need to add a md5 of the class and title name to fix this. </p>
<p>Add md5 field to the searches class extend</p>
<h4>PHP</h4>
<pre><code class="php hljs"> public $loadarray = [
"id",
"uid",
"insdate",
"title",
"additional",
"category",
"searchterm",
"searchclass",
"searchnumber",
"md5",
];</code></pre>
<p>Also append the searches db table with a new md5 field</p>
<p>Another bug editing the db.</p>
<p>Prob an old or very old version of php lite admin, </p>
<div>
<div>Version: 1.9.8-dev</div>
</div>
<p>Added md5 to search class, and sqlite, need to find loadfrommd5 function and add it. </p>
<p>this is not quite what i wanted, i might modify it a bit.</p>
<h4>PHP</h4>
<pre><code class="php hljs">// check if a product already exists by its md5
public function md5exists($md5) {
$dbtablename = $this->db->escapeString($this->dbtablename);
$md5 = $this->db->escapeString($md5);
$sql = "select id from $dbtablename where md5 = '$md5' limit 1";
$result = $this->db->query($sql);
if(!$result) { return false; }
while($row = $result->fetchArray()) {
$this->id = $row['id'];
return true;
}
return false;
}</code></pre>
<p>Ok i have fixed this record searches with a md5 added to the row rather than it loading from the title.</p>
<p>Seems to be working, as there are no longer multiple above searches appearing, and it is now updating latest searches properly. </p>
<h4>PHP</h4>
<pre><code class="php hljs"> // if there is something in out and it is a search result then record it.
/ add search result /
if( $out > "" ) {
// record search term if enabled
if($listtype == "search") {
global $recordsearches;
$recordsearchval = true;
// if the search value is from comments and its 5 then its a uid so dont record it.
if($dbtablename == "comments") {
if(strlen($searchterm) <= 5) {
$recordsearchval = false; // skip the uid search recording
}
}
if($recordsearches && $recordsearchval) {
$searches = new searches;
$searches->start();
// md5exists(md5)
$searchtitletable = $this->dbtablename . " " . $searchterm;
$md5searchtitle = md5($searchtitletable);
// if($searches->loadfromtitle($searchtitletable)) {
if($searches->md5exists($md5searchtitle)) {
// update existing
if($searches->loadfromid($searches->id)) {
$searches->searchnumber = $searches->searchnumber + 1;
$searches->update();
}
} else {
// add search
$searches->title = $this->dbtablename . " " . $searchterm;
$searches->searchterm = $searchterm;
$searches->searchclass = $this->dbtablename;
$searches->searchnumber = 1;
$searches->md5 = $md5search_title;
$searches->add();
}
}
}
}
/ add search result /</code></pre>
<p><img style="display: block; margin-left: auto; margin-right: auto;" src="https://i.imgur.com/oMCsNeL.png" /></p>
<h3>Git Commit Differences</h3>
<p><img src="https://i.imgur.com/4Z1C8Iv.png" /></p>
