我有以下Wordpress搜索设置:
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;
?>
现在,
当我搜索87个字符的文本时,请说:
“茉莉花胡萝卜,改善生态环境。茉莉花方便保留的需求。茉莉花质量。当立即拉动超级碗山脉的光芒时。直到橄榄球,小酒馆,儿童足球,一人的价格,沙拉。没有摄影质量的人。直到脚都没有按香蕉分类,牛肉功能齐全,价格低廉;实际上是为了进行灭菌生活理财而烤制的;是足球足球软底价的转播;整数开发者;明天的蛋白质;即使并非总是这种元素也活着;不可抵扣的区域;茉莉花保留的狮子,风,足球,摄影”
找到发布结果。
当搜索1个也包含88个字符的文本字符串时,说:
“ lorem ipsum胡萝卜,改善生态环境。茉莉花便利性保留需求。茉莉花质量。当立即拉动超级碗山脉的光芒时。 ,一种沙拉的价格,那里没有菜谱,直到用香蕉对脚进行分类,并且牛肉功能齐全,价格不菲,实际上是公平的,为了资助一种无菌生活疗法而被烤制,转播足球是软气价格。开发商。明天的蛋白质。除非有元素,否则将永远活着。Nunc的可扣除区域。茉莉狮子保留,贷款,相应地,
返回:未找到搜索结果
如何解决呢?Wordpress搜索字词的长度有一些限制吗?
我发现问题所在。问题出在实际进行搜索的WP Core文件中,即
wp-includes / query.php =>函数parse_search(){.....}
问题在:
if ( empty( $q['search_terms'] ) || count( $q['search_terms'] ) > 9 ){
$q['search_terms'] = array( $q['s'] );
}
即按照WP Core方法,如果搜索字符串中包含所有单词,即搜索词(不包括if / the / of等类型的单词,这些单词在query.php中的parse_search_terms()函数下过滤)。
- 1-9,将搜索字符串拆分为单个单词,并在帖子表标题和内容中单独搜索所有搜索词(使用LIKE子句),并将它们与在一起
对于前:
((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或> 9,则在数据库中将搜索字符串作为单个完整字符串进行搜索
对于前。
((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%'))
现在,以我为例,*在86个字符中,我的搜索词数组计数为9,因此每个搜索词在SQL DB中被单独搜索,并且所有搜索都被“与”在一起。*在87个字符中,我的搜索词数组计数为10,因此最终的搜索词未拆分为单个单词,而是作为单个字符串进行搜索。而且由于数据库中的字符串之间有一个html标记,因此作为单个字符串,它不会给出结果。
因此,构成逻辑差异的不是字符数,而是$ q ['search_terms']中的单词数。
希望能帮上忙。谢谢
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句