It is currently 18 Feb 2018, 09:08

Anything Goesphpbb How I made my forum save user searched keywords (Showcase | Slideshow)

Anything, almost anything at all
(even advertisement if it's decent, spammers will be banned)
Post Reply
User avatar
tim

Administrator
View: Showcase | Slideshow
Topic Posts: 2/2
Posts: 2155
Joined: 26 Sep 2016, 00:16
Cash on hand: 7,887.02 GLP
Bank: 51,356.25 GLP
Gender: Guy
Location: Victoria, BC
Website: https://gimplearn.net
Operating System: Windows
GIMP Version: 2.8.22
My Personal Blog
My FineArtAmerica
x 1192
x 256
Contact:
Canada

phpbb How I made my forum save user searched keywords

Post#1 by tim » 16 Sep 2017, 23:16


I added a table named keywords, with columns words varchar(256) and count int.
Find this line in search.php

Code: Select all

$search_forum	= $request->variable('fid', array(0));
Add after

Code: Select all

// HACK to save keywords that were searched for. =================================
$conn = new PDO("mysql:host=localhost;dbname=yourdb",'dbuser','dbpassword');
$query = 'INSERT INTO keywords(words,count) SELECT :keywords,0 FROM (SELECT 1)T WHERE NOT EXISTS (SELECT 1 FROM keywords WHERE words = :keywords)';
$sth = $conn->prepare($query);
$sth->execute(array(':keywords' => $keywords));
$query = 'UPDATE keywords SET count = count+1 WHERE words = :keywords';
$sth = $conn->prepare($query);
$sth->execute(array(':keywords' => $keywords));
$sth = null;
$conn = null;
// HACK ends
That's it and then i created a custom page the queried from this table and ordered it by descending count.
which can be viewed here: https://gimplearn.net/searches.php
0 x



aka Tin
Image gimplearn.net                                              

Registered members enjoy ads-free content
User avatar
tim

Administrator
View: Showcase | Slideshow
Topic Posts: 2/2
Posts: 2155
Joined: 26 Sep 2016, 00:16
Cash on hand: 7,887.02 GLP
Bank: 51,356.25 GLP
Gender: Guy
Location: Victoria, BC
Website: https://gimplearn.net
Operating System: Windows
GIMP Version: 2.8.22
My Personal Blog
My FineArtAmerica
x 1192
x 256
Contact:
Canada

Post#2 by tim » 17 Sep 2017, 17:33


Then I decided to also save number of results found for each search so i added a column named found(int) that defaults to zero.
and then
found this code

Code: Select all

$template->assign_vars(array(
		'SEARCH_TITLE'		=> $l_search_title,
		'SEARCH_MATCHES'	=> $l_search_matches,
		'SEARCH_WORDS'		=> $keywords,
		'SEARCHED_QUERY'	=> $search->get_search_query(),
		'IGNORED_WORDS'		=> (!empty($common_words)) ? implode(' ', $common_words) : '',

		'PHRASE_SEARCH_DISABLED'		=> $phrase_search_disabled,

		'TOTAL_MATCHES'		=> $total_match_count,
add before

Code: Select all

// HACK to save keywords that were searched for. =================================
	$conn = new PDO("mysql:host=localhost;dbname=yourdb",'dbuser','dbpassword');
	$query = 'UPDATE keywords SET found = :found WHERE words = :keywords';
	$sth = $conn->prepare($query);
	$sth->execute(array(':keywords' => $keywords,':found' => $total_match_count));
	$sth = null;
	$conn = null;
	// HACK ends
And changed my custom reporting page to show this found column as well so that people can quickly see which keywords are searched and how many results are returned.
0 x



aka Tin
Image gimplearn.net                                              

Post Reply

Last 20 Members Who Visited This Topic

User avatar tim (8), User avatar gnerd (1), User avatar RJKD (1)

  • Similar Topics
    Replies
    Views
    Last post
• Featuring Members' Works (Image Attachments Only) •
1: animicule
2: gnerd
3: Alan
4: oldmangrumpy
5: Issabella
6: tim
7: gnerd

Who is online

Users browsing this forum: No registered users and 1 guest