如何通过elastica在弹性搜索中找到字符串中的字符串?

时间:2015-01-21 09:47:53

标签: php elasticsearch elastica

假设我想要一个搜索结果,每个项目的这个特定字段都有字符串,例如# hashtag

例如我有一个名为description的数据字段,所以我想从结果中获得,只有那些在其描述中有字符串'hashtag'的项目,例如

"the english alphabet has 28 letters #hashtag"

所以,上面带有此描述字段的项目应该包含在搜索结果中,因为描述字段值字符串里面有一个“#hashtag”字符串。

如何在elastica中做到这一点?我应该使用什么过滤或功能?

1 个答案:

答案 0 :(得分:0)

<?php
$mystring = 'abc';
$findme   = 'a';
$pos = strpos($mystring, $findme);

// The !== operator can also be used.  Using != would not work as expected
// because the position of 'a' is 0. The statement (0 != false) evaluates 
// to false.
if ($pos !== false) {
     echo "The string '$findme' was found in the string '$mystring'";
         echo " and exists at position $pos";
} else {
     echo "The string '$findme' was not found in the string '$mystring'";
}
?>