Filter article names that really start with the prefix (has to be improved with a normalizer before comparing strings)

This commit is contained in:
mossroy 2013-03-14 18:16:32 +01:00
parent 66e42247ff
commit 6c5020b42a
2 changed files with 20 additions and 7 deletions

View File

@ -245,7 +245,7 @@ function readTitlesBeginningAtIndexStartingWithPrefix(titleFile,prefix,startInde
newLineIndex++;
}
var i = newLineIndex;
var titleNumber=-1;
var titleNumber=0;
var comboTitleList = document.getElementById('titleList');
while (i<byteArray.length && titleNumber<50) {
// Look for the index of the next NewLine
@ -262,13 +262,13 @@ function readTitlesBeginningAtIndexStartingWithPrefix(titleFile,prefix,startInde
var title = evopedia.Title.parseTitle(encodedTitle, new evopedia.LocalArchive(), i);
// Skip the first title
if (titleNumber>=0 && title) {
// TODO : check if the title starts with prefix, and return if it does not
// 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) {
comboTitleList.options[titleNumber] = new Option (title.name, title.fileNr + "|" + title.blockStart + "|" + title.blockOffset + "|" + title.articleLength);
debug("Title : startIndex = " + i + " endIndex = " + newLineIndex + " title.name = " + title.name + " title.fileNr = " + title.fileNr + " title.blockStart = " + title.blockStart + " title.blockOffset = " + title.blockOffset + " title.articleLength = " + title.articleLength);
debug("Title : startIndex = " + i + " endIndex = " + newLineIndex + title.toString());
titleNumber++;
}
titleNumber++;
i=newLineIndex+1;
}
// Update the offsets, as if the first item of the list was selected by the user

View File

@ -38,7 +38,9 @@ define(function(require) {
*/
function LocalArchive() {
this.directory = null;
this.titleFile = null;
this.titleFile = null;
this.date = null;
this.language = null;
}
@ -55,6 +57,10 @@ define(function(require) {
this.titleOffset = null;
this.titleEntryLength = null;
};
Title.prototype.getReadableName = function() {
return this.name.replace("_"," ");
};
/**
@ -119,6 +125,13 @@ define(function(require) {
return utf8ByteArrayToString(encodedTitle, 15, len);
};
Title.prototype.toStringId = function(){
return this.archive.language + "_" + this.archive.date + "_" + this.titleOffset;
};
Title.prototype.toString = function(){
return "title.id = " + this.toStringId() + "title.name = " + this.name + " title.fileNr = " + this.fileNr + " title.blockStart = " + this.blockStart + " title.blockOffset = " + this.blockOffset + " title.articleLength = " + this.articleLength;
};
/**
* Functions and classes exposed by this module
*/