How can I have $site->search(‘my awesome search’); search for “my awesome search” instead of “my” || “awesome” || “search”?
I want to include only the pages which have the string “my awesome search” on them (including spaces), and exclude pages which only have “my” or “awesome” or “search” on them?
I hope I make myself clear enough?
Thanks!
Bart
Unfortunately, that’s currently not possible.
You can however create your own implementation of $pages->search()
. If you comment out this and the following line and add $page->searchHits += $matches;
back in at line 219, it should do exactly what you want.
I have opened an issue over at GitHub , so maybe this will become a feature in a future version.
1 Like
Thank you for your replay @lukasbestle .
Is this something I can do as a plugin in the mean time (override the default search)?
1 Like
Sure! I have created a little plugin for you . It’s untested, so please let me know if it works.
Just drop it into your plugins
directory and use search($pages, $query, $params)
instead of $pages->search($query, $params)
.
4 Likes
I can confirm this works.
thank you very much @lukasbestle
gvocale
December 16, 2015, 5:52am
#6
I am just trying now the plugin and if I search “telefunken 12ax7” returns me few results, but if I search “12ax7 telefunken” returns no results.
Is there something that could avoid this problem to happen?
texnixe
December 16, 2015, 9:05am
#7
The plugin searches for complete string matches and not for the separate words individually, no matter in what order they appear in the text.
This deserves to be in core, at least as an option. I think it’s a behaviour expected by lots of users.
3 Likes
Thank you for the feedback, I have added your +1 to the GitHub issue.
2 Likes
Where do you find this to change it out? $pages->search($query, $params)
I’m currently using a controller
<?php
return function($site, $pages, $page) {
$query = get('q');
$results = $site->search($query, 'title|text');
return array(
'query' => $query,
'results' => $results,
'pagination' => $results->pagination()
);
};
?>
texnixe
October 6, 2016, 3:48pm
#12
@bbarclay Are you using Lukas’ plugin or do you want to make changes to the core?
@texnixe i just want my search results to be able to filter whole search terms. For instance “airline seats” and not airline and seats.
So either way. Hopefully I don’t have to modify the core.
texnixe
October 6, 2016, 4:00pm
#14
You can use the Lukas little plugin linked above?
Yeah, that’s what i was going to do. Although it says
Just drop it into your plugins directory and use search($pages, $query, $params) instead of $pages->search($query, $params).
I dropped this in my plugins folder. But when i search for something like, airline seats. It still pulls airlines and seats.
Not just “airline seats”
texnixe
October 6, 2016, 4:30pm
#17
Hm, it works in my test installation … Have you changed your controller?
From
$results = $site->search($query, 'title|text');
to
$results = search($pages->index(), $query, 'title|text');
```
I wonder if this has something to do with that custom controller. I was looking for search solutions in the past and these files were all included. So i removed my custom controller and it broke my search functionality.
I’m using the advice from here
https://getkirby.com/docs/cookbook/search
Telling me to create another controller in site/controller
Did your demo installation include that? @texnixe
Let me try this. Then I will get back to you.