執行以下Postgres查詢。計算兩個字符串之間的levenshtein距離
SELECT * FROM description WHERE levenshtein(desci, 'Description text?') <= 6 LIMIT 10;
使用以下代碼執行上面的查詢。
public static boolean authQuestion(String question) throws SQLException{
boolean isDescAvailable = false;
Connection connection = null;
try {
connection = DbRes.getConnection();
String query = "SELECT * FROM description WHERE levenshtein(desci, ?) <= 6";
PreparedStatement checkStmt = dbCon.prepareStatement(query);
checkStmt.setString(1, question);
ResultSet rs = checkStmt.executeQuery();
while (rs.next()) {
isDescAvailable = true;
}
} catch (URISyntaxException e1) {
e1.printStackTrace();
} catch (SQLException sqle) {
sqle.printStackTrace();
} catch (Exception e) {
if (connection != null)
connection.close();
} finally {
if (connection != null)
connection.close();
}
return isDescAvailable;
}
我想找到兩個輸入文本和數據庫中存在的值之間的編輯距離。我想要獲取編輯距離爲60%的所有數據。上述查詢不按預期工作。我如何獲得包含60%相似度的行?
Java代碼在這裏幾乎不相關。你從數據庫中得到的結果是什麼?你期望的結果是什麼。 ** [**]您的問題,並根據該數據添加一些示例數據和預期輸出。 [**格式化文本**](http://stackoverflow.com/help/formatting)請,[無屏幕截圖](http://meta.stackoverflow.com/questions/285551/why-may-i-not - 上傳圖像的代碼的時候,問一個問題/ 285557#285557) –
任何想法?..... –