WordPress.org

Forums

Relevanssi - A Better Search
[resolved] Relevanssi and numbers. (18 posts)

  1. samueljeden
    Member
    Posted 1 year ago #

    Hi Mikko,

    Im having a real problem searching for numbers inside a a product field.

    my example is

    https://www.maes-group.co.uk/shop/lucas/iveco-ford-cargo-12-volt-10-tooth-starter-motor/

    You can see here in the additional information tab that there are a list of cross reference numbers.

    in this list any long number works perfect, but short 5 digit numbers do not.

    IE

    if you use the search box at the top (for products only) and search:
    0986012470 it links directly back to the product.

    HOWEVER
    if you search 26341 - this does not work. it is the same on all of my products.

    NOW

    if you have a number with a letter at the end ie 25605D
    if you search 25605 it works how it should but if you search 25524 it doesn't work. (which is in the same list as 25605)
    IM REALLY CONFUSED. I HAVE JUST UPDATED TO 3.6 and i think everything was working right before.

    PLEASE HELPP!!!!

    Thanks
    Samuel@MAES

    http://wordpress.org/plugins/relevanssi/

  2. Mikko Saari
    Member
    Plugin Author

    Posted 1 year ago #

    What is your minimum word length setting in Relevanssi settings? Could it be six?

  3. samueljeden
    Member
    Posted 1 year ago #

    Minimum word length is 2.

  4. Mikko Saari
    Member
    Plugin Author

    Posted 1 year ago #

    Well, I have to say I don't know, not without looking under the hood. Have you tried re-indexing the database and deactivating and reactivating the plugin?

  5. samueljeden
    Member
    Posted 1 year ago #

    Hey Mikko,

    yes, ive tried both those things - its a strange occurance.

    as far as im aware it worked flawlessly before i updated wordpress to 3.6 - but that was only in tests.

    it was only brought to my attention when someone in the shop front tried using the website for a product that indeed we did sell but could not be located by its 5 digit reference :/

    do you want any details for login? i remember that you looked at my site for woocommerce issues before.

  6. samueljeden
    Member
    Posted 1 year ago #

    i can confirm this number 26341 is in the postmeta table too. i have checked via phpmyadmin for this to make sure it is being saved correctly.

  7. Mikko Saari
    Member
    Plugin Author

    Posted 1 year ago #

    You can check the _relevanssi table as well - does the number appear there in the "term" column?

    You can send me the logins to mikko @ mikkosaari.fi.

  8. samueljeden
    Member
    Posted 1 year ago #

    Hey Mikko,

    there is no record of the 26341 word in the _relevanssi table.

  9. Mikko Saari
    Member
    Plugin Author

    Posted 1 year ago #

    Looks like there's a bug in Relevanssi in how numeric search terms are handled. Next version will fix that.

  10. Charles St-Pierre
    Member
    Posted 1 year ago #

    Hi Mikko,

    I’m facing exactly the same problem.
    1-Do you have an update on the problem?
    2-Do you need a hand?
    3-Where should I look?

  11. Charles St-Pierre
    Member
    Posted 1 year ago #

    My bad, all is good.

    Mikko, I love your plugin.

  12. vinx77
    Member
    Posted 1 year ago #

    Same problem here, but then with version numbers. So searching for i.e. "WordPress+3.7" would ignore "3.7". Especially on technical websites this is a problem.

    Thanks for the great plugin! I love it.

  13. vinx77
    Member
    Posted 1 year ago #

    I solved it in common.php

    Replace

    $a = preg_replace('/([[:punct:]])+/u', ' ', $a);

    with

    $a = preg_replace('/((?!(\.\d))[[:punct:]])+/u', ' ', $a);

    This leaves numbers like ".55" and "3.7" in the index, while before they were changed to "55" and "3 7"

    Hope this helps others too.

  14. Mikko Saari
    Member
    Plugin Author

    Posted 1 year ago #

    Changing the default function is a bad idea, as your changes will be then overwritten when Relevanssi is updated. Instead, make a copy of the relevanssi_remove_punct() function, call it something else (say vinx77_remove_punct()), make changes there and then add this:

    remove_filter('relevanssi_remove_punctuation', 'relevanssi_remove_punct');
    add_filter('relevanssi_remove_punctuation', 'vinx77_remove_punct');

    This function is designed to be replaced with another function if necessary, so there's no reason to change the function in common.php.

  15. vinx77
    Member
    Posted 1 year ago #

    Thanks Mikko for the suggestion, as indeed I need to edit with every update. :) I'd prefer if you could add an option for indexing numbers, of course.

    Now got below code, but doesn't work if I put it in my template's functions.php - rebuilding the index doesn't work (0 documents in the index). Where should I put it? Or what should I do different?

    function relevanssi_remove_punct_not_numbers() {
    	$a = strip_tags($a);
    	$a = stripslashes($a);
    
    	$a = str_replace("·", '', $a);
    	$a = str_replace("…", '', $a);
    	$a = str_replace("€", '', $a);
    	$a = str_replace("­", '', $a);
    	$a = str_replace(chr(194) . chr(160), ' ', $a);
    	$a = str_replace(" ", ' ', $a);
    	$a = str_replace('’', ' ', $a);
    	$a = str_replace("'", ' ', $a);
    	$a = str_replace("’", ' ', $a);
    	$a = str_replace("‘", ' ', $a);
    	$a = str_replace("”", ' ', $a);
    	$a = str_replace("“", ' ', $a);
    	$a = str_replace("„", ' ', $a);
    	$a = str_replace("´", ' ', $a);
    	$a = str_replace("—", ' ', $a);
    	$a = str_replace("–", ' ', $a);
    	$a = str_replace("×", ' ', $a);
    
            $a = preg_replace('/((?!(\.\d)):punct:)+/u', ' ', $a);
    	//$a = preg_replace('/:punct:+/u', ' ', $a);
            $a = preg_replace('/:space:+/', ' ', $a);
    	$a = trim($a);
    
            return $a;
    }
    
    if ( function_exists( 'relevanssi_remove_punct' ) ) {
    
    	remove_filter('relevanssi_remove_punctuation', 'relevanssi_remove_punct');
    	add_filter('relevanssi_remove_punctuation', 'relevanssi_remove_punct_not_numbers');
    
    }
  16. Mikko Saari
    Member
    Plugin Author

    Posted 1 year ago #

    Your function is missing the argument, it should be

    function relevanssi_remove_punct_not_numbers($a) {

    Otherwise it seems correct to me.

  17. vinx77
    Member
    Posted 1 year ago #

    Thanks for the quick reply! And goodmorning... what a stupid mistake...

    Is there more extensive punctuation-support in the premium version? Such as easy ß->ss, numbers, shortcodes, (not) removing äccènts, etc. Or will there be?

  18. Mikko Saari
    Member
    Plugin Author

    Posted 1 year ago #

    No, it's the same in Premium. Relevanssi shouldn't remove accents in any case, Relevanssi is Unicode friendly.

    I think I'll add the ß -> ss conversion to the next version, that's quite nice.

    If you have good ideas how to improve the punctuation removal, I'm all ears, but so far this seems like a reasonable default setting to me, and if you need something else you can always change it.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Relevanssi - A Better Search
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic

Tags

No tags yet.