Page 1 of 1

Quicksearch (AND and extended properties)

Posted: Sat May 07, 2011 2:14 pm
by danst0
Hi,

For my blog the current search / quicksearch (or livesearch) is kind of useless, since it does not automatically connect the search terms with and AND. So a search for more than one blog related keyword leads to several dozen of results, instead of a more specific result.
Furthermore the search does only cover the entry body and extended (and maybe tags, but not the extended properties.

I don't really get how the plugin works (neither search in general nor the livesearch). Could someone please give me a hint how to fix those issues? Maybe also as options in the backend.

Daniel

Re: Quicksearch (AND and extended properties)

Posted: Sun May 08, 2011 10:50 am
by garvinhicking
Hi!


The search uses mysql fulltext search, so you can use "+word1 +word2" to have an AND combination.

HTH,
Garvin

Re: Quicksearch (AND and extended properties)

Posted: Sun May 08, 2011 3:07 pm
by danst0
And where would I change that default behavior? I think my visitors may not know that they could use a '+'. Furthermore I would love to search the custom extended fields as well, since I have some important keywords there.

Daniel

Re: Quicksearch (AND and extended properties)

Posted: Sun May 08, 2011 3:33 pm
by kleinerChemiker
Allthough MySQL doesnt use AND, articles with all of the search words should come first in the list because MySQL does a ranking of the results.

Re: Quicksearch (AND and extended properties)

Posted: Sun May 08, 2011 4:37 pm
by danst0
Ok, but that does not solve the problem.
I see in the stats, that the visitors aren't using '+' and even though the results may be sorted it is still a mess: example from my blog: you look for 'supply chain agility' where I wrote about 3 or 4 articles about you still get about 120 results since in about every article there's one of these keywords.

To mitigate this I already have written a plugin which adds a '+' in front of every search term, but this only works for the final search results not for the livesearch results.

And even if that would work the search does not seem to include the text within the custom fields, which for my articles contain important information.

Where should I have a look within the code for these issues?

Daniel

Re: Quicksearch (AND and extended properties)

Posted: Mon May 09, 2011 10:41 am
by garvinhicking
Hi!

You can write a HTML nugget with text containing help for your visitors on how to search?

Extending the search for custom entryproperties can easily be done with a plugin, there's a hook for the entry search. Check for example the staticpage plugin, this performs additional searches for static pages, you can use that to search for your custom content if you like...

Code: Select all

To mitigate this I already have written a plugin which adds a '+' in front of every search term, but this only works for the final search results not for the livesearch results.
How do you do this? To replace this you should either replace $_REQUEST['s'] (livesearch) / $serendipity['GET']['searchTerm'] (quicksearch) in the frontend_config hook, or hook on "frontend_fetchentries" to replace $eventData on the actual SQL code, which is executed in the serendipity_searchEntries() function.

HTH,
Garvin

Re: Quicksearch (AND and extended properties)

Posted: Mon May 09, 2011 2:30 pm
by danst0
Ok, thanks, I'll have a look into the static page plugin.


That's the code I am using to add the plusses. Furthermore I changed some code so that the +'es are not displayed on the results page. Is there a better way to do that.

The disadvantage of this code is that the results one gets from the "live search" (the javascript which opens when you start typing) are different then those from the final results. And I would love to align them.

Daniel

Code: Select all

    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'])) {
                    $position = strpos($serendipity['GET']['searchTerm'],"+");
                    if ($position === false) {
                        $serendipity['GET']['searchTerm'] = str_replace(" ", " +", "+" . $serendipity['GET']['searchTerm']);
                    }
                   
                }
                return true;
                break;

              default:
                return false;
            }

        } else {
            return false;
        }
    }

Re: Quicksearch (AND and extended properties)

Posted: Mon May 09, 2011 3:10 pm
by garvinhicking
Hi!

You did read my posting about $_REQUEST['s']?

Regards,
Garvin

Re: Quicksearch (AND and extended properties)

Posted: Mon May 09, 2011 4:34 pm
by danst0
Indeed I did, but I did not understand it, now I had a look at the s9y_event_livesearch code, but I still don't know how I would catch which event to change $_REQUEST['s']...

Daniel

ps. I also read your proposal to put an html nugget somewhere explaining the plus-thing... but I don't think that would be a good solution for two reasons 1) I then had additional non-important text on my page where I don't want it (it should be self explanatory) 2) I like to limit the search results to as few as possible.

Re: Quicksearch (AND and extended properties)

Posted: Mon May 09, 2011 4:38 pm
by garvinhicking
Hi!

The same event like you currently rewrite $serendipit['GET']['searchTerm’]. You should be able to do the same, by simpy copy&paste and do it with $_REQUEST's'....
ps. I also read your proposal to put an html nugget somewhere explaining the plus-thing... but I don't think that would be a good solution for two reasons 1) I then had additional non-important text on my page where I don't want it (it should be self explanatory) 2) I like to limit the search results to as few as possible.
What would you suggest?

Regards,
Garvin

Re: Quicksearch (AND and extended properties)

Posted: Mon May 09, 2011 9:08 pm
by danst0
That was way easier than expected. I just was not aware of the $_REQUEST variable. I searched a little bit without success, is there some documentation about this?

With this solution the search problem is solved for me. Both live- and quick search now always use '+' as connector.
Of course it would be nice to have this as a general option in the quick / livesearch plugin.

Daniel

ps. I also already included the search within the custom fields.
I posted the code of the plugin here: http://pastebin.com/7YpHamB5

Re: Quicksearch (AND and extended properties)

Posted: Wed May 11, 2011 9:06 am
by danst0
A good example for a search function that I find quite intuitive: http://www.reichelt.de

eg. search for "stiftleiste 2x gerade 2,54" starting first with only the first term and then adding the others. with each iteration the number of results decreases until you find what you want!
If you used the s9y (or) search for that the number of results would increase with each iteration.

I am not familiar with "web search theory", so maybe there is an application for an or-search, but there definitely is an application for and-connected search!

What confuses me is that I seem to be the only one concerned with or using the search this way...

Daniel