package genbook;

import org.xurble.technorati.Cosmos;
import org.xurble.technorati.Item;
import org.xurble.technorati.Technorati;
import org.xurble.technorati.WebLog;


public class GenTechnorati {


	public static String[] technoSearch(String search){

		//key
		Technorati t = new Technorati("9061b44b20dde18ee9fccadc549e4023");

		Cosmos c = null;
		WebLog w;
		String x = search;

		c = t.keywordSearch(x);
		
		int numItems = c.numItems();
		String[] thingsToReturn = new String[numItems];
		for(int i = 0; i < numItems; i++) //I replaced numItems with the # 2
		{
			Item item = c.getItem(i);
			w = item.getWebLog();
			

			if(w!=null){
				
				//get the blog exceprt and pass it out 
				thingsToReturn[i] = item.getExcerpt();
				
				//trying to return only when there is something caugth by wordinsentence regex but ain't working
				/*
				WordInSentence tempContent = new WordInSentence(item.getExcerpt(),x);
				String output = cleanupResult(tempContent.getSentences().toString());
				if(output!=""){
				thingsToReturn[i] = output;
				System.out.println(w.getURL());
				System.out.println("EXCERPT -> "+thingsToReturn[i]);
				}else{
					if(i>0){
					i = i-1;
					System.out.println("i is"+i);
					}
				}
				*/
				
				
				//thingsToReturn[i] = item.getExcerpt();
				
				
			}else {
				thingsToReturn[i] = "nothing here!";
			}

		}
		return thingsToReturn;
	}
	
	public static String cleanupResult(String r_){
		String dirtyResult = r_;
		//here is remove the tags once all the results (10) from a search query are back
		TagRemover tagremove = new TagRemover(dirtyResult);
		String cleanOutput = tagremove.removeTags();
		return cleanOutput;
	}
	

}
