List of usage examples for org.apache.solr.client.solrj SolrQuery SolrQuery
public SolrQuery(String q)
From source file:at.tugraz.kmi.medokyservice.rec.io.SolrDBClient.java
License:Open Source License
public List<ContentTags> getContentTagsByUser(String username) throws SolrServerException { List<ContentTags> tagList = new LinkedList<ContentTags>(); SolrQuery query = new SolrQuery("username:" + username).setFields("tags, timestamp") .setFilterQueries("tags:['' TO *]").setRows(10000000); QueryResponse rsp = this.query(query); SolrDocumentList docs = rsp.getResults(); for (SolrDocument doc : docs) { Date date = (Date) doc.getFieldValue("timestamp"); if (date == null || doc.getFieldValue("tags") == null) continue; ContentTags tagEntry = new ContentTags(date); tagEntry.tags = ((ArrayList<String>) doc.getFieldValue("tags")); tagList.add(tagEntry);/*w w w .j a va2 s .c o m*/ } return tagList; }
From source file:at.tugraz.kmi.medokyservice.rec.io.SolrDBClient.java
License:Open Source License
public List<ContentTags> getContentTagsByGroup(String inquiryId) throws SolrServerException { List<ContentTags> tagList = new LinkedList<ContentTags>(); SolrQuery query = new SolrQuery("course:" + inquiryId).setFields("tags, timestamp") .setFilterQueries("tags:['' TO *]").setRows(10000000); QueryResponse rsp = this.query(query); SolrDocumentList docs = rsp.getResults(); for (SolrDocument doc : docs) { Date date = (Date) doc.getFieldValue("timestamp"); if (date == null || doc.getFieldValue("tags") == null) continue; ContentTags tagEntry = new ContentTags(date); tagEntry.tags = ((ArrayList<String>) doc.getFieldValue("tags")); tagList.add(tagEntry);/*from w ww . j av a2 s . co m*/ } return tagList; }
From source file:at.tugraz.kmi.medokyservice.rec.io.SolrDBClient.java
License:Open Source License
public List<ContentTags> getContentFeatureTagsByGroup(String inquiryId) throws SolrServerException { List<ContentTags> tagList = new LinkedList<ContentTags>(); SolrQuery query = new SolrQuery("course:" + inquiryId).setFields("tags, features, timestamp") .setFilterQueries("tags:['' TO *] AND features:['' TO *] ").setRows(10000000); QueryResponse rsp = this.query(query); SolrDocumentList docs = rsp.getResults(); for (SolrDocument doc : docs) { Date date = (Date) doc.getFieldValue("timestamp"); if (date == null || doc.getFieldValue("tags") == null || doc.getFieldValue("features") == null) continue; ContentTags tagEntry = new ContentTags(date); tagEntry.tags = ((ArrayList<String>) doc.getFieldValue("tags")); tagEntry.setFeatures((ArrayList<String>) doc.getFieldValue("features")); tagList.add(tagEntry);/*from w w w . j av a 2s . c om*/ } return tagList; }
From source file:at.tugraz.kmi.medokyservice.rec.io.SolrDBClient.java
License:Open Source License
@SuppressWarnings("unchecked") public Map<String, Long> getTagCountByUser(String username) throws SolrServerException { LinkedHashMap<String, Long> userTagCount = new LinkedHashMap<String, Long>(); SolrQuery query = new SolrQuery("username:" + username).setFields(" ").setRows(1).setFacet(true) .setFacetMinCount(1).addFacetField("tags"); QueryResponse rsp = this.query(query); FacetField ff = rsp.getFacetField("tags"); for (Count count : ff.getValues()) { if (count.getName() == null || count.getName().length() <= 0) continue; userTagCount.put(count.getName(), count.getCount()); }// ww w . j a v a2s . c om return userTagCount; }
From source file:at.tugraz.kmi.medokyservice.rec.io.SolrDBClient.java
License:Open Source License
@SuppressWarnings("unchecked") public Set<String> getTagTextByUser(String username) throws SolrServerException { Set<String> tagList = new HashSet<String>(); SolrQuery query = new SolrQuery("username:" + username).setFields("tags").setRows(10000000); QueryResponse rsp = this.query(query); SolrDocumentList docs = rsp.getResults(); for (SolrDocument doc : docs) { if (doc.getFieldValue("tags") != null) tagList.addAll((ArrayList<String>) doc.getFieldValue("tags")); // if (tag == null) // continue; // tagList.add(tag); }//from w w w . j a v a 2 s . c o m return tagList; }
From source file:at.tugraz.kmi.medokyservice.rec.io.SolrDBClient.java
License:Open Source License
public Map<String, Long> getTagCountByGroup(String courseId) throws SolrServerException { LinkedHashMap<String, Long> groupTags = new LinkedHashMap<String, Long>(); SolrQuery query2 = new SolrQuery("course:" + courseId).setFields(" ").setRows(1).setFacet(true) .setFacetMinCount(1).addFacetField("tags"); QueryResponse rsp2 = this.query(query2); FacetField ff = rsp2.getFacetField("tags"); for (Count count : ff.getValues()) { if (count.getName() == null || count.getName().length() <= 0) continue; groupTags.put(count.getName(), count.getCount()); }//from w ww. jav a2 s. co m return groupTags; }
From source file:at.tugraz.kmi.medokyservice.rec.io.SolrDBClient.java
License:Open Source License
public Map<String, Long> getTagsByGroupOrUser(String groupId, String userId) throws SolrServerException { LinkedHashMap<String, Long> groupOrUserTags = new LinkedHashMap<String, Long>(); SolrQuery query2 = new SolrQuery("course:" + groupId + " OR username:" + userId).setFields(" ").setRows(1) .setFacet(true).setFacetMinCount(1).addFacetField("tags"); QueryResponse rsp2 = this.query(query2); FacetField ff = rsp2.getFacetField("tags"); for (Count count : ff.getValues()) { if (count.getName() == null || count.getName().length() <= 0) continue; groupOrUserTags.put(count.getName(), count.getCount()); }//from w w w . j a v a 2 s.c o m return groupOrUserTags; }
From source file:at.tugraz.kmi.medokyservice.rec.io.SolrDBClient.java
License:Open Source License
public List<ContentTags> getContentFeatureTagsByUser(String userId) throws SolrServerException { List<ContentTags> tagList = new LinkedList<ContentTags>(); SolrQuery query = new SolrQuery("username:" + userId).setFields("tags, features, timestamp") .setFilterQueries("tags:['' TO *] AND features:['' TO *] ").setRows(10000000); QueryResponse rsp = this.query(query); SolrDocumentList docs = rsp.getResults(); for (SolrDocument doc : docs) { Date date = (Date) doc.getFieldValue("timestamp"); if (date == null || doc.getFieldValue("tags") == null || doc.getFieldValue("features") == null) continue; ContentTags tagEntry = new ContentTags(date); tagEntry.tags = ((ArrayList<String>) doc.getFieldValue("tags")); tagEntry.setFeatures((ArrayList<String>) doc.getFieldValue("features")); tagList.add(tagEntry);/*from w ww .j a v a 2s .c o m*/ } return tagList; }
From source file:au.edu.aekos.shared.service.index.PublishSubmissionToSolrTestIT.java
License:Creative Commons License
private void assertThatDocumentCanBeQueried(Submission s) throws SolrServerException { SolrServer server = objectUnderTest.getSolrServer(); QueryResponse rsp = server.query(new SolrQuery("id:" + s.getId().toString())); assertEquals(1, rsp.getResults().size()); SolrDocument doc = rsp.getResults().get(0); logger.info("Solr document contents:"); for (Entry<String, Object> entry : doc.entrySet()) { logger.info(entry.getKey() + "=" + entry.getValue()); }// ww w .j ava 2 s .c o m }
From source file:au.org.aekos.shared.api.model.dataset.SharedSearchResultFactoryTest.java
License:Creative Commons License
/** * Can we create a new instance from a Solr doc? *///w w w. ja va2s . c o m @Test public void testNewInstance01() throws Exception { Calendar calendar = new GregorianCalendar(); calendar.add(Calendar.YEAR, 1); Date oneYearInTheFuture = calendar.getTime(); createSolrTestData(solrServer, aDocument(aField(prop("index-names.id"), new Long(8491L)), aField(prop("index-names.dataset.name"), "Animi voluptatem Tempor ut quia illo velit velit nihil"), aField(prop("index-names.dataset.abstract"), "Omnis quibusdam"), aField(prop("index-names.dataset.version"), "666"), aField(prop("index-names.project.name"), "Voluptas omnis"), aField(prop("index-names.study-location-count"), new Integer(3)), aField(prop("index-names.visit-date.first"), sdf.parse("2014-02-10T13:30:00Z")), aField(prop("index-names.visit-date.last"), sdf.parse("2014-02-24T13:30:00Z")), aField(prop("index-names.keywords"), "Qui illum, quia commodo tempor"), aField(prop("index-names.field-of-research"), "404"), aField(prop("index-names.field-of-research"), "503"), aField(prop("index-names.socio-economic-objectives"), "9613"), aField(prop("index-names.ecoloigical-theme"), "Ecotoxicology"), aField(prop("index-names.ecoloigical-theme"), "Debitis praesentium consectetur"), aField(prop("index-names.conservation-themes"), "Migratory species"), aField(prop("index-names.conservation-themes"), "Obcaecati veniam aliquip aut"), aField(prop("index-names.dataset.custodian"), "ABARES"), aField(prop("index-names.dataset.custodian"), "TERN"), aField(prop("index-names.method.name"), "The Be-Awesome Method"), aField(prop("index-names.license-type"), "Tern Attribution (TERN-BY) Data Licence V1.0"), aField(prop("index-names.spatial-location"), "POINT(138.7128906 -23.9834339)"), aField(prop("index-names.embargo-date"), oneYearInTheFuture), aField(prop("index-names.image-url"), "/getSubmissionImage?submissionId=4757&questionId=3.10&imageId=2521a72e-35bd-41ca-900d-ba0135e4f83a.jpg"), aField(prop("index-names.thumbnail-url"), "/getSubmissionImage?submissionId=4757&questionId=3.10&imageId=2521a72e-35bd-41ca-900d-ba0135e4f83a_tn.jpg"))); QueryResponse solrResp = solrServer.query(new SolrQuery("*:*")); SolrDocument source = solrResp.getResults().get(0); SharedSearchResult result = objectUnderTest.newSearchResultInstance(source); assertThat(result.getDatasetId(), is("8491")); assertThat(result.getTitleDescription(), is("Animi voluptatem Tempor ut quia illo velit velit nihil")); assertThat(result.getAbstractDescription(), is("Omnis quibusdam")); assertThat(result.getImageUrl(), is( "/getSubmissionImage?submissionId=4757&questionId=3.10&imageId=2521a72e-35bd-41ca-900d-ba0135e4f83a.jpg")); assertThat(result.getThumbnailUrl(), is( "/getSubmissionImage?submissionId=4757&questionId=3.10&imageId=2521a72e-35bd-41ca-900d-ba0135e4f83a_tn.jpg")); assertThat(result.getWkt(), is("POINT(138.7128906 -23.9834339)")); assertThat(result.isEmbargoedToday(), is(true)); assertThat(result.getLicenseType(), is("TERN-BY 1.0")); assertThat(result.getGridFields(), hasItems(new SharedGridField("Version Number", "666"), new SharedGridField("Project Name", "Voluptas omnis"), new SharedGridField("Number of Sites", "3"), new SharedGridField("Start Date", "10/02/2014"), new SharedGridField("End Date", "24/02/2014"), new SharedGridField("Keywords", "Qui illum, quia commodo tempor"), new SharedGridField("ANZRC FOR Codes", "404, 503"), new SharedGridField("ANZRC SEO Codes", "9613"), new SharedGridField("Ecological Themes", "Ecotoxicology, Debitis praesentium consectetur"), new SharedGridField("Conservation/NRM Themes", "Migratory species, Obcaecati veniam aliquip aut"), new SharedGridField("Dataset Custodian", "ABARES, TERN"), new SharedGridField("Method Name", "The Be-Awesome Method"), new SharedGridField("License Type", "Tern Attribution (TERN-BY) Data Licence V1.0"))); assertThat(result.getGridFields().size(), is(13)); }