DEV Community

Discussion on: How to create small search engine for your awesome project?

Collapse
 
mrm8488 profile image
Manuel Romero • Edited

Great article! Remember to add error first management in search function:

function search(search_string, func) {
     pool.query(
        "SELECT * FROM university WHERE fts @@ to_tsquery('english',$1)", 
        [search_string],
        function(err, result) {  
            if(err) {
                func(err)
            } else {
                func(null, result.rows)
            }
        }
    );
}

And then, when you call the function:

search(req.query.text, function(error, data_items) {...}
Collapse
 
gaserd profile image
Sergey Gustun

Thanks!
Yes, i adding "error management"

Collapse
 
mrm8488 profile image
Manuel Romero

Thank you for your awesome article. I have worked with dedicated full text search database called Apache Solr. Thanks to you I know that I can use that feature in a relational DB.