• Resolved dannydanny

    (@dannydanny)


    I’m sure this has been answered, but I’m tired of looking for the answer. I see that Relevanssi replaces apostrophes with white space, but then that causes strange search results at times. Say I’m doing a search for God’s Grace. Relevanssi highlights the word God and every single letter s in the excerpt. I have read your posts that this is standard search engine behavior, but that doesn’t happen to me when I search google, or even when I use my search engine on my previous site (Zoom Search). When I use apostrophes in a search term and then search for it, the search results display what I’m looking for (e.g., I search for God’s grace and the results show God’s grace, not God and also every single letter s). I’m sure there’s a simple fix so that words searched can be exactly what is displayed in the results . . .

    Also, you talk about Relevanssi not being able to handle tens of thousands of posts but how about five or six hundred pages that are much longer than a typical post?

    THANK YOU! It is a great plugin.

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

Viewing 8 replies - 1 through 8 (of 8 total)
  • I know a quick temporary fix for you. Of course, make a backup of any file you change before you change it.

    In your Relevanssi files, find the common.php file in the lib folder. Look for the function relevanssi_remove_punct. In that section, you will see a list of all the punctation that is either replaced by a space, or stripped out (by not being replaced with anything.)

    Find the line with the apostrophe that your site uses. The code will look something like this:

    $a = str_replace(“‘”, ‘ ‘, $a);

    In the array, the punctation inside the quotations is the punctuation that is being replaced. Whatever is in between the second set of single quotes is what the punctuation is being replaced with. If you don’t want the space, take it out but leave the single quotes.

    $a = str_replace(“‘”, ”, $a);

    If you don’t want the punctuation to change at all, simple remove the line.

    Save your changes, replace the online file with your modified file, and test it. This is not a change that affects the search index, so you should be able to see it immediately.

    Remember, this is a temporary fix because doing it this way means you have to change this file everytime you update the plugin.

    Is there any update on this? I am having the same issue where the ‘s’ after any apostrophe/single quote is being separated into its own search word which then highlights every ‘s’ on the page. This is not correct search behavior and I can apply technogizmo’s fix but I use this plugin on many sites so that would require me to make manual edits to each site every time the plugin updates.

    Is there a better fix or is it possible for the plugin author to include an option for how to handle apostrophes/quotations/single quotes?

    Plugin Author Mikko Saari

    (@msaari)

    First of all – technogizmo is on the right tracks, but there’s no need to modify Relevanssi files when you can use filters. The punctuation removal is done through the filter relevanssi_remove_punctuation and you can hook onto that to change how the punctuation is handled.

    Just add this to your functions.php (and rebuild the index, because this very much is a change that affects the index, unlike technogizmo says):

    add_filter('relevanssi_remove_punctuation', 'remove_apostrophes', 9);
    function remove_apostrophes($a) {
        $a = str_replace("'", '', $a);
        return $a;
    }

    Relevanssi should have no problems with hundreds of long posts, unless you’re talking about millions and millions of words.

    And you’re right, the highlighting doesn’t make much sense when you’re looking for something like “god’s”. However, there’s no easy solution to it, either. I’ll probably have to rewrite the way the queries are handled to keep the punctuation together for highlighting purpose – currently the code is the same for highlighting and for searching, and in searching this is definitely the way to go. In highlighting, not so much.

    But I’ll take a look at this. Perhaps there’s a solution for this in the next version, if I can come up with something useful.

    Anyway, since you wanted an option for how to handle the punctuation, you’ve got it – you just need to use the filters. It doesn’t help with the highlights, though, only searching.

    Thread Starter dannydanny

    (@dannydanny)

    Thanks technogizmo, and thanks Mikko. Your code words perfectly. I just added a functions.php file to my child theme with your code and voila! it works. Thank you for your support. I’m considering purchasing the pro version although I’m not 100% sure it’s necessary at this time for my needs. What a great plugin. WordPress’s search is literally useless without it.

    Plugin Author Mikko Saari

    (@msaari)

    Also, I’m changing the highlighting in the next version in a way that should highlight only “god’s”, and nothing else, no extra “s”:s or anything.

    Thread Starter dannydanny

    (@dannydanny)

    Does this mean that when the next version comes out I can delete that code out of my functions.php file? 😉

    Thanks again!

    Plugin Author Mikko Saari

    (@msaari)

    Yes, it should.

    Hi Mikko,

    Thanks for all the information and great plugin.

    When searching on oikonos.org using Relevanssi plugin…
    Stejneger's Petrel
    Stejneger is not highlighted
    Petrel is highlighted.

    If we use curly apostrophe to exactly match content
    Stejneger’s Petrel
    Then every “s” is highlighted in search results
    and Stejneger’s is still not highlighted.

    I did add this code to functions.php as you said to do earlier in this thread regarding apostrophes

    add_filter('relevanssi_remove_punctuation', 'remove_apostrophes', 9);
    function remove_apostrophes($a) {
        $a = str_replace("'", '', $a);
        return $a;
    }

    We updated plug-in yesterday and built the index again.

    Regards,
    Greg

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Apostrophes’ is closed to new replies.