Project

General

Profile

« Previous | Next » 

Revision 7569

Added by Jing Tao over 11 years ago

Add a query method in the test.

View differences:

metacat-index/src/test/java/edu/ucsb/nceas/metacat/index/SolrIndexTest.java
10 10

  
11 11

  
12 12

  
13
import org.apache.solr.client.solrj.SolrServer;
14
import org.apache.solr.client.solrj.SolrServerException;
15
import org.apache.solr.client.solrj.response.QueryResponse;
16
import org.apache.solr.common.SolrDocument;
17
import org.apache.solr.common.SolrDocumentList;
18
import org.apache.solr.common.params.SolrParams;
19
import org.apache.solr.servlet.SolrRequestParsers;
13 20
import org.dataone.service.types.v1.SystemMetadata;
14 21
import org.dataone.service.util.TypeMarshaller;
15 22
import org.junit.Test;
......
30 37
       SystemMetadata systemMetadata = TypeMarshaller.unmarshalTypeFromFile(SystemMetadata.class, SYSTEMMETAFILEPATH);
31 38
       InputStream emlInputStream = new FileInputStream(new File(EMLFILEPATH));    
32 39
       solrIndex.insert(id, systemMetadata, emlInputStream);
33
       
40
       doQuery(solrIndex.getSolrServer());
34 41
    }
35 42
    
36 43
    /**
......
50 57
        SolrIndex index = solrIndexesarray[0];
51 58
        return index;
52 59
    }
60
    
61
    /*
62
     * Do query
63
     */
64
    private void doQuery(SolrServer server)
65
                    throws SolrServerException {
66
                StringBuffer request = new StringBuffer();
67
                request.append("q=" + "*:*");
68
                SolrParams solrParams = SolrRequestParsers.parseQueryString(request
69
                        .toString());
70
                QueryResponse reponse = server.query(solrParams);
71
                System.out.println(reponse.toString());
72
    }
73

  
74
    
75
    /*
76
     * Print out the QueryResponse
77
     */
78
    private void print(QueryResponse response) {
79
        SolrDocumentList docs = response.getResults();
80
        if (docs != null) {
81
            System.out.println(docs.getNumFound() + " documents found, "
82
                    + docs.size() + " returned : ");
83
            for (int i = 0; i < docs.size(); i++) {
84
                SolrDocument doc = docs.get(i);
85
                System.out.println("\t" + doc.toString());
86
            }
87
        }
88
    }
53 89
}
54 90

  
metacat-index/src/main/java/edu/ucsb/nceas/metacat/index/SolrIndex.java
76 76
    
77 77
    private static final String SOLRHOMEPATH = "/Users/tao/Downloads/apache-solr-3.4.0/example/solr";
78 78
    
79
    private static final String SOLRHOME = "solr.solr.home";
79
    public static final String SOLRHOME = "solr.solr.home";
80 80
    private static final String SOLRSERVERNAME = "metacat-core";
81 81
    
82 82
    
......
322 322
        solrServer.commit();
323 323
       
324 324
    }
325

  
326
    /**
327
     * Get the solrServer
328
     * @return
329
     */
330
    SolrServer getSolrServer() {
331
        return solrServer;
332
    }
333

  
334
    /**
335
     * Set the solrServer
336
     * @param solrServer
337
     */
338
    void setSolrServer(SolrServer solrServer) {
339
        this.solrServer = solrServer;
340
    }
325 341
}

Also available in: Unified diff