Some more fixes in the search algorithm

This commit is contained in:
mossroy 2013-05-10 16:18:31 +02:00
parent 5457ab0f51
commit ecf48a0d41
3 changed files with 30 additions and 7 deletions

View File

@ -76,8 +76,6 @@ define(function (require) {
localArchive.findTitlesWithPrefix("Am", callbackFunction);
});
//TODO check findTitlesWithPrefix
// Create a title instance for the Article 'Abraham'
var titleAbraham = new evopedia.Title();
titleAbraham.archive = localArchive;
@ -89,7 +87,23 @@ define(function (require) {
titleAbraham.titleOffset = 57;
// TODO check parseTitle for Abraham, and for another one with escape characters
// TODO check getTitleByName
asyncTest("check getTitleByName with accents : Diego Velázquez", function() {
var callbackFunction = function(titleList) {
ok (titleList && titleList.length==1,"One title found");
equal(titleList[0].name,"Diego_Velázquez","Name of the title is correct");
start();
};
localArchive.getTitleByName("Diego Velázquez",callbackFunction);
});
asyncTest("check getTitleByName with quote : Hundred Years' War", function() {
var callbackFunction = function(titleList) {
ok (titleList && titleList.length==1,"One title found");
equal(titleList[0].name,"Hundred_Years'_War","Name of the title is correct");
start();
};
localArchive.getTitleByName("Hundred Years' War",callbackFunction);
});
test("check parseTitleFromId", function() {
var titleId = "small|2010-08-14|0|57|Abraham|2364940|127640|10071";

View File

@ -127,6 +127,8 @@ define(function(require) {
*/
function populateDropDownListOfTitles(titleList) {
var comboTitleList = document.getElementById('titleList');
// Remove previous results
comboTitleList.options.length = 0;
for (var i=0; i<titleList.length; i++) {
var title = titleList[i];
comboTitleList.options[i] = new Option (title.name, title.toStringId());

View File

@ -258,10 +258,17 @@ define(function(require) {
var currentLocalArchiveInstance = this;
var normalizedPrefix = remove_diacritics.normalizeString(prefix).replace(" ","_").toLowerCase();
this.recursivePrefixSearch(reader, normalizedPrefix, 0, titleFileSize, function(titleOffset) {
// TODO Skip the titles that do not start with the prefix
// TODO use a normalizer to compare the strings
//if (title && title.getReadableName().toLowerCase().indexOf(prefix.toLowerCase())==0) {
currentLocalArchiveInstance.getTitlesStartingAtOffset(titleOffset, 50, callbackFunction);
currentLocalArchiveInstance.getTitlesStartingAtOffset(titleOffset, 50, function(titleList){
var i = 0;
for (i=0; i<titleList.length;i++) {
var titleName = titleList[i].name;
var normalizedTitleName = remove_diacritics.normalizeString(titleName).toLowerCase();
if (normalizedTitleName.length<normalizedPrefix.length || normalizedTitleName.substring(0,normalizedPrefix.length)!=normalizedPrefix) {
break;
}
}
callbackFunction(titleList.slice(0,i));
});
});
};