Plus Minus feature in searchbox

Get help with installation and running phpBB 3.0.x here. Please do not post bug reports, feature requests, or MOD-related questions here.
Ideas Centre
Forum rules
END OF SUPPORT: 1 January 2017 (announcement)
kinkazu
Registered User
Posts: 4
Joined: Tue Jun 16, 2009 10:55 am

Plus Minus feature in searchbox

Post by kinkazu »

Hi all.
I would like to disable + - feature in search function as my forum will be about products and models like ex-23, rt-12 etc. So at this moment there is no chance to find topics which include rt-12 as it looks for all posts with rt and without 12, and I want to fix this. Any chance to get an helpful advice here?
Best regards
kinkazu
Registered User
Posts: 4
Joined: Tue Jun 16, 2009 10:55 am

Re: Plus Minus feature in searchbox

Post by kinkazu »

That is how google does it:

Terms you want to exclude (-)
Attaching a minus sign immediately before a word indicates that you do not want pages that contain this word to appear in your results. The minus sign should appear immediately before the word and should be preceded with a space. For example, in the query [ anti-virus software ], the minus sign is used as a hyphen and will not be interpreted as an exclusion symbol; whereas the query [ anti-virus -software ] will search for the words 'anti-virus' but exclude references to software. You can exclude as many words as you want by using the - sign in front of all of them, for example [ jaguar -cars -football -os ]. The - sign can be used to exclude more than just words. For example, place a hyphen before the 'site:' operator (without a space) to exclude a specific site from your search results.
kinkazu
Registered User
Posts: 4
Joined: Tue Jun 16, 2009 10:55 am

Re: Plus Minus feature in searchbox

Post by kinkazu »

I am trying and trying and I can't get rid off that - feature. If it works at least as Google one it would be great. - is treated as minus only when it is a first character of the new word in search box.
kinkazu
Registered User
Posts: 4
Joined: Tue Jun 16, 2009 10:55 am

Re: Plus Minus feature in searchbox

Post by kinkazu »

I found a cure. It is not exactly what I need, but it will do the job till I get a better solution.
I've put a simple function in overall_header.html

Code: Select all

function replace()
{
  document.getElementById('search').keywords.value = document.getElementById('search').keywords.value.replace('-', ' ');
}
that changes all - to blank spaces just before form is sumbitted.

in overall_header.html and and search_body.html there is an onlick action on submit buttons to call repleace() function.

Code: Select all

<input class="button2" value="{L_SEARCH}" type="submit" onclick="replace()"/>


I will still seek for a better solution which simply finds all text-text words in my forum.
User avatar
MichaelTunnell
Registered User
Posts: 211
Joined: Fri Apr 29, 2005 9:46 pm
Location: don't rush me
Name: Michael Tunnell
Contact:

Re: Plus Minus feature in searchbox

Post by MichaelTunnell »

It is possible to disable it however trying to make it work on the first word and not anywhere else is kind of futile considering no one searches like that.

Anyway you will need to edit a file in order to apply this modification.


OPEN - root/search.php

FIND

Code: Select all

$keywords		= utf8_normalize_nfc(request_var('keywords', '', true));
REPLACE WITH

Code: Select all

$keywords		= "\"".utf8_normalize_nfc(request_var('keywords', '', true))."\"";
I have not tested this but this will add quotes to every search such as "rt-12" making it look for rt-12 as a full word rather than rt(minus)12
MaFeSa
Registered User
Posts: 175
Joined: Wed Feb 11, 2009 7:48 am

Re: Plus Minus feature in searchbox

Post by MaFeSa »

The only solution that seems to work in my forum with phpBB 3.0.6 is kinkazu method !

If i search:
"Test-1234" -> No results
"Test 1234" -> OK !!

I will try ... :roll:
Last edited by MaFeSa on Sat Dec 05, 2009 6:51 pm, edited 1 time in total.
MaFeSa
Registered User
Posts: 175
Joined: Wed Feb 11, 2009 7:48 am

Re: Plus Minus feature in searchbox

Post by MaFeSa »

Nothing ... I'm going crazy !!

The kinkazu mod does not work on 3.0.6 and returns always Test-1234
MaFeSa
Registered User
Posts: 175
Joined: Wed Feb 11, 2009 7:48 am

Re: Plus Minus feature in searchbox

Post by MaFeSa »

After four months of trying I realize that with phpBB is IMPOSSIBLE to find post with subject that contain words with character - (minus) For example Test-123-OK

:cry:
User avatar
triadruid
Registered User
Posts: 73
Joined: Thu Jul 16, 2009 9:58 pm

Re: Plus Minus feature in searchbox

Post by triadruid »

That's true, but only if you're using the full native search. mysql search is slightly more 'logical', but isn't enabled in all installations.
MaFeSa
Registered User
Posts: 175
Joined: Wed Feb 11, 2009 7:48 am

Re: Plus Minus feature in searchbox

Post by MaFeSa »

triadruid wrote:That's true, but only if you're using the full native search. mysql search is slightly more 'logical', but isn't enabled in all installations.
No, it is NOT possible also with mysql search !
User avatar
triadruid
Registered User
Posts: 73
Joined: Thu Jul 16, 2009 9:58 pm

Re: Plus Minus feature in searchbox

Post by triadruid »

Apologies, I didn't note the "subject-line only" caveat in your post. That sounds like a bug, because searching hyphenated text in the post body seems to work fine.
MaFeSa
Registered User
Posts: 175
Joined: Wed Feb 11, 2009 7:48 am

Re: Plus Minus feature in searchbox

Post by MaFeSa »

Yes, probably a is bug.
I'm reporting from version 3.0.4 but nobody does anything.
In the meantime I switched to SMF.
triadruid wrote:Apologies, I didn't note the "subject-line only" caveat in your post.
Yes, you're right.
MaFeSa
Registered User
Posts: 175
Joined: Wed Feb 11, 2009 7:48 am

Re: Plus Minus feature in searchbox

Post by MaFeSa »

Hi ;)
Just for information ...
This problem is still present on phpbb 3.0.7 PL1 ?

Many thanks.
User avatar
AmigoJack
Registered User
Posts: 6108
Joined: Tue Jun 15, 2010 11:33 am
Location: グリーン ヒル ゾーン
Contact:

Re: Plus Minus feature in searchbox

Post by AmigoJack »

(This only applies to using MySQL fulltext search)

phpBB3.0.7-PL1 does interpret every minus as an operator, no matter if words are in quotes. This way it is not possible to get the right results when searching "Anne-Sophie", because phpBB3 always turns Anne into an inclusive and Sophie into an exclusive. However, if you have MySQL version 5 or later chances are high you can get your expected search results by saying "Anne.Sophie" instead (also with quotation marks, of course). Why? Because in a literal search every non-word character is treated the same - hence for MySQL there is no difference between "Anne-Sophie" and "Anne.Sophie" and even "Anne;Sophie". phpBB3 overinterprets on + and - itself to always assume boolean operators, which ultimately modifies your search query before it reaches MySQL. But characters like . or ; or = are not affected by phpBB3. Two Exceptions: ' and _ are considered as word-characters, so don't use them.

So the workaround without modifying any file is: turn a search of Anne-Sophie into "Anne.Sophie" (use dot instead of hyphen/minus character and enclose search in quotations marks).
  • "The problem is probably not my English but you do not want to understand correctly. ... We will not come anybody anyway, nevertheless, it's best to shit this." Affin, 2018-11-20
  • "But this shit is not here for you. You can follow with your. Maybe the question, instead, was for you, who know, so you shoved us how you are." axe70, 2020-10-10
  • "My reaction is not to everyone, especially to you." Raptiye, 2021-02-28
e.Rock
Registered User
Posts: 1
Joined: Thu Sep 08, 2011 4:31 pm

Re: Plus Minus feature in searchbox

Post by e.Rock »

This will negate the inclusion/exclusion functions of the search, but my band-aid solution was to modify root/search.php to include this line (sometime after $keywords is assigned):

Code: Select all

$keywords = str_replace('-', ' ', $keywords); 
This effectively converts the "temp-table" search string to "temp table".

With some more time, this could be improved to only work on "string-string" instead of "string -string" or "-string", but our needs lean much more towards recognizing hyphens in the string than being able to exclude a string from the search.

If anyone is better at regexps than me, please feel free to contribute a "better" solution.
Locked

Return to “[3.0.x] Support Forum”