0
votes

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?

2
Why would you need Lucene for such a search? Is there a particular reason you decided to use Lucene instead of a simple SQL query?itsadok

2 Answers

3
votes

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

0
votes
<?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));

}
?>