Page 1 of 1
Adjust Search Plugin
Posted: Tue Feb 01, 2011 12:56 pm
by danst0
Hi,
where do I find the code for the quicksearch plugin. I would love to replace the current OR-jointed search with an AND-jointed one.
Daniel
Re: Adjust Search Plugin
Posted: Tue Feb 01, 2011 1:13 pm
by garvinhicking
Hi!
This is core functionality, you cannot easily change that.
You can pass "+word1 +word2" to the search, then it will AND join both searches. To force that, you could write an even tplugin that listens on 'frontend_configure' and rewrites the $serendipity['GET']['searchTerm'] variable so that each word has a "+" in front of it.
Regards,
Garvin
Re: Adjust Search Plugin
Posted: Tue Feb 01, 2011 1:28 pm
by danst0
When I do a: find . -name \*.php -exec grep -i -l -d skip "serendipity_plugin_api::hook_event('frontend_configure'" {} \;
On my installation I only get serendipity_config.inc.php as result, do you by accident know a plugin that uses the hook?
Daniel
Re: Adjust Search Plugin
Posted: Tue Feb 01, 2011 3:01 pm
by garvinhicking
Hi!
You better search for "case 'frontend_configure'" to find these.
A simple plugin that listens there is serendipity_event_templatechooser (or maybe serendipity_event_templatedropdown I don't remember).
Regards,
Garvin
Re: Adjust Search Plugin
Posted: Wed Feb 02, 2011 6:24 am
by danst0
Ok, and I call it ANDSearch
Code: Select all
class serendipity_event_andsearch extends serendipity_event
{
var $title = PLUGIN_EVENT_ANDSEARCH_NAME;
function introspect(&$propbag)
{
global $serendipity;
$propbag->add('name', PLUGIN_EVENT_ANDSEARCH_NAME);
$propbag->add('description', PLUGIN_EVENT_ANDSEARCH_DESC);
$propbag->add('stackable', false);
$propbag->add('author', 'Daniel Stengel');
$propbag->add('version', '0.9');
$propbag->add('requirements', array(
'serendipity' => '0.8',
'smarty' => '2.6.7',
'php' => '4.1.0'
));
$propbag->add('groups', array('FRONTEND_FEATURES'));
$propbag->add('event_hooks', array('frontend_configure' => true));
}
function generate_content(&$title) {
$title = $this->title;
}
function event_hook($event, &$bag, &$eventData) {
global $serendipity;
$hooks = &$bag->get('event_hooks');
if (isset($hooks[$event])) {
switch($event) {
case 'frontend_configure':
if (isset($serendipity['GET']['searchTerm'])) {
$serendipity['GET']['searchTerm'] = str_replace(" ", " +", " " . $serendipity['GET']['searchTerm']);
//echo $serendipity['GET']['searchTerm'];
}
return true;
break;
default:
return false;
}
} else {
return false;
}
}
}
/* vim: set sts=4 ts=4 expandtab : */
?>
Works as designed.
Is it somehow possible to get rid of the pluses at the result output? (here: "Your search for +test returned 6 results")
Daniel
Re: Adjust Search Plugin
Posted: Wed Feb 02, 2011 8:49 am
by Timbalu
HI
Yes with smarty inside the output tpl:
Ian
Re: Adjust Search Plugin
Posted: Wed Feb 02, 2011 1:43 pm
by danst0
While playing with this, i discovered the following
Code: Select all
$pos = strpos("+test","+");
if ($pos == false) {
echo "No Plus found";
}
$pos is going to be 0, but the if-clause will always be executed...
I have this code basically directly from the php-manual,
http://php.net/manual/de/function.strpos.php
Isn't it possible to detect a plus sign at the first string position? If yes, tell me how?
Daniel
Re: Adjust Search Plugin
Posted: Wed Feb 02, 2011 2:13 pm
by Timbalu
Well you asked for replacing the + in the output. This wont work in your plugin, while it puts together the search string only andf gives it to core. The output is inside a template file. (which one I dont know out of the bin)
If you are just playing around try
Code: Select all
if ($pos === false) echo "No Plus found";
else echo 'Found + in string';
else have a look at
http://www.php.net/manual/de/function.stripos.php
Ian
Re: Adjust Search Plugin
Posted: Wed Feb 02, 2011 2:28 pm
by danst0
Ok the code looks like this now and works perfectly:
Code: Select all
switch($event) {
case 'frontend_configure':
if (isset($serendipity['GET']['searchTerm'])) {
$position = strpos($serendipity['GET']['searchTerm'],"+");
if ($position === false) {
$serendipity['GET']['searchTerm'] = str_replace(" ", " +", "+" . $serendipity['GET']['searchTerm']);
}
}
return true;
break;
default:
return false;
}
I realized my problem was that there were three = signs. So at least now I know the evolution, from Basic (=) to C (==) to PHP (===)?
Daniel
Re: Adjust Search Plugin
Posted: Wed Feb 02, 2011 2:38 pm
by Timbalu
This function may return Boolean FALSE, but may also return a non-Boolean value which evaluates to FALSE, such as 0 or "".
So the === is a evolution, true!
I just like it that PHP is picky in these things.
Ian
Re: Adjust Search Plugin
Posted: Tue Jun 25, 2013 1:14 pm
by Carl @ ATS
Hi,
Although I'm new to Serendipity and am not a programmer, I've been able to install the software and create a blog of my own on my web host's server. The quicksearch plug-in is part of the basic Serendipity bundle, but where exactly can I find the plug-in (it's not where I'd expect it to be, namely together with the other plug-ins I've installed using Spartacus) and how do I go about changing the title of the feature as it appears on my blog? I don't want it to be called "quicksearch", but "quick search" with a space in the middle (standard English); since I'm a translator and editor, I want it to be spelt the standard way. So once I've managed to pinpoint the file, what do I need to change, please?
Thanks for any help.
Carl
Re: Adjust Search Plugin
Posted: Tue Jun 25, 2013 1:43 pm
by onli
The Quicksearch plugin as a core plugin is in the file include/plugin_internal.inc.php. In there you would find that it uses the constant QUICKSEARCH to generate the name and the title. The easiest way to spell the name differently is to change that constant: Add
Code: Select all
@define('QUICKSEARCH', 'Quick search');
to your serendipity_config_local.inc.php
Re: Adjust Search Plugin
Posted: Tue Jun 25, 2013 2:33 pm
by Carl @ ATS
Thanks onli,
That worked nicely.
Regards
Carl
P.S. I'm looking forward to version 2.0 of Serendipity! (I see you're working on it.) Did you know that some of the optional plug-ins for the current version don't work any more? The sites they refer to have changed. So I think it's time for the developers to update certain plug-ins now -- and also add a few new ones offering extra features. Is there a relatively easy way of creating a blogroll, for example? The current way using a plug-in with Cron jobs is very complicated and time-consuming IMHO. The easier it is to set up a blog, the better.)
Re: Adjust Search Plugin
Posted: Tue Jun 25, 2013 3:15 pm
by onli
Reagarding your PS: Thanks. We didn't touch plugins yet, apart from a bit of preparation. It is quite possible that a cleanup is necessary, but I don't think we will be able to check them all and make them work again if they are broken. Maybe a few very important ones.
Not familiar with the or another blogroll-plugin, sorry.