diff --git a/orcid-core/src/main/java/org/orcid/core/manager/impl/OrgDisambiguatedManagerImpl.java b/orcid-core/src/main/java/org/orcid/core/manager/impl/OrgDisambiguatedManagerImpl.java index 0d25b443b34..0ea7b06e63e 100644 --- a/orcid-core/src/main/java/org/orcid/core/manager/impl/OrgDisambiguatedManagerImpl.java +++ b/orcid-core/src/main/java/org/orcid/core/manager/impl/OrgDisambiguatedManagerImpl.java @@ -209,7 +209,7 @@ synchronized public void processOrgsWithIncorrectPopularity() { @Override public List searchOrgsFromSolr(String searchTerm, int firstResult, int maxResult, boolean fundersOnly) { - List docs = orcidSolrOrgsClient.getOrgs(searchTerm, firstResult, maxResult, fundersOnly); + List docs = orcidSolrOrgsClient.getOrgs(searchTerm, firstResult, maxResult, fundersOnly, true); List ret = new ArrayList(); for (OrgDisambiguatedSolrDocument doc : docs) { OrgDisambiguated org = convertSolrDocument(doc); diff --git a/orcid-core/src/main/java/org/orcid/core/solr/OrcidSolrOrgsClient.java b/orcid-core/src/main/java/org/orcid/core/solr/OrcidSolrOrgsClient.java index e50cf1aa1ab..15624af61af 100644 --- a/orcid-core/src/main/java/org/orcid/core/solr/OrcidSolrOrgsClient.java +++ b/orcid-core/src/main/java/org/orcid/core/solr/OrcidSolrOrgsClient.java @@ -4,7 +4,9 @@ import java.io.IOException; import java.text.MessageFormat; +import java.util.ArrayList; import java.util.List; +import java.util.Map; import javax.annotation.Resource; @@ -33,6 +35,8 @@ public class OrcidSolrOrgsClient { private static final String SOLR_SELF_SERVICE_ORGS_QUERY = "(org-disambiguated-id-from-source:%s)^50.0 (org-disambiguated-name%s)^50.0 (org-disambiguated-name-string:%s)^25.0"; private static final String SOLR_ORG_BY_ROR_ID_QUERY = "org-disambiguated-id-from-source:%s"; + + private static final String ORG_NAMES_HIGHLIGHT_DELIMITATOR ="::"; public OrgDisambiguatedSolrDocument findById(Long id) { SolrQuery query = new SolrQuery(); @@ -50,7 +54,7 @@ public OrgDisambiguatedSolrDocument findById(Long id) { return null; } - public List getOrgs(String searchTerm, int firstResult, int maxResult, boolean fundersOnly) { + public List getOrgs(String searchTerm, int firstResult, int maxResult, boolean fundersOnly, boolean withNamesHighlight) { StringBuilder queryString = new StringBuilder(SOLR_ORGS_QUERY.replace("%s", searchTerm)); if (fundersOnly) { queryString.append(" AND is-funding-org:true"); @@ -60,17 +64,52 @@ public List getOrgs(String searchTerm, int firstRe query.setQuery(queryString.toString()); query.addOrUpdateSort("score", ORDER.desc); query.addOrUpdateSort("org-disambiguated-popularity", ORDER.desc); + + // Set the preserveMulti parameter + query.setParam("preserveMulti", "true"); + if(fundersOnly) { query.addFilterQuery(String.format("(%s:(%s OR %s))", SolrConstants.ORG_DISAMBIGUATED_ID_SOURCE_TYPE, "ROR", "FUNDREF")); } else { query.addFilterQuery(String.format("(%s:(%s))", SolrConstants.ORG_DISAMBIGUATED_ID_SOURCE_TYPE, "ROR")); } + if(withNamesHighlight) { + query.setHighlight(withNamesHighlight); + query.addHighlightField(SolrConstants.ORG_NAMES); + query.setHighlightSnippets(maxResult); + query.setHighlightSimplePost(ORG_NAMES_HIGHLIGHT_DELIMITATOR); + query.setHighlightSimplePre(ORG_NAMES_HIGHLIGHT_DELIMITATOR); + } + LOGGER.debug("SOLR Query: " + query.toQueryString()); try { QueryResponse queryResponse = solrReadOnlyOrgsClient.query(query); - return queryResponse.getBeans(OrgDisambiguatedSolrDocument.class); + List orgs = queryResponse.getBeans(OrgDisambiguatedSolrDocument.class); + // Get the highlight results + if(withNamesHighlight) { + List orgsNamesHighlighted = new ArrayList(); + Map>> highlightMap = queryResponse.getHighlighting(); + for(OrgDisambiguatedSolrDocument org : orgs) { + // Print highlighted snippets + if (highlightMap.containsKey(org.getOrgDisambiguatedId())) { + Map> fieldHighlightMap = highlightMap.get(org.getOrgDisambiguatedId()); + if (fieldHighlightMap.containsKey(SolrConstants.ORG_NAMES)) { + List highlights = fieldHighlightMap.get(SolrConstants.ORG_NAMES); + OrgDisambiguatedSolrDocument highlightOrg; + for (String highlight : highlights) { + //strip the highlight delimitator ORG_NAMES_HIGHLIGHT_DELIMITATOR + highlightOrg = new OrgDisambiguatedSolrDocument(org); + highlightOrg.setOrgDisambiguatedName(highlight.replaceAll(ORG_NAMES_HIGHLIGHT_DELIMITATOR, "")); + orgsNamesHighlighted.add(highlightOrg); + } + } + } + } + return orgsNamesHighlighted; + } + return orgs; } catch (SolrServerException | IOException se) { String errorMessage = MessageFormat.format("Error when attempting to search for orgs, with search term {0}", new Object[] { searchTerm }); throw new NonTransientDataAccessResourceException(errorMessage, se); diff --git a/orcid-core/src/main/java/org/orcid/pojo/summary/RecordSummaryPojo.java b/orcid-core/src/main/java/org/orcid/pojo/summary/RecordSummaryPojo.java index 51f83708564..1628c45bbed 100644 --- a/orcid-core/src/main/java/org/orcid/pojo/summary/RecordSummaryPojo.java +++ b/orcid-core/src/main/java/org/orcid/pojo/summary/RecordSummaryPojo.java @@ -1,6 +1,5 @@ package org.orcid.pojo.summary; - import java.util.List; import javax.xml.bind.annotation.XmlRootElement; diff --git a/orcid-core/src/test/java/org/orcid/core/solr/OrcidSolrOrgsClientTest.java b/orcid-core/src/test/java/org/orcid/core/solr/OrcidSolrOrgsClientTest.java index 35ea5844ec4..f269c1dfa9c 100644 --- a/orcid-core/src/test/java/org/orcid/core/solr/OrcidSolrOrgsClientTest.java +++ b/orcid-core/src/test/java/org/orcid/core/solr/OrcidSolrOrgsClientTest.java @@ -70,7 +70,7 @@ public void pesistAndFindByIdTest() throws IOException, SolrServerException { @Test public void findFundrefOrgsOnlyTest() throws SolrServerException, IOException { ArgumentCaptor captor = ArgumentCaptor.forClass(SolrQuery.class); - orcidSolrOrgsClient.getOrgs("xxx", 0, 0, true); + orcidSolrOrgsClient.getOrgs("xxx", 0, 0, true, false); Mockito.verify(solrReadOnlyOrgsClientMock).query(captor.capture()); SolrQuery query = captor.getValue(); @@ -81,7 +81,7 @@ public void findFundrefOrgsOnlyTest() throws SolrServerException, IOException { @Test public void findNonFundrefOrgsOnlyTest() throws SolrServerException, IOException { ArgumentCaptor captor = ArgumentCaptor.forClass(SolrQuery.class); - orcidSolrOrgsClient.getOrgs("xxx", 0, 0, false); + orcidSolrOrgsClient.getOrgs("xxx", 0, 0, false, false); Mockito.verify(solrReadOnlyOrgsClientMock).query(captor.capture()); SolrQuery query = captor.getValue(); diff --git a/orcid-utils/src/main/java/org/orcid/utils/solr/entities/OrgDisambiguatedSolrDocument.java b/orcid-utils/src/main/java/org/orcid/utils/solr/entities/OrgDisambiguatedSolrDocument.java index d837de9a4c2..6ae71ebeabf 100644 --- a/orcid-utils/src/main/java/org/orcid/utils/solr/entities/OrgDisambiguatedSolrDocument.java +++ b/orcid-utils/src/main/java/org/orcid/utils/solr/entities/OrgDisambiguatedSolrDocument.java @@ -1,7 +1,9 @@ package org.orcid.utils.solr.entities; import java.io.Serializable; +import java.util.ArrayList; import java.util.List; +import java.util.Set; import org.apache.solr.client.solrj.beans.Field; @@ -287,5 +289,25 @@ public boolean equals(Object obj) { return false; return true; } + + public OrgDisambiguatedSolrDocument() {}; + + public OrgDisambiguatedSolrDocument(OrgDisambiguatedSolrDocument originalDoc) { + this.orgDisambiguatedId = String.valueOf(originalDoc.getOrgDisambiguatedId()); + this.orgDisambiguatedName = originalDoc.getOrgDisambiguatedName(); + this.orgDisambiguatedCity = originalDoc.getOrgDisambiguatedCity(); + this.orgDisambiguatedRegion = originalDoc.getOrgDisambiguatedRegion(); + this.orgDisambiguatedCountry = originalDoc.getOrgDisambiguatedCountry(); + this.orgDisambiguatedIdFromSource = originalDoc.getOrgDisambiguatedIdFromSource(); + this.orgDisambiguatedIdSourceType = originalDoc.getOrgDisambiguatedIdSourceType(); + this.orgDisambiguatedType = originalDoc.getOrgDisambiguatedType(); + this.orgDisambiguatedPopularity =originalDoc.getOrgDisambiguatedPopularity(); + this.orgNames = originalDoc.getOrgNames(); + this.isFundingOrg =originalDoc.isFundingOrg(); + this.orgLocationsJson = originalDoc.getOrgLocationsJson(); + this.orgNamesJson = originalDoc.getOrgNamesJson(); + this.isOrgChosenByMember = originalDoc.isOrgChosenByMember(); + this.orgDisambiguatedStatus = originalDoc.getOrgDisambiguatedStatus(); + } } diff --git a/properties/development.properties b/properties/development.properties index 9a6da83976f..381a95783bb 100644 --- a/properties/development.properties +++ b/properties/development.properties @@ -130,7 +130,7 @@ org.orcid.core.works.bulk.write.max=100 org.orcid.core.issn.source=APP-POCQZAUC70YOFL9R # Orgs grouping -org.orcid.core.orgs.query=(org-disambiguated-name:\"%s\") ^100.0 (org-disambiguated-name:%s*) ^10.0 +org.orcid.core.orgs.query=(org-names:\"%s\")^100.0 (org-names:\"%s\"~15)^80.0 (org-names:*%s*)^10.0 org.orcid.core.orgsToGroup.query=select a.* from org_disambiguated a full outer join org_disambiguated_external_identifier b on a.id = b.org_disambiguated_id where b.identifier_type = 'FUNDREF' and a.source_type='ROR' ################ @@ -257,3 +257,6 @@ org.orcid.scheduler.autospam.enabled=true # Slack org.orcid.core.autospam.slackChannel=collab-spam-reports org.orcid.core.autospam.webhookUrl= + +#org.orcid.persistence.liquibase.enabled=false +org.orcid.persistence.solr.read.only.url=http://localhost:8983/solr