Package buscador

Source Code of buscador.BuscadorAvanzado

/*
* 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;
import java.util.Date;

/**
*
* @author Alan
*/
public class BuscadorAvanzado implements Buscable {


    private int page = 1;
    private int cantRes = ManejadorDeConfiguracion.getInstance().getTweetsPorpagina();
    private Object[] criteria;
  

    public BuscadorAvanzado(Object[] criteria) {
        this.criteria = criteria;
       
    }

    public Object[] getCriteria() {
        return criteria;
    }


  
    public Tweet[] siguientePagina() {
        Tweet[] twts = null;
        try {
                twts=buscarAvanzada(criteria);
        } catch (Exception e) {
            e.printStackTrace();
        }
        // if(twts.length==cantRes){
        page++;
        // }

        return twts;
    }

   
    /**
     * Busqueda avanzada
     * @param criteria [0.ConAll,1.ConAny,2.ConExact,3.ConHash,4.ConNone,5.From,6.Reference,7.Since(DATE),8.to,9.Until(Date)]
     * @return
     */
      private Tweet[] buscarAvanzada(Object[] criteria) {

        SearchDevice s = SearchDevice.getInstance();
             Query q=null;
        for(int i=0; i<criteria.length;i++){
            switch(i){
                case 0:
                    if(((String)criteria[i])!=null&&!((String)criteria[i]).equals("")){
                        if(q!=null){
                            q=QueryComposer.append(q, QueryComposer.containAll((String)criteria[i]));
                        }else{
                            q=QueryComposer.containAll((String)criteria[i]);
                        }
                    }
                    break;
                    case 1:
                    if(((String)criteria[i])!=null&&!((String)criteria[i]).equals("")){
                        if(q!=null){
                            q=QueryComposer.append(q, QueryComposer.containAny((String)criteria[i]));
                        }else{
                            q=QueryComposer.containAny((String)criteria[i]);
                        }
                    }
                    break;
                    case 2:
                    if(((String)criteria[i])!=null&&!((String)criteria[i]).equals("")){
                        if(q!=null){
                            q=QueryComposer.append(q, QueryComposer.containExact((String)criteria[i]));
                        }else{
                            q=QueryComposer.containExact((String)criteria[i]);
                        }
                    }
                    break;
                    case 3:
                    if(((String)criteria[i])!=null&&!((String)criteria[i]).equals("")){
                        if(q!=null){
                            q=QueryComposer.append(q, QueryComposer.containHashtag((String)criteria[i]));
                        }else{
                            q=QueryComposer.containHashtag((String)criteria[i]);
                        }
                    }
                    break;
                    case 4:
                    if(((String)criteria[i])!=null&&!((String)criteria[i]).equals("")){
                        if(q!=null){
                            q=QueryComposer.append(q, QueryComposer.containNone((String)criteria[i]));
                        }else{
                            q=QueryComposer.containNone((String)criteria[i]);
                        }
                    }
                    break;
                    case 5:
                    if(((String)criteria[i])!=null&&!((String)criteria[i]).equals("")){
                        if(q!=null){
                            q=QueryComposer.append(q, QueryComposer.from((String)criteria[i]));
                        }else{
                            q=QueryComposer.from((String)criteria[i]);
                        }
                    }
                    break;
                    case 6:
                    if(((String)criteria[i])!=null&&!((String)criteria[i]).equals("")){
                        if(q!=null){
                            q=QueryComposer.append(q, QueryComposer.reference((String)criteria[i]));
                        }else{
                            q=QueryComposer.reference((String)criteria[i]);
                        }
                    }
                    break;
                    case 7:
                    if(((Date)criteria[i])!=null){
                        if(q!=null){
                            q=QueryComposer.append(q, QueryComposer.since((Date)criteria[i]));
                        }else{
                            q=QueryComposer.since((Date)criteria[i]);
                        }
                    }
                    break;
                     case 8:
                    if(((String)criteria[i])!=null&&!((String)criteria[i]).equals("")){
                        if(q!=null){
                            q=QueryComposer.append(q, QueryComposer.to((String)criteria[i]));
                        }else{
                            q=QueryComposer.to((String)criteria[i]);
                        }
                    }
                    break;
                    case 9:
                    if(((Date)criteria[i])!=null){
                        if(q!=null){
                            q=QueryComposer.append(q, QueryComposer.until((Date)criteria[i]));
                        }else{
                            q=QueryComposer.until((Date)criteria[i]);
                        }
                    }
                    break;

            }

        }
         q = QueryComposer.append(q, QueryComposer.paginate(cantRes, page));
        Tweet[] twts=null;
        try {
            twts = s.searchTweets(q);
        } catch (IOException ex) {
            ex.printStackTrace();
        } catch (LimitExceededException ex) {
            ex.printStackTrace();
        }
        return twts;



      }

    public int getTipoBusqueda() {
        return TiposDeBusqueda.AVANZADA;
    }
}
TOP

Related Classes of buscador.BuscadorAvanzado

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.