Created
March 31, 2011 21:58
-
-
Save marktriggs/897359 to your computer and use it in GitHub Desktop.
test code...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(import '(org.apache.solr.core CoreContainer CoreContainer$Initializer)) | |
(import '(org.apache.solr.client.solrj.embedded EmbeddedSolrServer)) | |
(import '(org.apache.solr.client.solrj SolrQuery)) | |
(import '(org.apache.solr.common SolrInputDocument)) | |
(System/setProperty "solr.solr.home" | |
"/home/mst/projects/nyu/sakai/upstream/solr-debugging") | |
(def core (.initialize (new CoreContainer$Initializer))) | |
(def server (EmbeddedSolrServer. core "")) | |
;;; Add some test documents... | |
(def test-data [{:id 123 | |
:returnpath "/my/url/is/wonderful" | |
:someother "My wonderful document"} | |
{:id 234 | |
:returnpath "/my/url/is/wonderful" | |
:someother "Another corker"} | |
{:id 345 | |
:returnpath "/my/url/is/lousy" | |
:someother "This document is not so great..."} | |
{:id 456 | |
:returnpath "/my/url/is/wonderful" | |
:someother "But this is fantastic"}]) | |
(doseq [td test-data] | |
(let [doc (SolrInputDocument.)] | |
(doseq [[k v] td] (.addField doc (name k) v)) | |
(.add server doc))) | |
(.commit server) | |
;;; And query it... | |
(.query server (doto (SolrQuery.) | |
(.setQuery "id:*") | |
(.setParam "group" true) | |
(.setParam "group.field" (into-array ["returnpath"])))) | |
Yields: | |
#<QueryResponse {responseHeader={status=0,QTime=2,params={q=id:*,group=true,group.field=returnpath}},grouped={returnpath={matches=4,groups=[{groupValue=/my/url/is/wonderful,doclist={numFound=3,start=0,docs=[SolrDocument[{returnpath=/my/url/is/wonderful, someother=[My wonderful document], id=123}]]}}, {groupValue=/my/url/is/lousy,doclist={numFound=1,start=0,docs=[SolrDocument[{returnpath=/my/url/is/lousy, someother=[This document is not so great...], id=345}]]}}]}}}> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment