@@ -60,6 +60,7 @@ public class JBrowseLuceneSearch
6060 private final JBrowseSession _session ;
6161 private final JsonFile _jsonFile ;
6262 private final User _user ;
63+ private final String [] specialStartPatterns = {"*:* -" , "+" , "-" };
6364
6465 private JBrowseLuceneSearch (final JBrowseSession session , final JsonFile jsonFile , User u )
6566 {
@@ -115,6 +116,19 @@ private String tryUrlDecode(String input) {
115116 }
116117 }
117118
119+ public String extractFieldName (String queryString ) {
120+ // Check if the query starts with any of the start patterns
121+ for (String pattern : specialStartPatterns ) {
122+ if (queryString .startsWith (pattern )) {
123+ queryString = queryString .substring (pattern .length ()).trim ();
124+ break ;
125+ }
126+ }
127+
128+ // Split the remaining string by ':' and return the first part (field name)
129+ String [] parts = queryString .split (":" , 2 );
130+ return parts .length > 0 ? parts [0 ].trim () : null ;
131+ }
118132
119133 public JSONObject doSearch (User u , String searchString , final int pageSize , final int offset ) throws IOException , ParseException
120134 {
@@ -180,18 +194,7 @@ public JSONObject doSearch(User u, String searchString, final int pageSize, fina
180194 String queryString = tokenizer .nextToken ();
181195 Query query = null ;
182196
183- // Type is defined by the first field in the lucene query
184- // "First" field is defined by getting the first consecutive string of ASCII characters or underscores terminated by a colon
185- // we might just want to return the field(s) in the form instead
186- Pattern pattern = Pattern .compile ("[\\ p{ASCII}&&[^\\ s:*+-]][\\ p{ASCII}&&[^:\\ p{Punct}*]]*:" );
187-
188- Matcher matcher = pattern .matcher (queryString );
189-
190- String fieldName = null ;
191- if (matcher .find ())
192- {
193- fieldName = matcher .group ().substring (0 , matcher .group ().length () - 1 );
194- }
197+ String fieldName = extractFieldName (queryString );
195198
196199 if (VARIABLE_SAMPLES .equals (fieldName ))
197200 {
0 commit comments