Package buscador

Source Code of buscador.Buscador

/*
* 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.ConstantesConfiguracion;
import conf.ManejadorDeConfiguracion;
import java.io.IOException;

/**
*
* @author Alan
*/
public class Buscador {

   
    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;
    }
}
TOP

Related Classes of buscador.Buscador

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.