问题
I'm using Plone 4.3 in a little intranet and the search fiel makes me feel annoying. Live search works fine but when you push enter, the search shows different results. The results can be obtained by adding a "" top the end of the text and then it shows the same results as livesearch. So I ask, is ti possible to insert automatically a "" when pushin enter key in order to achieve the same results as livesearch?
thanks
pd: my english is not very good, sorry
回答1:
As live search is displaying results as the user is entering letters, it makes sense to perform a query for all words starting with the current term (for instance if you have entered "car", you get results containing the word "car" but also "careful", because we cannot tell yet if you have finished typing letters). In the advanced search, when you search for "car", the system knows you rae interested in results about "car", not about "careful". So that's why the 2 searches work differently.
And Plone assumes that when we press Enter in the livesearch, we have finished entering the word we are looking for, so it redirects to the advanced search page using the exact search term we have entered.
It is implemented in the searchbox viewlet, you will find the code in plone.app.layout/plone/app/layout/viewlets/searchbox.pt
, and as you can see it is a very basic form submitting the "SearchableText" input to "@@search".
To me, the easiest way to customize it is to add a small JS like this somewhere in your skin:
$('#portal-searchbox form').submit(function(e) {
var input = $('#portal-searchbox input[name="SearchableText"]');
input.val(input.val() + '*');
});
来源:https://stackoverflow.com/questions/41811422/customize-plone-search