Reputation:

City name query

Am a newbie to Lucene an working on a city search API using Lucene. If user types in san francisco as search input, then it should give cities with exact match only and not San Jose /San Diego,etc.

How should i index city names in Lucene?and which Lucene analyzer and query class do i need to use?

Upvotes: 0

Views: 391

Answers (2)

Gorakh Yadav
Gorakh Yadav

Reputation: 302

<?php
if(isset($_POST['submit']) && $_POST['submit']=='submit' ){
    $city   =   $_POST['city'];  
    $query  =  "SELECT * FROM libreary  WHERE city LIKE'".$city."'";
    $row    =  mysqli_query($con,$query);
    $result =  mysqli_num_rows($row);
if($result>0){
    while($row1 = mysqli_fetch_array($row)){
        print_r($row1);
    }
}
    $respon['Response'] = $response; 
    print_r(json_encode($respon));

}
?>

Upvotes: 0

Shashikant Kore
Shashikant Kore

Reputation: 5042

Index your content with StandardAnalyzer. And then use PhraseQuery to search. For this, simply use the query string as "san francisco" with double quotes.

Upvotes: 3

Related Questions