/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package buscador;
import com.twitterapime.search.LimitExceededException;
import com.twitterapime.search.Query;
import com.twitterapime.search.QueryComposer;
import com.twitterapime.search.SearchDevice;
import com.twitterapime.search.Tweet;
import conf.ManejadorDeConfiguracion;
import java.io.IOException;
/**
*
* @author Alan
*/
public class Buscador implements Buscable{
private int page = 1;
private int cantRes = ManejadorDeConfiguracion.getInstance().getTweetsPorpagina();
private String criteria;
private int tipoBusqueda;
public Buscador(String criteria, int tipoBusqueda) {
this.criteria = criteria;
this.tipoBusqueda = tipoBusqueda;
}
public int getTipoBusqueda() {
return tipoBusqueda;
}
public Tweet[] siguientePagina() {
Tweet[] twts = null;
try {
switch (tipoBusqueda) {
//TAG
case 1:
twts = busquedaPorTag();
break;
//CONTENIDO
case 2:
twts = busquedaPorContenido();
break;
//Autor
case 3:
twts = busquedaPorAutor();
break;
}
} catch (Exception e) {
e.printStackTrace();
}
// if(twts.length==cantRes){
page++;
// }
return twts;
}
private Tweet[] busquedaPorTag() throws IOException, LimitExceededException {
SearchDevice s = SearchDevice.getInstance();
Query q = QueryComposer.append(QueryComposer.containHashtag(criteria), QueryComposer.paginate(cantRes, page));
Tweet[] twts;
twts = s.searchTweets(q);
return twts;
}
private Tweet[] busquedaPorContenido() throws IOException, LimitExceededException {
SearchDevice s = SearchDevice.getInstance();
Query q = QueryComposer.append(QueryComposer.containAny(criteria), QueryComposer.paginate(cantRes, page));
Tweet[] twts;
twts = s.searchTweets(q);
return twts;
}
private Tweet[] busquedaPorAutor() throws IOException, LimitExceededException {
SearchDevice s = SearchDevice.getInstance();
Query q = QueryComposer.append(QueryComposer.from(criteria), QueryComposer.paginate(cantRes, page));
Tweet[] twts;
twts = s.searchTweets(q);
return twts;
}
}