Coder Social home page Coder Social logo

zodiac1978 / wp-search-ignore-block-names Goto Github PK

View Code? Open in Web Editor NEW
3.0 2.0 3.0 260 KB

Modifies the native search to ignore block editor comments

Home Page: https://wordpress.org/plugins/ignore-block-name-in-search/

License: GNU General Public License v2.0

PHP 100.00%
blockeditor gutenberg search wordpress wordpress-plugin

wp-search-ignore-block-names's Introduction

Ignore HTML and shortcodes in search

Modifies the native search to ignore HTML markup (block editor comments) and shortcodes

Why?

This plugin modifies the native wordpress search feature to ignore HTML markup (like block names) and shortcodes in your content.

With this plugin activated the unexpected search results are fixed which are reported in #3739 and in #56294

Works only for MySQL 8.0.4+ and MariaDB 10.0.5+

Frequently Asked Questions

I don't see any changes.

This plugin has no settings page, it modifies the internal search to ignore HTML and HTML comments in the post markup.

Imagine a development blog using a syntaxhighlighting block. If you search on this blog to find posts with the term "syntaxhighlighting" you will get every post with code and not only those post which are really about syntax highlighting.

What about the alt/title attribute?

At the moment this is not searched for anymore with this plugin. Maybe I can specifically allow this in a future version of the plugin.

I need more features!

This plugin just wants to solve this particular problem without too much overhead. If you need more customizations to your search, then please have a look at Relevanssi or Better Search.

These plugins are building up an index from your content and are therefore solving the underlying issue in another way with much more ways to customize it. And they will be even faster.

Can I help you?

Thanks for asking! Yes, I'm very interested in edge cases and incompatibilities (other plugins or server configurations). Please open a new issue for this.

Thanks

Props for helping to fix this go to espiat, l1nuxjedi, mustafauysal, ravishaheshan, and websupporter!

Changelog

1.2.0

  • Fixed broken search for title and excerpt
  • Ignore shortcodes additionally to markup
  • Rename plugin

1.1.1

  • Added back link to error message, if REGEXP_REPLACE is not supported
  • Fixed some typos

1.1.0

  • Changed approach to remove the markup (now requires MySQL 8.0.4+ or MariaDB 10.0.5+)

1.0.0

  • Initial public release

wp-search-ignore-block-names's People

Contributors

mustafauysal avatar zodiac1978 avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

wp-search-ignore-block-names's Issues

Adding a toggle for the internal search in admin area

Looks like an excellent solution. Does this filter backend searches as well? I find that searching for blocks can be quite useful there. Might be worth adding an is_admin()...
Source: Roy Tanck (@roytanck) on Twitter

To allow searching for blocks as well, we could add a toggle to enable/disable searching for block comments.

Search for title and excerpt is broken with this plugin

A simplified Query for a standard search is this

SELECT SQL_CALC_FOUND_ROWS wp_posts.ID 
FROM wp_posts WHERE 1=1 
AND (((wp_posts.post_title LIKE '%wat%') 
OR (wp_posts.post_excerpt LIKE '%wat%') 
OR (wp_posts.post_content LIKE '%wat%')))

This plugin adds a new condition:

$where .= " AND REGEXP_REPLACE({$wpdb->posts}.post_content, '<.+?>', '') LIKE '%{$search_query}%'";

This breaks searching for title and excerpt.

We need to add the two OR statements again to fix this.

Not working as expected

Your solution doesn't work when the search term is in both tags and content. ex: this is a paragraph the post with this content doesn't get captured when searching for "paragraph" because of the AND clause in your query

See: https://core.trac.wordpress.org/ticket/56294#comment:5

Unfortunately I did not find a simple way to achieve this with MySQL below 8.
Since MySQL 8 there is REPLACE_REGEXP which would solve this:
https://stackoverflow.com/questions/986826/how-to-do-a-regular-expression-replace-in-mysql

See: https://core.trac.wordpress.org/ticket/56294#comment:6

I will try to get this working at least with MySQL 8+ (and with the according MariaDB version). If this works, there needs to be some MySQL version checking built in.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.