Skip to content

Commit

Permalink
Fixing UD-569. Adding preprocessor to replace comma with whitespace in
Browse files Browse the repository at this point in the history
all Solr search managers.
Fixing UD-558. Trim the error message if it is over 2000 when saving it
to database.
  • Loading branch information
jingjingbic committed Aug 30, 2019
1 parent 4681300 commit 892a0b6
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,7 @@
*/
package org.ndexbio.common.models.dao.postgresql;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.security.SecureRandom;
import java.sql.Array;
import java.sql.PreparedStatement;
Expand All @@ -57,7 +53,6 @@

import javax.xml.bind.DatatypeConverter;

import org.apache.commons.io.FileUtils;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.common.SolrDocument;
import org.apache.solr.common.SolrDocumentList;
Expand All @@ -79,7 +74,6 @@
import org.ndexbio.model.object.network.NetworkIndexLevel;
import org.ndexbio.model.object.network.NetworkSummary;
import org.ndexbio.model.object.network.VisibilityType;
import org.ndexbio.rest.Configuration;

import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.JsonProcessingException;
Expand Down Expand Up @@ -1705,15 +1699,18 @@ public int revokeUserPrivilege(UUID networkUUID, UUID userUUID) throws SQLExcept
}

/**
* Becareful when using this function, it commit the db connection of the current DAO object.
* Be careful when using this function, it commit the db connection of the current DAO object.
*
* @param networkId
* @param ErrorMessage
* @param errorMessage
*/
public void setErrorMessage(UUID networkId, String ErrorMessage) {
public void setErrorMessage(UUID networkId, String errorMessage) {
String sql = "update network set error = ? where \"UUID\" = ? and is_deleted=false";

String trimedMsg = ( errorMessage.length()>2000) ?
(errorMessage.substring(0, 1996) + "...") : errorMessage ;
try ( PreparedStatement pst = db.prepareStatement(sql)) {
pst.setString(1, ErrorMessage);
pst.setString(1, trimedMsg);
pst.setObject(2, networkId);
int i = pst.executeUpdate();
if ( i !=1)
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/ndexbio/common/solr/GroupIndexManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import org.apache.solr.common.SolrInputDocument;
import org.apache.solr.common.util.NamedList;
import org.ndexbio.model.exceptions.NdexException;
import org.ndexbio.model.tools.SearchUtilities;
import org.ndexbio.rest.Configuration;

public class GroupIndexManager implements AutoCloseable{
Expand Down Expand Up @@ -101,7 +102,7 @@ public SolrDocumentList searchGroups (String searchTerms, int limit, int offset)

SolrQuery solrQuery = new SolrQuery();

solrQuery.setQuery(searchTerms).setFields(UUID);
solrQuery.setQuery(SearchUtilities.preprocessSearchTerm(searchTerms)).setFields(UUID);
if ( searchTerms.equalsIgnoreCase("*:*"))
solrQuery.setSort(UUID, ORDER.desc);
if ( offset >=0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
import org.apache.solr.common.SolrInputDocument;
import org.apache.solr.common.util.NamedList;
import org.ndexbio.common.NdexClasses;
import org.ndexbio.model.tools.SearchUtilities;
import org.ndexbio.model.tools.TermUtilities;
import org.ndexbio.common.util.Util;
import org.ndexbio.cxio.aspects.datamodels.ATTRIBUTE_DATA_TYPE;
Expand Down Expand Up @@ -239,7 +240,7 @@ else if ( permission == Permissions.READ) {
solrQuery.setSort(MODIFICATION_TIME, ORDER.desc);

// solrQuery.setQuery( searchTerms ).setFields(UUID);
solrQuery.setQuery("( " + searchTerms + " ) AND _val_:\"div(" + NDEX_SCORE+ ",10)\"" ).setFields(UUID);
solrQuery.setQuery("( " + SearchUtilities.preprocessSearchTerm(searchTerms) + " ) AND _val_:\"div(" + NDEX_SCORE+ ",10)\"" ).setFields(UUID);
solrQuery.set("defType", "edismax");
solrQuery.set("qf","uuid^20 name^10 description^5 labels^6 owner^2 networkType^4 organism^3 disease^3 tissue^3 author^2 methods nodeName represents alias rights^0.6 rightsHolder^0.6");
if ( offset >=0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
import org.ndexbio.cxio.core.AspectIterator;
import org.ndexbio.model.cx.FunctionTermElement;
import org.ndexbio.model.exceptions.NdexException;
import org.ndexbio.model.tools.SearchUtilities;
import org.ndexbio.rest.Configuration;

import com.fasterxml.jackson.core.JsonProcessingException;
Expand Down Expand Up @@ -99,7 +100,7 @@ public SolrDocumentList getNodeIdsByQuery(String query, int limit) throws SolrSe

SolrQuery solrQuery = new SolrQuery();

solrQuery.setQuery(query).setFields(ID);
solrQuery.setQuery(SearchUtilities.preprocessSearchTerm(query)).setFields(ID);
solrQuery.set("defType", "edismax");
solrQuery.set("qf", NAME + " " + REPRESENTS + " " + ALIAS);
solrQuery.setStart(0);
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/ndexbio/common/solr/UserIndexManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import org.apache.solr.common.SolrInputDocument;
import org.apache.solr.common.util.NamedList;
import org.ndexbio.model.exceptions.NdexException;
import org.ndexbio.model.tools.SearchUtilities;
import org.ndexbio.rest.Configuration;

public class UserIndexManager implements AutoCloseable{
Expand Down Expand Up @@ -109,7 +110,7 @@ public SolrDocumentList searchUsers (String searchTerms, int limit, int offset)

SolrQuery solrQuery = new SolrQuery();

solrQuery.setQuery(searchTerms).setFields(UUID);
solrQuery.setQuery(SearchUtilities.preprocessSearchTerm(searchTerms)).setFields(UUID);
if ( searchTerms.equalsIgnoreCase("*:*"))
solrQuery.setSort(UUID, ORDER.desc);
if ( offset >=0)
Expand Down

0 comments on commit 892a0b6

Please sign in to comment.