JAL-1563 smarter support for advanced querying of Uniprot FTS
authortcofoegbu <tcnofoegbu@dundee.ac.uk>
Wed, 18 May 2016 15:48:39 +0000 (16:48 +0100)
committertcofoegbu <tcnofoegbu@dundee.ac.uk>
Wed, 18 May 2016 15:48:39 +0000 (16:48 +0100)
src/jalview/fts/service/uniprot/UniProtFTSRestClient.java

index a4f82cf..dfdf715 100644 (file)
@@ -63,22 +63,20 @@ public class UniProtFTSRestClient extends FTSRestClient
               : uniportRestRequest.getResponseSize();
 
       int offSet = uniportRestRequest.getOffSet();
+      String query;
+      if (isAdvancedQuery(uniportRestRequest.getSearchTerm()))
+      {
+        query = uniportRestRequest.getSearchTerm();
+      }
+      else
+      {
+        query = uniportRestRequest.getFieldToSearchBy().equalsIgnoreCase(
+                "Search All") ? uniportRestRequest.getSearchTerm()
+                + " or mnemonic:" + uniportRestRequest.getSearchTerm()
+                : uniportRestRequest.getFieldToSearchBy() + ":"
+                        + uniportRestRequest.getSearchTerm();
+      }
 
-      String query = uniportRestRequest.getFieldToSearchBy()
-              .equalsIgnoreCase("Search All") ? uniportRestRequest
-              .getSearchTerm()
-              + " or mnemonic:"
-              + uniportRestRequest
-              .getSearchTerm() : uniportRestRequest.getFieldToSearchBy()
-              + ":" + uniportRestRequest.getSearchTerm();
-
-      // + (uniportRestRequest.isAllowUnpublishedEntries() ? ""
-      // : " AND status:REL");
-      // System.out.println(">>>>> Query : " + query);
-      // System.out.println(">>>>> Columns : " + wantedFields);
-      // System.out.println(">>>>> Response size: " + responseSize
-      // + " offset : "
-      // + offSet);
       WebResource webResource = null;
       webResource = client.resource(UNIPROT_SEARCH_ENDPOINT)
               .queryParam("format", "tab")
@@ -131,6 +129,17 @@ public class UniProtFTSRestClient extends FTSRestClient
     }
   }
 
+  public boolean isAdvancedQuery(String query)
+  {
+    if (query.contains(" AND ") || query.contains(" OR ")
+            || query.contains(" NOT ") || query.contains(" ! ")
+            || query.contains(" || ") || query.contains(" && ")
+            || query.contains(":") || query.contains("-"))
+    {
+      return true;
+    }
+    return false;
+  }
 
   public FTSRestResponse parseUniprotResponse(
           String uniProtTabDelimittedResponseString,