Jump to content

2 questions about the search


Relmos
 Share

Recommended Posts

Hi,

I have two questions about the search coming with PW 2.3.6.

1. How would I be able to search word fragments? I only want titles to be searchable. If a title is "superdog" and you search for "dog" nothing will be found here. Only when you exactly search for "superdog".

--> Ok found the answer here: http://processwire.com/talk/topic/168-wildcard/?p=1181 But strangely it's exactly the other way around. * will find "apple" in "applesauce" where ~ does only find results matching exactly the string.

2. I have a multilingual site. How would it be possible that the search also works in other languages? For now it always switches to the default language when previously the language was switched.

--> Also found a solution here: Just have to get the language prefix as usual, for example: domain.de/es/search/, and it will search the spanish site.

Thank you.

- Relmos

  • Like 1
Link to comment
Share on other sites

1. How would I be able to search word fragments? I only want titles to be searchable. If a title is "superdog" and you search for "dog" nothing will be found here. Only when you exactly search for "superdog".

To match a partial word in the middle of it, you'd need to use a non-fulltext-indexed search. That's because fulltext indexing indexes full words, not parts of words... it can only match full words or words beginning with some text. To use a non-fulltext-indexed search, use the %= operator rather than the *= operator. 

--> Ok found the answer here: http://processwire.c...ildcard/?p=1181 But strangely it's exactly the other way around. * will find "apple" in "applesauce" where ~ does only find results matching exactly the string.

This highlights a core difference between *= and ~=. The *= operator is matching an exact word or phrase that begins with your term. The ~= operator is matching full words, but they can be matched no matter where they appear in the text / in any order. The %= operator behaves very much like the *= operator except that %= can match in anywhere in-between words too, not just words/phrases that begin with something.

2. I have a multilingual site. How would it be possible that the search also works in other languages? For now it always switches to the default language when previously the language was switched.

 So long as the $user->language is set to the language you intend to search in, it will give preference to that language in performing the search. 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...