Closes #899, Setting max chars to 0 should disable full-text indexing

This commit is contained in:
Dan Stillman 2016-02-07 00:43:48 -05:00
parent 892708d071
commit a20a6c86bc
2 changed files with 88 additions and 7 deletions

View file

@ -549,6 +549,9 @@ Zotero.Fulltext = Zotero.FullText = new function(){
} }
var maxLength = Zotero.Prefs.get('fulltext.textMaxLength'); var maxLength = Zotero.Prefs.get('fulltext.textMaxLength');
if (!maxLength) {
return false;
}
var obj = yield convertItemHTMLToText(itemID, document.body.innerHTML, maxLength); var obj = yield convertItemHTMLToText(itemID, document.body.innerHTML, maxLength);
var text = obj.text; var text = obj.text;
var totalChars = obj.totalChars; var totalChars = obj.totalChars;
@ -596,12 +599,17 @@ Zotero.Fulltext = Zotero.FullText = new function(){
return false; return false;
} }
Zotero.debug('Indexing file ' + path); var maxLength = Zotero.Prefs.get('fulltext.textMaxLength');
if (!maxLength) {
return false;
}
if (complete) {
maxLength = null;
}
Zotero.debug('Indexing file ' + path);
var text = yield Zotero.File.getContentsAsync(path, charset); var text = yield Zotero.File.getContentsAsync(path, charset);
var totalChars = text.length; var totalChars = text.length;
var maxLength = complete ? false : Zotero.Prefs.get('fulltext.textMaxLength');
if (contentType == 'text/html') { if (contentType == 'text/html') {
let obj = yield convertItemHTMLToText(itemID, text, maxLength); let obj = yield convertItemHTMLToText(itemID, text, maxLength);
text = obj.text; text = obj.text;

View file

@ -1,10 +1,83 @@
describe("Zotero.Fulltext", function () { describe("Zotero.Fulltext", function () {
var win, pdfToolsVersion;
before(function* () {
// Hidden browser, which requires a browser window, needed for charset detection
// (until we figure out a better way)
win = yield loadBrowserWindow();
pdfToolsVersion = Zotero.isWin ? '3.02a' : '3.04';
});
after(function () {
if (win) {
win.close();
}
});
describe("#indexItems()", function () {
before(function* () {
yield Zotero.Fulltext.downloadPDFTool('info', pdfToolsVersion);
yield Zotero.Fulltext.downloadPDFTool('converter', pdfToolsVersion);
});
beforeEach(function () {
Zotero.Prefs.clear('fulltext.textMaxLength');
Zotero.Prefs.clear('fulltext.pdfMaxPages');
});
after(function () {
Zotero.Prefs.clear('fulltext.textMaxLength');
Zotero.Prefs.clear('fulltext.pdfMaxPages');
});
it("should index a text file by default", function* () {
var item = yield importFileAttachment('test.txt');
assert.equal(
(yield Zotero.Fulltext.getIndexedState(item)),
Zotero.Fulltext.INDEX_STATE_INDEXED
);
})
it("should skip indexing of a text file if fulltext.textMaxLength is 0", function* () {
Zotero.Prefs.set('fulltext.textMaxLength', 0);
var item = yield importFileAttachment('test.txt');
assert.equal(
(yield Zotero.Fulltext.getIndexedState(item)),
Zotero.Fulltext.INDEX_STATE_UNINDEXED
);
})
it("should index a PDF by default", function* () {
var item = yield importFileAttachment('test.pdf');
assert.equal(
(yield Zotero.Fulltext.getIndexedState(item)),
Zotero.Fulltext.INDEX_STATE_INDEXED
);
})
it("should skip indexing of a PDF if fulltext.textMaxLength is 0", function* () {
Zotero.Prefs.set('fulltext.textMaxLength', 0);
var item = yield importFileAttachment('test.pdf');
assert.equal(
(yield Zotero.Fulltext.getIndexedState(item)),
Zotero.Fulltext.INDEX_STATE_UNINDEXED
);
})
it("should skip indexing of a PDF if fulltext.pdfMaxPages is 0", function* () {
Zotero.Prefs.set('fulltext.pdfMaxPages', 0);
var item = yield importFileAttachment('test.pdf');
assert.equal(
(yield Zotero.Fulltext.getIndexedState(item)),
Zotero.Fulltext.INDEX_STATE_UNINDEXED
);
})
})
describe("#downloadPDFTool()", function () { describe("#downloadPDFTool()", function () {
it("should install the PDF tools", function* () { it("should install the PDF tools", function* () {
yield Zotero.Fulltext.uninstallPDFTools(); yield Zotero.Fulltext.uninstallPDFTools();
assert.isFalse(Zotero.Fulltext.pdfInfoIsRegistered()); assert.isFalse(Zotero.Fulltext.pdfInfoIsRegistered());
var version = Zotero.isWin ? '3.02a' : '3.04';
var dataDir = Zotero.getZoteroDirectory().path; var dataDir = Zotero.getZoteroDirectory().path;
var execFileName = Zotero.Fulltext.pdfInfoFileName; var execFileName = Zotero.Fulltext.pdfInfoFileName;
var execPath = OS.Path.join(dataDir, execFileName); var execPath = OS.Path.join(dataDir, execFileName);
@ -16,7 +89,7 @@ describe("Zotero.Fulltext", function () {
'resource://zotero/redirect.' + scriptExt 'resource://zotero/redirect.' + scriptExt
); );
var cacheExecPath = OS.Path.join( var cacheExecPath = OS.Path.join(
getTestDataDirectory().path, "pdf", version, execFileName getTestDataDirectory().path, "pdf", pdfToolsVersion, execFileName
); );
// Delete existing files // Delete existing files
@ -33,7 +106,7 @@ describe("Zotero.Fulltext", function () {
} }
catch (e) {} catch (e) {}
yield Zotero.Fulltext.downloadPDFTool('info', version); yield Zotero.Fulltext.downloadPDFTool('info', pdfToolsVersion);
assert.ok(Zotero.Fulltext.pdfInfoIsRegistered()); assert.ok(Zotero.Fulltext.pdfInfoIsRegistered());
assert.equal( assert.equal(
@ -45,7 +118,7 @@ describe("Zotero.Fulltext", function () {
} }
assert.equal( assert.equal(
(yield Zotero.File.getContentsAsync(versionPath)), (yield Zotero.File.getContentsAsync(versionPath)),
version pdfToolsVersion
); );
//Temp: disabled on Windows //Temp: disabled on Windows