Easy text search using Elastic Search

Recently I used to add very plain text search to ne.no and since I’m using Elastic Search with ElasticaBundle it was easy to achieve.

$textQuery = new \Elastica_Query_QueryString();
$textQuery->setFields(array("address", "name", "city", "searchPartNames", "searchCompanyName"));
$textQuery->setDefaultOperator("AND");
$textQuery->setQueryString($selectedText);

$tmpTexts = array();
foreach (explode(" ", $selectedText) as $oneWord) {
    $oneWord = trim($oneWord);
    if ($oneWord == "")
        continue;
    if (preg_match("/^[0-9]+/", $oneWord)) {
        $tmpTexts[] = $oneWord;
    } else {
        $tmpTexts[] = $oneWord . "*";
    }
}
$selectedText = implode(" ", $tmpTexts);

Added star-wildcard after all words, but not after numbers, so that user is able to find correct building address located on Drammensgt or Drammensvn if he searches for “Drammens 171″.

Lego


Ne.no has been released

Ne.no is out and working well. It is my second project built using Symfony2 framework.

This blog v2

After several years of silence I decided to continue blogging about things I read, see or just want to mention.