--- bookmarktools/www/documentation.html 2009/02/28 07:41:45 1.18 +++ bookmarktools/www/documentation.html 2009/02/28 07:49:16 1.19 @@ -3,6 +3,7 @@ + Bookmark Tools @@ -69,8 +70,8 @@
  • USER GUIDE
  • XPCOM
  • OTHER
  • @@ -80,157 +81,154 @@
    -
    - -

    backHowTo use the index component (uses clucene-core-0.9.20)

    -

    Writing::

    -
    -
    -										//initialize file object (location: profile directory)
    -										var file = Components.classes["@mozilla.org/file/directory_service;1"]
    -													.getService(Components.interfaces.nsIProperties)
    -													.get("ProfD", Components.interfaces.nsIFile);
    -
    -										file.append("index"); //folder named 'index'
    -										
    -										if(!file.exists() || !file.isDirectory()) 
    -											file.create(Components.interfaces.nsIFile.DIRECTORY_TYPE, 0777);
    +								
    - //initialize xpcom - var writer = Components.classes["@bookmarktools.mozdev.org/search/indexWriter;1"].createInstance(); - writer = writer.QueryInterface(Components.interfaces.ICLWriter); - - //set path - writer.setPath(file.path); - - //create index document - var cl_document = new Object(); - cl_document.primaryKey = "key0"; //this shoud be a unique key - cl_document.name = "CLucene Indexer"; //document name - cl_document.lastModifiedDate = new Date().getTime(); //date in millis - cl_document.content = "Hello World!"; //some content - - //append document - writer.appendDocument( - cl_document.primaryKey, - cl_document.name, - cl_document.lastModifiedDate, - cl_document.content - ); - - //optimize data - writer.optimize(); - -
    +

    backHowTo use the index component (uses clucene-core-0.9.20)

    +

    Writing::

    +
    +
    +									//initialize file object (location: profile directory)
    +									var file = Components.classes["@mozilla.org/file/directory_service;1"]
    +												.getService(Components.interfaces.nsIProperties)
    +												.get("ProfD", Components.interfaces.nsIFile);
     
    -									

    Searching::

    -
    +									file.append("index"); //folder named 'index'
    +									
    +									if(!file.exists() || !file.isDirectory()) 
    +										file.create(Components.interfaces.nsIFile.DIRECTORY_TYPE, 0777);
     
    -										//initialize xpcom
    -										var reader = Components.classes["@bookmarktools.mozdev.org/search/indexReader;1"].createInstance();
    -										reader = reader.QueryInterface(Components.interfaces.ICLReader);
    -										
    -										//set path
    -										reader.setPath(file.path); //see section 'Writing'
    -										
    -										if(reader.exists()){ //check for index data
    -											
    -											var query = "Hell*";
    -											var results = Components.classes["@mozilla.org/array;1"]
    -															.createInstance(Components.interfaces.nsIMutableArray);
    -											reader.search(query, results);
    -											
    -											var e = results.enumerate();
    -											while (e.hasMoreElements()) {
    -												var resultNode = e.getNext().QueryInterface(Components.interfaces.IResultNode);
    -												
    -												//Object: resultNode
    -												//-> resultNode.primaryKey
    -												//-> resultNode.score
    -												alert(resultNode.primaryKey + "\n" + resultNode.score);
    -											}
    -											
    -										}else {
    -											//display message or do nothing
    -										}
    -										
    -									
    + //initialize xpcom + var writer = Components.classes["@bookmarktools.mozdev.org/search/indexWriter;1"].createInstance(); + writer = writer.QueryInterface(Components.interfaces.ICLWriter); + + //set path + writer.setPath(file.path); + + //create index document + var cl_document = new Object(); + cl_document.primaryKey = "key0"; //this shoud be a unique key + cl_document.name = "first document"; //document name + cl_document.content = "Hello World!"; //some content + + //append document + writer.appendDocument( + cl_document.primaryKey, + cl_document.name, + cl_document.content + ); + + //optimize data + writer.optimize(); + +
    -

    Lookup::

    -
    +								

    Searching::

    +
     
    -										//initialize xpcom
    -										var reader = Components.classes["@bookmarktools.mozdev.org/search/indexReader;1"].createInstance();
    -										reader = reader.QueryInterface(Components.interfaces.ICLReader);
    -										
    -										//set path
    -										reader.setPath(file.path); //see section 'Writing'
    +									//initialize xpcom
    +									var reader = Components.classes["@bookmarktools.mozdev.org/search/indexReader;1"].createInstance();
    +									reader = reader.QueryInterface(Components.interfaces.ICLReader);
    +									
    +									//set path
    +									reader.setPath(file.path); //see section 'Writing'
    +									
    +									if(reader.exists()){ //check for index data
     										
    +										var query = "Hell*";
     										var results = Components.classes["@mozilla.org/array;1"]
     														.createInstance(Components.interfaces.nsIMutableArray);
    -										reader.lookup(results);
    +										reader.search(query, results);
     										
     										var e = results.enumerate();
     										while (e.hasMoreElements()) {
    -											var lookupNode = e.getNext().QueryInterface(Components.interfaces.ILookupNode);
    +											var resultNode = e.getNext().QueryInterface(Components.interfaces.IResultNode);
     											
    -											//Object: lookupNode
    -											//-> lookupNode.primaryKey
    -											//-> lookupNode.name
    -											alert(lookupNode.primaryKey + "\n" + lookupNode.name);
    +											//Object: resultNode
    +											//-> resultNode.primaryKey
    +											//-> resultNode.score
    +											alert(resultNode.primaryKey + "\n" + resultNode.score);
     										}
    +										
    +									}else {
    +										//display message or do nothing
    +									}
    +									
    +								
    -
    - -

    Delete documents::

    -
    +								

    Lookup::

    +
     
    -										//initialize xpcom
    -										var writer = Components.classes["@bookmarktools.mozdev.org/search/indexWriter;1"].createInstance();
    -										writer = writer.QueryInterface(Components.interfaces.ICLWriter);
    -										
    -										//set path
    -										writer.setPath(file.path); //see section 'Writing'
    -										
    -										//delete documents with index 0, 5 and 2
    -										var docs = [0, 5, 2];
    -										writer.deleteDocument(docs, docs.length);
    +									//initialize xpcom
    +									var reader = Components.classes["@bookmarktools.mozdev.org/search/indexReader;1"].createInstance();
    +									reader = reader.QueryInterface(Components.interfaces.ICLReader);
    +									
    +									//set path
    +									reader.setPath(file.path); //see section 'Writing'
    +									
    +									var results = Components.classes["@mozilla.org/array;1"]
    +													.createInstance(Components.interfaces.nsIMutableArray);
    +									reader.lookup(results);
    +									
    +									var e = results.enumerate();
    +									while (e.hasMoreElements()) {
    +										var lookupNode = e.getNext().QueryInterface(Components.interfaces.ILookupNode);
    +										
    +										//Object: lookupNode
    +										//-> lookupNode.primaryKey
    +										//-> lookupNode.name
    +										alert(lookupNode.primaryKey + "\n" + lookupNode.name);
    +									}
    +
    +								
    + +

    Delete documents::

    +
    +
    +									//initialize xpcom
    +									var writer = Components.classes["@bookmarktools.mozdev.org/search/indexWriter;1"].createInstance();
    +									writer = writer.QueryInterface(Components.interfaces.ICLWriter);
    +									
    +									//set path
    +									writer.setPath(file.path); //see section 'Writing'
    +									
    +									//delete documents with index 0, 5 and 2
    +									var docs = [0, 5, 2];
    +									writer.deleteDocument(docs, docs.length);
     
    -									
    +
    -
    +
    -
    - -

    backHowTo use the tidy component (uses ctidy version 060405)

    -

    Cleanup::

    -
    -
    -										//initialize xpcom
    -										var tidy = Components.classes["@bookmarktools.mozdev.org/repair/tidy;1"].createInstance();
    -										tidy = tidy.QueryInterface(Components.interfaces.ITidy);
    -										
    -										var src = "
    -										<html>
    -											<head></head>
    -											<body
    -												broken body tag & no entity
    -											</body>
    -										</html>";
    -										
    -										//result contains the repaired html/xhtml/xml source
    -										//otherwise a error message returned
    -										var result = tidy.cleanup(src);
    -										
    -										if(result == "Tidy: no output"){
    -											alert("error returned");
    -										}else {
    -											alert(src);
    -										}
    -										
    -									
    - +
    +

    backHowTo use the tidy component (uses ctidy version 060405)

    +

    Cleanup::

    +
    +
    +									//initialize xpcom
    +									var tidy = Components.classes["@bookmarktools.mozdev.org/repair/tidy;1"].createInstance();
    +									tidy = tidy.QueryInterface(Components.interfaces.ITidy);
    +									
    +									var src = "
    +									<html>
    +										<head></head>
    +										<body
    +											broken body tag & no entity
    +										</body>
    +									</html>";
    +									
    +									//result contains the repaired html/xhtml/xml source
    +									//otherwise a error message returned
    +									var result = tidy.cleanup(src);
    +									
    +									if(result == "Tidy: no output"){
    +										alert("error returned");
    +									}else {
    +										alert(src);
    +									}
    +									
    +								
    +