deleteWords.bindValue(":guid", guid);
deleteWords.exec();
}
// Reindex a note
public synchronized void addWordToNoteIndex(String guid, String word, String type, Integer weight) {
NSqlQuery findWords = new NSqlQuery(db.getIndexConnection());
if (!findWords.prepare("Select weight from words where guid=:guid and source=:type and word=:word")) {
logger.log(logger.MEDIUM, "Prepare failed in addWordToNoteIndex()");
logger.log(logger.MEDIUM, findWords.lastError());
}
findWords.bindValue(":guid", guid);
findWords.bindValue(":type", type);
findWords.bindValue(":word", word);
boolean addNeeded = true;
findWords.exec();
// If we have a match, find out which has the heigher weight & update accordingly
if (findWords.next()) {
int recordWeight = new Integer(findWords.valueString(0));
addNeeded = false;
if (recordWeight < weight) {
NSqlQuery updateWord = new NSqlQuery(db.getIndexConnection());
if (!updateWord.prepare("Update words set weight=:weight where guid=:guid and source=:type and word=:word")) {
logger.log(logger.MEDIUM, "Prepare failed for find words in addWordToNoteIndex()");
logger.log(logger.MEDIUM, findWords.lastError());
}
updateWord.bindValue(":weight", weight);
updateWord.bindValue(":guid", guid);
updateWord.bindValue(":type", type);
updateWord.bindValue(":word",word);
updateWord.exec();
}
}
if (!addNeeded)
return;
NSqlQuery insertWords = new NSqlQuery(db.getIndexConnection());
if (!insertWords.prepare("Insert Into Words (word, guid, weight, source)"
+" Values(:word, :guid, :weight, :type )")) {
logger.log(logger.EXTREME, "Note SQL select prepare checkWords has failed.");
logger.log(logger.MEDIUM, insertWords.lastError());
}
insertWords.bindValue(":word", word);
insertWords.bindValue(":guid", guid);
insertWords.bindValue(":weight", weight);
insertWords.bindValue(":type", type);
if (!insertWords.exec()) {
String err = insertWords.lastError();
logger.log(logger.MEDIUM, "Error inserting words into index: " +err);
}
}