2

I have following Wordpress search setup :

search_form.php

 <input type="text" class="search_form clearable" name="s" id="s" autocomplete="off" placeholder="Search Text" />

search.php

 <?php if ( have_posts() && strlen( trim(get_search_query()) ) != 0 ) :
        while ( have_posts() ) :
        set_query_var( 'boxclass', 'full horizontal');
               the_post();
              .
              .
              .
        // If no content, include the "No posts found" template.
        else :
           echo '<div>No search results found</div>';
        endif;
   ?>

Now,

When I search a text of 87 characters, say :

"Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu, consequat"

A post result is found.

When I search text string of 88 characters which also exist in the post, say :
"Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu, consequata"

It returns : No search results found

How to resolve this? Is there some limit on Wordpress search term length?

cosmoloc
  • 2,884
  • 5
  • 29
  • 48

2 Answers2

2

It looks like you are hitting PHP max parameter legth limit, not related to wordpress.

See this Max size of URL parameters in _GET

Community
  • 1
  • 1
kkarpieszuk
  • 516
  • 3
  • 9
  • I am still unable to find any official article defining the Max size of URL parameters in _GET – cosmoloc Aug 09 '16 at 12:38
  • @ztit You may check this: http://php.net/manual/fr/reserved.variables.get.php#101469 Resolution is similar to the link in answer. –  Aug 09 '16 at 13:31
  • Hi kkarpieszuk, i created a test php file with GET form and checked. There is no such limitation – cosmoloc Aug 10 '16 at 07:31
  • thanks Nirjhar, but in my case, the search term has no special character. Its a single word say : "abc" gives search result while "abcd" does not.. your suggested answer would be an unclean work around to search it in 2 parts – cosmoloc Aug 10 '16 at 07:33
1

I found the issue to the problem. The issue lies in WP Core file where the actual search takes place, i.e.

wp-includes/query.php => function parse_search(){.....}

Issue was under :

if ( empty( $q['search_terms'] ) || count( $q['search_terms'] ) > 9 ){                    
                     $q['search_terms'] = array( $q['s'] );
                    }

i.e. As per WP Core method, if search string has all words in it i.e. the search terms' (excluding if/the/of etc type words filtered under function parse_search_terms() in query.php) count :

  • 1-9, the search string is split to individual words and all the search terms are individually searched(using LIKE clause) in the posts table title and content and these are ANDed together

For ex :

 ((test_posts.post_title LIKE '%Officers%') OR (test_posts.post_content LIKE '%Officers%')) AND ((test_posts.post_title LIKE '%Manager%') OR (test_posts.post_content LIKE '%Manager%'))
  • 0 or >9, the search string is search as a single complete string in the DB

For ex.

((test_posts.post_title LIKE '%Officers and Managers are working and coordinating into an atmosphere of healthy development in the year 1982 of bright age%') OR (test_posts.post_content LIKE '%Officers and Managers are working and coordinating into an atmosphere of healthy development in the year 1982 of bright age%'))

Now, in my case, * In 86 characters, my search terms array count was 9, and thus each search term was being searched in SQL DB separately and all the searches were "AND"ed together. * In 87 characters, my search terms array count was 10, thus the final search term was NOT being split to individual words, and being searched as a single string. And since the string in the DB had an html tag in between, thus as a single string it did not give post as result.

Thus it was not the count of characters, but the count of words in $q['search_terms'] that was posing the logic difference.

Hope it helps.Thanks

cosmoloc
  • 2,884
  • 5
  • 29
  • 48