Skip to content

Commit b4bcf09

Browse files
hextrazaSebastian Benjaminbbimber
authored
Refactor field regex (#253)
* Add extractFieldName instead of regex * Add API unit and selenium tests --------- Co-authored-by: Sebastian Benjamin <sebastiancbenjamin@gmail.com> Co-authored-by: bbimber <bbimber@gmail.com>
1 parent 7e4c1bc commit b4bcf09

File tree

3 files changed

+243
-35
lines changed

3 files changed

+243
-35
lines changed

jbrowse/src/client/JBrowse/VariantSearch/components/FilterForm.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ const FilterForm = (props: FilterFormProps ) => {
265265
<InputLabel id="value-select-label">Value</InputLabel>
266266
<Select
267267
labelId="value-select-label"
268+
id={`value-select-${index}`}
268269
value={filter.value}
269270
onChange={(event) =>
270271
handleFilterChange(index, "value", event.target.value)
@@ -305,6 +306,7 @@ const FilterForm = (props: FilterFormProps ) => {
305306
<InputLabel id="value-select-label">Value</InputLabel>
306307
<Select
307308
labelId="value-select-label"
309+
id={`value-select-${index}`}
308310
value={filter.value}
309311
disabled={filter.operator === "is empty" || filter.operator === "is not empty"}
310312
onChange={(event) =>
@@ -321,6 +323,7 @@ const FilterForm = (props: FilterFormProps ) => {
321323
) : (
322324
<TextFieldMinWidth
323325
label="Value"
326+
id={`value-select-${index}`}
324327
sx={ highlightedInputs[index]?.value ? highlightedSx : null }
325328
value={filter.value}
326329
disabled={filter.operator === "is empty" || filter.operator === "is not empty"}

jbrowse/src/org/labkey/jbrowse/JBrowseLuceneSearch.java

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)