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

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