Announcement

#1 2023-01-29 17:49:22

BigIsland270972
Member
Norway
2022-03-15
374

Is it possible to modify search.php to search for exact match??

Hello/Hi/Greetings,

Is it possible to modify search.php to search "exact" term without adding "" ? Like a third options under field?

piwigo 13.5

Piwigo URL: http://

Last edited by BigIsland270972 (2023-01-31 13:58:52)


Piwigo 14.0 | https://fotoarkiv.no | https://foto.arki.vet | http://Bergen.gallery  | http://Ålesund.gallery | http://geiranger.gallery | http://fjord.photos | http://foto.oslo.no
Apache | PHP 8.1 | MariaDB

Offline

 

#2 2023-01-29 21:26:48

BigIsland
Member
2015-02-12
3

Re: Is it possible to modify search.php to search for exact match??

Hi. Let me explain further. When I search for "Kommune : Sande" I want the exact match for that frase. HOW?
Cheers

Offline

 

#3 2023-01-29 23:34:16

BigIsland270972
Member
Norway
2022-03-15
374

Re: Is it possible to modify search.php to search for exact match??


Piwigo 14.0 | https://fotoarkiv.no | https://foto.arki.vet | http://Bergen.gallery  | http://Ålesund.gallery | http://geiranger.gallery | http://fjord.photos | http://foto.oslo.no
Apache | PHP 8.1 | MariaDB

Offline

 

#4 2023-01-30 21:54:16

BigIsland270972
Member
Norway
2022-03-15
374

Re: Is it possible to modify search.php to search for exact match??

https://www.fotoarkiv.no//priv/qouted.png

This is suppose to get hits from the exact phrase. Its NOT! I get hits both George AND Washington
How to  fix this??


Piwigo 14.0 | https://fotoarkiv.no | https://foto.arki.vet | http://Bergen.gallery  | http://Ålesund.gallery | http://geiranger.gallery | http://fjord.photos | http://foto.oslo.no
Apache | PHP 8.1 | MariaDB

Offline

 

#5 2023-01-31 00:57:59

erAck
Only trying to help
2015-09-06
2023

Re: Is it possible to modify search.php to search for exact match??

I don't know where you got it'd be supposed to search for the quoted phrase, but you can see in search.php that's not the case. Operator characters and quotes in $drop_char_match are removed and replaced by their correspondent (blank or empty) in $drop_char_replace, words split and OR or AND clause applied.


Running Piwigo at https://erack.net/gallery/

Offline

 

#6 2023-01-31 12:17:42

BigIsland270972
Member
Norway
2022-03-15
374

Re: Is it possible to modify search.php to search for exact match??

erAck wrote:

I don't know where you got it'd be supposed to search for the quoted phrase, but you can see in search.php that's not the case. Operator characters and quotes in $drop_char_match are removed and replaced by their correspondent (blank or empty) in $drop_char_replace, words split and OR or AND clause applied.

AND That means what? Sorry confusing answer :)


Piwigo 14.0 | https://fotoarkiv.no | https://foto.arki.vet | http://Bergen.gallery  | http://Ålesund.gallery | http://geiranger.gallery | http://fjord.photos | http://foto.oslo.no
Apache | PHP 8.1 | MariaDB

Offline

 

#7 2023-01-31 12:27:44

erAck
Only trying to help
2015-09-06
2023

Re: Is it possible to modify search.php to search for exact match??

That means that from the input the double quote characters are stripped, then the input is split as words, on which the selected AND or OR clause is applied.


Running Piwigo at https://erack.net/gallery/

Offline

 

#8 2023-01-31 13:07:12

BigIsland270972
Member
Norway
2022-03-15
374

Re: Is it possible to modify search.php to search for exact match??

erAck wrote:

That means that from the input the double quote characters are stripped, then the input is split as words, on which the selected AND or OR clause is applied.

OK! Understand. So how do I search for the exact phrase??

Last edited by BigIsland270972 (2023-01-31 13:07:36)


Piwigo 14.0 | https://fotoarkiv.no | https://foto.arki.vet | http://Bergen.gallery  | http://Ålesund.gallery | http://geiranger.gallery | http://fjord.photos | http://foto.oslo.no
Apache | PHP 8.1 | MariaDB

Offline

 

#9 2023-01-31 16:55:54

BigIsland270972
Member
Norway
2022-03-15
374

Re: Is it possible to modify search.php to search for exact match??


Piwigo 14.0 | https://fotoarkiv.no | https://foto.arki.vet | http://Bergen.gallery  | http://Ålesund.gallery | http://geiranger.gallery | http://fjord.photos | http://foto.oslo.no
Apache | PHP 8.1 | MariaDB

Offline

 

#10 2023-01-31 17:33:09

BigIsland270972
Member
Norway
2022-03-15
374

Re: Is it possible to modify search.php to search for exact match??

SO the short answer is YOU CAN'T do this kind of search. What a pity.


Piwigo 14.0 | https://fotoarkiv.no | https://foto.arki.vet | http://Bergen.gallery  | http://Ålesund.gallery | http://geiranger.gallery | http://fjord.photos | http://foto.oslo.no
Apache | PHP 8.1 | MariaDB

Offline

 

#11 2023-01-31 19:48:28

TOnin
Member
1970-01-01
106

Re: Is it possible to modify search.php to search for exact match??

Hi, longer answer:
what about adding next to OR and AND; a third possibility approaching your desire?

in search.tpl add this line

Code:

<label><input type="radio" name="mode" value="EXACT"> {'Search for exact phrase'|@translate}</label>

in search.php add the third possibility EXACT in the checking code to get this line

Code:

check_input_parameter('mode', $_POST, false, '/^(OR|AND|EXACT)$/');

then modify code to handle an alternative preventing word splitting:

Code:

 
    if ($_POST['mode']=='EXACT') {
    // Do not split words
    $search['fields']['allwords'] = array(
      'words' => array_unique(
        array(
          str_replace(
            $drop_char_match,
            $drop_char_replace,
            $_POST['search_allwords']
            )
          )
        ),
      'mode' => 'AND',
      'fields' => $_POST['fields'],
      );
    }
    else {
    // Split words
    $search['fields']['allwords'] = array(
      'words' => array_unique(
        preg_split(
          '/\s+/',
          str_replace(
            $drop_char_match,
            $drop_char_replace,
            $_POST['search_allwords']
            )
          )
        ),
      'mode' => $_POST['mode'],
      'fields' => $_POST['fields'],
      );
    }

I do not provide any warranty for this tweak, nor pretend reaching full text search holy grail.
To get closer to the aim, this just miss a way to split properly input search ["a b" c d "e f g"] in 4 parts: "a b", "c", "d", "e f g".

Offline

 

#12 2023-01-31 19:59:02

BigIsland270972
Member
Norway
2022-03-15
374

Re: Is it possible to modify search.php to search for exact match??

Thanks!


Piwigo 14.0 | https://fotoarkiv.no | https://foto.arki.vet | http://Bergen.gallery  | http://Ålesund.gallery | http://geiranger.gallery | http://fjord.photos | http://foto.oslo.no
Apache | PHP 8.1 | MariaDB

Offline

 

#13 2023-01-31 20:38:16

BigIsland270972
Member
Norway
2022-03-15
374

Re: Is it possible to modify search.php to search for exact match??

Got it working but no hits when searching for Kommune: Sande and there are a thousand image desription with that exact phrase. Try Yourself: https://www.fotoarkiv.no/search.php


Best regards
Robert


Piwigo 14.0 | https://fotoarkiv.no | https://foto.arki.vet | http://Bergen.gallery  | http://Ålesund.gallery | http://geiranger.gallery | http://fjord.photos | http://foto.oslo.no
Apache | PHP 8.1 | MariaDB

Offline

 

#14 2023-01-31 21:17:00

TOnin
Member
1970-01-01
106

Re: Is it possible to modify search.php to search for exact match??

Mind removing accepted chars like ':' from $drop_char_match
Be careful with some of the others chars, the aim is not to expose your database to SQL injection.

I would try with "Kommune: Flora" because did not see any "Kommune: Sande" in my results.

Offline

 

#15 2023-01-31 23:43:10

BigIsland270972
Member
Norway
2022-03-15
374

Re: Is it possible to modify search.php to search for exact match??

TOnin wrote:

Mind removing accepted chars like ':' from $drop_char_match
Be careful with some of the others chars, the aim is not to expose your database to SQL injection.

I would try with "Kommune: Flora" because did not see any "Kommune: Sande" in my results.

Yes removed : from char_match but nether do I get any result for Kommune: Sande. STRANGE.

You can clearly se it's there: https://www.fotoarkiv.no/picture.php?/1 … af-andreas

best regards
RS

Last edited by BigIsland270972 (2023-01-31 23:43:52)


Piwigo 14.0 | https://fotoarkiv.no | https://foto.arki.vet | http://Bergen.gallery  | http://Ålesund.gallery | http://geiranger.gallery | http://fjord.photos | http://foto.oslo.no
Apache | PHP 8.1 | MariaDB

Offline

 

Board footer

Powered by FluxBB

github twitter newsletter Donate Piwigo.org © 2002-2024 · Contact