Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 29 additions & 19 deletions search/src/org/labkey/search/SearchController.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.labkey.api.action.ExportAction;
import org.labkey.api.action.FormHandlerAction;
import org.labkey.api.action.FormViewAction;
import org.labkey.api.action.HasBindParameters;
import org.labkey.api.action.ReadOnlyApiAction;
import org.labkey.api.action.ReturnUrlForm;
import org.labkey.api.action.SimpleRedirectAction;
Expand All @@ -52,7 +53,6 @@
import org.labkey.api.security.permissions.ApplicationAdminPermission;
import org.labkey.api.security.permissions.ReadPermission;
import org.labkey.api.settings.LookAndFeelProperties;
import org.labkey.api.util.ConfigurationException;
import org.labkey.api.util.ExceptionUtil;
import org.labkey.api.util.HtmlString;
import org.labkey.api.util.HtmlStringBuilder;
Expand All @@ -77,6 +77,8 @@
import org.labkey.search.model.IndexInspector;
import org.labkey.search.model.LuceneDirectoryType;
import org.labkey.search.model.SearchPropertyManager;
import org.springframework.beans.MutablePropertyValues;
import org.springframework.beans.PropertyValues;
import org.springframework.validation.BindException;
import org.springframework.validation.Errors;
import org.springframework.web.servlet.ModelAndView;
Expand All @@ -91,6 +93,8 @@
import java.util.Objects;
import java.util.concurrent.TimeUnit;

import static org.labkey.api.action.BaseViewAction.springBindParameters;

public class SearchController extends SpringActionController
{
private static final DefaultActionResolver _actionResolver = new DefaultActionResolver(SearchController.class);
Expand Down Expand Up @@ -384,7 +388,7 @@ public void addNavTrail(NavTree root)


@AdminConsoleAction
public class IndexContentsAction extends SimpleViewAction<Object>
public static class IndexContentsAction extends SimpleViewAction<Object>
{
@Override
public ModelAndView getView(Object o, BindException errors)
Expand Down Expand Up @@ -430,7 +434,7 @@ public void export(ExportForm form, HttpServletResponse response, BindException

/** for selenium testing */
@RequiresSiteAdmin
public class WaitForIdleAction extends SimpleRedirectAction<Object>
public static class WaitForIdleAction extends SimpleRedirectAction<Object>
{
@Override
public URLHelper getRedirectURL(Object o) throws Exception
Expand Down Expand Up @@ -569,7 +573,7 @@ public ApiResponse execute(SearchForm form, BindException errors)

final Path contextPath = Path.parse(getViewContext().getContextPath());

final String query = form.getQueryString()
final String query = form.getQ()
.replaceAll("(?<!\\\\)[\\/]", "\\\\/"); //escape any '/' that aren't already escaped Issue 47325
final JSONObject response = new JSONObject();
Object[] arr = new Object[0];
Expand Down Expand Up @@ -865,9 +869,10 @@ public URLHelper getSuccessURL(SearchForm searchForm)
}


public static class SearchForm
@SuppressWarnings("unused")
public static class SearchForm implements HasBindParameters
{
private String[] _query;
private String _query = "";
private String _sortField;
private boolean _print = false;
private int _offset = 0;
Expand Down Expand Up @@ -896,22 +901,14 @@ public SearchConfiguration getConfig()
return _config;
}

public String[] getQ()
{
return null == _query ? new String[0] : _query;
}

public String getQueryString()
public String getQ()
{
if (null == _query || _query.length == 0)
return "";

return StringUtils.join(_query, " ");
return _query;
}

public void setQ(String[] query)
public void setQ(String query)
{
_query = query;
_query = StringUtils.trimToEmpty(query);
}

public String getSortField()
Expand Down Expand Up @@ -1091,6 +1088,19 @@ public void setFields(List<String> fields)
{
_fields = fields;
}

@Override
public @NotNull BindException bindParameters(PropertyValues m)
{
MutablePropertyValues mpvs = new MutablePropertyValues(m);
var q = mpvs.getPropertyValue("q");
if (null != q && q.getValue() instanceof String[] arr)
{
mpvs.removePropertyValue("q");
mpvs.addPropertyValue("q", StringUtils.join(arr," "));
}
return springBindParameters(this, "form", mpvs);
}
}


Expand All @@ -1099,7 +1109,7 @@ protected void audit(SearchForm form)
ViewContext ctx = getViewContext();
String comment = form.getComment();

audit(ctx.getUser(), ctx.getContainer(), form.getQueryString(), comment);
audit(ctx.getUser(), ctx.getContainer(), form.getQ(), comment);
}


Expand Down
6 changes: 2 additions & 4 deletions search/src/org/labkey/search/view/search.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -224,13 +224,11 @@
Path contextPath = Path.parse(ctx.getContextPath());
SearchService ss = SearchService.get();

List<String> q = new ArrayList<>(Arrays.asList(form.getQ()));
String value = StringUtils.trim(StringUtils.join(q, " "));
SearchResultTemplate template = form.getSearchResultTemplate();
SearchScope scope = (null == template.getSearchScope() ? form.getSearchScope() : template.getSearchScope());
String categories = (null == template.getCategories() ? form.getCategory() : template.getCategories());
Set<String> selectedCategories = categories == null ? Collections.emptySet() : new CaseInsensitiveHashSet(categories.split("\\+"));
String queryString = form.getQueryString();
String queryString = form.getQ();
String sortField = form.getSortField();
boolean invertSort = form.isInvertSort();

Expand Down Expand Up @@ -293,7 +291,7 @@
<div<%=unsafe(form.isWebPart() ? "" : " class=\"col-md-12\"")%>>
<div style="position:relative;">
<labkey:form id="<%=searchFormId%>" className="lk-search-form" action="<%=searchConfig.getPostURL(c)%>">
<labkey:input type="text" name="q" placeholder="<%=form.isWebPart() ? \"\" : SearchUtils.getPlaceholder(c)%>" formGroup="false" value="<%=value%>"/>
<labkey:input type="text" name="q" placeholder="<%=form.isWebPart() ? \"\" : SearchUtils.getPlaceholder(c)%>" formGroup="false" value="<%=queryString%>"/>
<a class="search-overlay fa fa-search"></a>
<% if (showAdvancedUI) { %>
<small>
Expand Down