File:  [mozdev] / bookmarktools / www / documentation.html
Revision 1.6: download - view: text, annotated - select for diffs - revision graph
Thu Feb 5 21:30:39 2009 UTC (10 years, 3 months ago) by maik
Branches: MAIN
CVS tags: HEAD
- source code added

    1: <!-- MAIN CONTENT -->
    2: 
    3: <table style="border-width: 2px; border-style: dotted; border-color: black; width: 100%; padding: 5px;">
    4: 	<thead></thead>
    5: 	<tbody>
    6: 		<tr><td><h2>Content:</h2></td></tr>
    7: 		<tr>
    8: 			<td>
    9: 				<ul>
   10: 					<li><strong>USER GUIDE</strong></li>
   11: 					<li><strong>XPCOM</strong>
   12: 						<ul>
   13: 							<li><a href="#HowToIndex">HowTo use the index component</a></li>
   14: 							<li><a href="#HowToTidy">HowTo use the tidy component</a></li>
   15: 					    </ul>
   16: 					</li>
   17: 					<li><strong>OTHER</strong></li>
   18: 				</ul>
   19: 			</td>
   20: 		</tr>
   21: 	</tbody>
   22: </table>
   23: 
   24: <br />
   25: 
   26: <h2><a name="HowToIndex">HowTo use the index component (uses clucene-core-0.9.20)</a></h2>
   27: <h3>Writing::</h3>
   28: <pre class="brush: js">
   29: 
   30: 	//initialize file object (location: profile directory)
   31: 	var file = Components.classes["@mozilla.org/file/directory_service;1"]
   32: 				.getService(Components.interfaces.nsIProperties)
   33: 				.get("ProfD", Components.interfaces.nsIFile);
   34: 
   35: 	file.append("index"); //folder named 'index'
   36: 	
   37: 	if(!file.exists() || !file.isDirectory()) 
   38: 		file.create(Components.interfaces.nsIFile.DIRECTORY_TYPE, 0777);
   39: 
   40: 	//initialize xpcom
   41: 	var writer = Components.classes["@bookmarktools.mozdev.org/search/indexWriter;1"].createInstance();
   42: 	writer = writer.QueryInterface(Components.interfaces.ICLWriter);
   43: 	
   44: 	//set path
   45: 	writer.setPath(file.path);
   46: 	
   47: 	//create index document
   48: 	var cl_document = new Object();
   49: 	cl_document.primaryKey = "key0";						//this shoud be a unique key
   50: 	cl_document.name = "CLucene Indexer";					//document name
   51: 	cl_document.lastModifiedDate = new Date().getTime();	//date in millis
   52: 	cl_document.content = "Hello World!";					//some content
   53: 	
   54: 	//append document
   55: 	writer.appendDocument(
   56: 		cl_document.primaryKey,
   57: 		cl_document.name,
   58: 		cl_document.lastModifiedDate,
   59: 		cl_document.content
   60: 	);
   61: 	
   62: 	//optimize data
   63: 	writer.optimize();
   64: 	
   65: </pre>
   66: 
   67: <h3>Searching::</h3>
   68: <pre class="brush: js">
   69: 
   70: 	//initialize xpcom
   71: 	var reader = Components.classes["@bookmarktools.mozdev.org/search/indexReader;1"].createInstance();
   72: 	reader = reader.QueryInterface(Components.interfaces.ICLReader);
   73: 	
   74: 	//set path
   75: 	reader.setPath(file.path); //see section 'Writing'
   76: 	
   77: 	if(reader.exists()){ //check for index data
   78: 		
   79: 		var query = "Hell*";
   80: 		var results = Components.classes["@mozilla.org/array;1"]
   81: 						.createInstance(Components.interfaces.nsIMutableArray);
   82: 		reader.search(query, results);
   83: 		
   84: 		var e = results.enumerate();
   85: 		while (e.hasMoreElements()) {
   86: 			var resultNode = e.getNext().QueryInterface(Components.interfaces.IResultNode);
   87: 			
   88: 			//Object: resultNode
   89: 			//-> resultNode.primaryKey
   90: 			//-> resultNode.score
   91: 			alert(resultNode.primaryKey + "\n" + resultNode.score);
   92: 		}
   93: 		
   94: 	}else {
   95: 		//display message or do nothing
   96: 	}
   97: 	
   98: </pre>
   99: 
  100: <h3>Lookup::</h3>
  101: <pre class="brush: js">
  102: 
  103: 	//initialize xpcom
  104: 	var reader = Components.classes["@bookmarktools.mozdev.org/search/indexReader;1"].createInstance();
  105: 	reader = reader.QueryInterface(Components.interfaces.ICLReader);
  106: 	
  107: 	//set path
  108: 	reader.setPath(file.path); //see section 'Writing'
  109: 	
  110: 	var results = Components.classes["@mozilla.org/array;1"]
  111: 					.createInstance(Components.interfaces.nsIMutableArray);
  112: 	reader.lookup(results);
  113: 	
  114: 	var e = results.enumerate();
  115: 	while (e.hasMoreElements()) {
  116: 		var lookupNode = e.getNext().QueryInterface(Components.interfaces.ILookupNode);
  117: 		
  118: 		//Object: lookupNode
  119: 		//-> lookupNode.primaryKey
  120: 		//-> lookupNode.name
  121: 		alert(lookupNode.primaryKey + "\n" + lookupNode.name);
  122: 	}
  123: 
  124: </pre>
  125: 
  126: <h3>Delete documents::</h3>
  127: <pre class="brush: js">
  128: 
  129: 	//initialize xpcom
  130: 	var writer = Components.classes["@bookmarktools.mozdev.org/search/indexWriter;1"].createInstance();
  131: 	writer = writer.QueryInterface(Components.interfaces.ICLWriter);
  132: 	
  133: 	//set path
  134: 	writer.setPath(file.path); //see section 'Writing'
  135: 	
  136: 	//delete documents with index 0, 5 and 2
  137: 	var docs = [0, 5, 2];
  138: 	writer.deleteDocument(docs, docs.length);
  139: 
  140: </pre>
  141: 
  142: <br />
  143: 
  144: <h2><a name="HowToTidy">HowTo use the tidy component (uses ctidy version 060405)</a></h2>
  145: <h3>Cleanup::</h3>
  146: <pre class="brush: js">
  147: 
  148: 	//initialize xpcom
  149: 	var tidy = Components.classes["@bookmarktools.mozdev.org/repair/tidy;1"].createInstance();
  150: 	tidy = tidy.QueryInterface(Components.interfaces.ITidy);
  151: 	
  152: 	var src = "
  153: 	&lt;html&gt;
  154: 		&lt;head&gt;&lt;/head&gt;
  155: 		&lt;body
  156: 			broken body tag & no entity
  157: 		&lt;/body&gt;
  158: 	&lt;/html>";
  159: 	
  160: 	//result contains the repaired html/xhtml/xml source
  161: 	//otherwise a error message returned
  162: 	var result = tidy.cleanup(src);
  163: 	
  164: 	if(result == "Tidy: no output"){
  165: 		alert("error returned");
  166: 	}else {
  167: 		alert(src);
  168: 	}
  169: 	
  170: </pre>
  171: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>