You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by lupiss <lu...@hotmail.com> on 2008/11/21 21:31:20 UTC

Re: solr search

Hola!

soy nueva en solr y tengo el mismo problema, necesito obtener todos los
resultados de cierta consulta y si se puede paginados, de 10 en 10, yo estoy
usando jsolr y jsp en una aplicación web, entonces no sabria donde poner la
nueva url, con el start = 10 y el rows = 10 o algo así, estoy usando struts
entonces la consulta ocurre en una action que ha obtenido los parámetros de
un jsp pegaré parte del código:  

la clase que hace la conexión, consulta y añade, etc...
public class TestSolrClient {
    CommonsHttpSolrServer server;
    SolrInputDocument doc;
    UpdateRequest req;
    UpdateResponse rsp;
    SolrQuery query;
    QueryResponse qrsp;
    SolrDocumentList docs;
    SolrDocument documento;
       
    public TestSolrClient() throws MalformedURLException,
SolrServerException, 
                                   IOException {
        String url = "http://localhost:8080/solr";
                server = new CommonsHttpSolrServer( url );
                server.setParser(new XMLResponseParser());
  }  
    
    public void añadir(Campo[] Campos) throws SolrServerException,
IOException {
            doc = new SolrInputDocument();
            for(int y=0; y<Campos.length; y++)
                doc.addField(Campos[y].getNombre(),Campos[y].getValor());
            server.add( doc );
            server.commit();
            req = new UpdateRequest(); 
            req.setAction( UpdateRequest.ACTION.COMMIT, false, false );
            req.add( doc );
            rsp = req.process( server );  
        }
         
      public  SolrDocumentList consultar(String Consulta) throws
SolrServerException {
            query = new SolrQuery();
            query.setQuery( Consulta );
            qrsp = server.query( query );  
            docs= qrsp.getResults();
            System.out.println("num de resultados: "+docs.getNumFound());
            return docs;
        }
        
        public void BorrarTodo() throws SolrServerException, IOException {
            server.deleteByQuery( "*:*" );
        }
    }


la jsp que recibe los parametros de la busqueda:
<table cellspacing="0" cellpadding="0" border="0" width="40%">
        <tr>
            <th>
                <logic:iterate id="ite" name="ConsultaSolr"
property="seleccionados">
                <tr>
                    <td>
                        <bean:write name="ite" property="etiqueta"/>
                    </td>
                    <td>
                     <html:text property="valores"/>
                    </td>
                </tr>
                </logic:iterate>
             </th>
        </tr>
    </table>
solo puse una parte donde se recogen los valores introducidos por el
usuario, en realidad la jsp pide un tipo de documento a consultar, luego
sobre ese documento pide que se seleccionen los campos que se consultara y
por ultimo pide que se introduzcan valores para esos campos, despues esos
valores se quedan en memoria en un bean que es accedido desde la action, a
continuación la action que hace la consulta:
public class ConsultarSolrAction extends Action {
      /**This is the main action called from the Struts framework.
     * @param mapping The ActionMapping used to select this instance.
     * @param form The optional ActionForm bean for this request.
     * @param request The HTTP Request we are processing.
     * @param response The HTTP Response we are processing.
     */
    public ActionForward execute(ActionMapping mapping, ActionForm form, 
                                 HttpServletRequest request, 
                                 HttpServletResponse response) throws
IOException, 
                                                                     
ServletException, 
                                                                     
SolrServerException {
  //      forma es el bean
        ConsultaSolr forma = (ConsultaSolr)form;
        List aux=forma.getSeleccionados();
        String[] Valores= request.getParameterValues("valores");
        forma.añadirConsulta("tipo: "+forma.getTipo()+" ");
        if(Valores!=null){
        for(int i=0; i<Valores.length; i++)
        {
            if(Valores[i].length()>0)
            {
                Campo campo= (Campo)aux.get(i);
                System.out.println("Valor: "+ Valores[i]);
                if(campo.getNombre().compareTo("general")!=0)
                    forma.añadirConsulta(campo.getNombre()+": "+Valores[i]+"
");
                else
                    forma.añadirConsulta(Valores[i]+" ");
            }
        }
        }
        System.out.println("la consulta a solr sera:" +
forma.getConsulta());    
        TestSolrClient Solr = new TestSolrClient();
        forma.resetValores();
        forma.resetSeleccionados();
        forma.setListSolr(Solr.consultar(forma.getConsulta()));
        forma.reset(mapping,request);
        System.out.println("num de resultados:
"+forma.getListSolr().size());
        if(forma.getListSolr().isEmpty())
            return mapping.findForward( "Error");
        else
            return mapping.findForward( "success");
      }  
}

despues de aqui se va a otra jsp que muestra los resultados, el problema es
que hago una consulta que tiene numfound=600 y solo muestra los 10 primeros
y yo quiero todos!!
help please!!!!!!
-- 
View this message in context: http://www.nabble.com/solr-search-tp17249602p20628977.html
Sent from the Solr - User mailing list archive at Nabble.com.