0

i concatted postal code, state, city, and country code and created a new column called location. i put a fulltext index on location. sometimes the search works well with good accuracy, and other times nothing gets returned

search.php code:

<?php

require(__DIR__ . "/../includes/config.php");

// numerically indexed array of places
$places = [];

//split on commas or spaces
$query = preg_split("/[\s,]+/", $_GET["geo"]);
$items = count($query); //max index = $items - 1


//loop $items number of times and add a word to the query string

//queries will look something like: "+ma* +cambri*"
$queries = "";
for ($i = 0; $i < $items; $i++) {
    $queries .= ('+' . $query[$i] . '* ');
}

$sql_search = "SELECT * FROM places WHERE MATCH(city, state) AGAINST ('{$queries}' IN BOOLEAN MODE)";

$places[] = CS50::query($sql_search);

//output places as JSON (pretty-printed for debugging convenience)
header("Content-type: application/json");
print(json_encode($places, JSON_PRETTY_PRINT));


?>

example of a row in my location column:

New Haven Connecticut 06503 US

when i do a search via search.php with new haven, nothing comes back

when i do a search via search.php with "US" somewhere in the query, nothing comes back

when i do a search on phpadmin like

...AGAINST ("+haven +con*" IN BOOLEAN MODE), 

i get back some nice results. if i do

...AGAINST("+ne* +haven*" IN BOOLEAN MODE) 
 or
...AGAINST("+haven* +US*" IN BOOLEAN MODE)

then nothing gets returned.

i know that words under 4 characters are considered stopwords and wont be used but i dont get why it stops results from coming back.

thanks

0

https://www.facebook.com/groups/cs50/permalink/674220296058352/?comment_id=674674836012898&notif_t=group_comment&notif_id=1461879804367700

solution here. change the ft_min_word_length via cs50.io terminal

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .