diff --git a/backend/src-common/src/main/java/org/eclipse/sw360/datahandler/db/VendorSearchHandler.java b/backend/src-common/src/main/java/org/eclipse/sw360/datahandler/db/VendorSearchHandler.java index d27bfd6a9c..1a3576501e 100644 --- a/backend/src-common/src/main/java/org/eclipse/sw360/datahandler/db/VendorSearchHandler.java +++ b/backend/src-common/src/main/java/org/eclipse/sw360/datahandler/db/VendorSearchHandler.java @@ -1,5 +1,5 @@ /* - * Copyright Siemens AG, 2013-2015. Part of the SW360 Portal Project. + * Copyright Siemens AG, 2013-2018. Part of the SW360 Portal Project. * * SPDX-License-Identifier: EPL-1.0 * @@ -17,7 +17,6 @@ import java.io.IOException; import java.util.List; -import java.util.Set; import static org.eclipse.sw360.datahandler.couchdb.lucene.LuceneAwareDatabaseConnector.prepareWildcardQuery; @@ -54,7 +53,7 @@ public List search(String searchText) { return connector.searchView(Vendor.class, luceneSearchView, prepareWildcardQuery(searchText)); } - public Set searchIds(String searchText) { + public List searchIds(String searchText) { // Query the search view for the provided text return connector.searchIds(Vendor.class, luceneSearchView, prepareWildcardQuery(searchText)); } diff --git a/backend/src/src-vendors/src/main/java/org/eclipse/sw360/vendors/VendorHandler.java b/backend/src/src-vendors/src/main/java/org/eclipse/sw360/vendors/VendorHandler.java index ca961080ab..b74045664c 100644 --- a/backend/src/src-vendors/src/main/java/org/eclipse/sw360/vendors/VendorHandler.java +++ b/backend/src/src-vendors/src/main/java/org/eclipse/sw360/vendors/VendorHandler.java @@ -1,5 +1,5 @@ /* - * Copyright Siemens AG, 2013-2015. Part of the SW360 Portal Project. + * Copyright Siemens AG, 2013-2018. Part of the SW360 Portal Project. * * SPDX-License-Identifier: EPL-1.0 * @@ -76,7 +76,7 @@ public List searchVendors(String searchText) throws TException { } @Override - public Set searchVendorIds(String searchText) throws TException { + public List searchVendorIds(String searchText) throws TException { return vendorSearchHandler.searchIds(searchText); } diff --git a/build-configuration/resources/couchdb.properties b/build-configuration/resources/couchdb.properties index 1e32442235..b8ffb6cea2 100644 --- a/build-configuration/resources/couchdb.properties +++ b/build-configuration/resources/couchdb.properties @@ -1,5 +1,5 @@ # -# Copyright Siemens AG, 2013-2016. Part of the SW360 Portal Project. +# Copyright Siemens AG, 2013-2018. Part of the SW360 Portal Project. # # All rights reserved. This configuration file is provided to you under the # terms and conditions of the Eclipse Distribution License v1.0 which @@ -18,3 +18,13 @@ couchdb.attachments = sw360attachments couchdb.fossologyKeys = sw360fossologykeys couchdb.vulnerability_management = sw360vm lucenesearch.limit = 150 + +# Warning: If you enable lucene leading wildcards you have to enable this configuration also in couchdb-lucene.ini +# leading wildcard search is disabled as default because its a expensive operation. +# couchdb-lucene.ini (is part of the couchdb-lucene .war package) +# [lucene] +# allowLeadingWildcard=true +# see more: https://wiki.apache.org/lucene-java/LuceneFAQ#What_wildcard_search_support_is_available_from_Lucene.3F +lucenesearch.leading.wildcard = false + + diff --git a/frontend/sw360-portlet/src/main/java/org/eclipse/sw360/portal/common/datatables/PaginationParser.java b/frontend/sw360-portlet/src/main/java/org/eclipse/sw360/portal/common/datatables/PaginationParser.java index d669cf18fc..8864fe376a 100644 --- a/frontend/sw360-portlet/src/main/java/org/eclipse/sw360/portal/common/datatables/PaginationParser.java +++ b/frontend/sw360-portlet/src/main/java/org/eclipse/sw360/portal/common/datatables/PaginationParser.java @@ -10,15 +10,17 @@ */ package org.eclipse.sw360.portal.common.datatables; +import org.apache.log4j.Logger; import org.eclipse.sw360.portal.common.datatables.data.PaginationParameters; import javax.servlet.http.HttpServletRequest; import java.util.Map; +import java.util.Optional; -import static org.eclipse.sw360.portal.common.PortalConstants.*; import static org.eclipse.sw360.portal.common.datatables.DataTablesUtils.getSimple; import static org.eclipse.sw360.portal.common.datatables.DataTablesUtils.getSimpleInt; + /** * @author thomas.maier@evosoft.com */ @@ -34,6 +36,8 @@ public class PaginationParser { private static final String DATATABLE_SORT_DIRECTION = "sSortDir_0"; private static final String DATATABLE_SORT_ASC = "asc"; + private static final Logger log = Logger.getLogger(PaginationParser.class); + protected static PaginationParameters parametersFrom(Map parameterMap) { PaginationParameters paginationParameters = new PaginationParameters(); paginationParameters.setEcho(getSimple(parameterMap, DATATABLE_ECHO)); @@ -41,13 +45,27 @@ protected static PaginationParameters parametersFrom(Map param paginationParameters.setColumnCount(getSimpleInt(parameterMap, DATATABLE_COLUMN_COUNT)); paginationParameters.setDisplayLength(getSimpleInt(parameterMap, DATATABLE_DISPLAY_LENGTH)); paginationParameters.setDisplayStart(getSimpleInt(parameterMap, DATATABLE_DISPLAY_START)); - paginationParameters.setSortingColumn(getSimpleInt(parameterMap, DATATABLE_SORT_COLUMN)); paginationParameters.setAscending(isAscendingSortOrder(parameterMap, DATATABLE_SORT_DIRECTION)); + paginationParameters.setSortingColumn(getColumnSortIndexByParameterMap(parameterMap, DATATABLE_SORT_COLUMN)); return paginationParameters; } - private static boolean isAscendingSortOrder(Map parameterMap, String parameterName) { - return getSimple(parameterMap, parameterName).equals(DATATABLE_SORT_ASC); + private static Optional isAscendingSortOrder(Map parameterMap, String parameterName) { + try { + return Optional.ofNullable(getSimple(parameterMap, parameterName).equals(DATATABLE_SORT_ASC)); + } catch (IllegalArgumentException e) { + log.debug("Ascending sort order is not set because of initial load of data"); + return Optional.empty(); // initial load of data should not destroy the origin sort order (lucene search) + } + } + + private static Optional getColumnSortIndexByParameterMap(Map parameterMap, String parameterName) { + try { + return Optional.ofNullable(getSimpleInt(parameterMap, parameterName)); + } catch (IllegalArgumentException e) { + log.debug("Column sort index value is not set because of initial load of data"); + return Optional.empty(); // initial load of data should not destroy the sort origin order (lucene search) + } } public static PaginationParameters parametersFrom(HttpServletRequest request) { diff --git a/frontend/sw360-portlet/src/main/java/org/eclipse/sw360/portal/common/datatables/data/PaginationParameters.java b/frontend/sw360-portlet/src/main/java/org/eclipse/sw360/portal/common/datatables/data/PaginationParameters.java index 9b8f8bde90..f574afc0b2 100644 --- a/frontend/sw360-portlet/src/main/java/org/eclipse/sw360/portal/common/datatables/data/PaginationParameters.java +++ b/frontend/sw360-portlet/src/main/java/org/eclipse/sw360/portal/common/datatables/data/PaginationParameters.java @@ -10,6 +10,8 @@ */ package org.eclipse.sw360.portal.common.datatables.data; +import java.util.Optional; + /** * @author thomas.maier@evosoft.com */ @@ -43,18 +45,18 @@ public class PaginationParameters { /** * Column index being sorted on */ - private int sortingColumn; + private Optional sortingColumn; /** * Direction to be sorted - ascending or descending order */ - private boolean ascending; + private Optional ascending; public PaginationParameters() { } - public PaginationParameters(String echo, String columnNames, int displayLength, int displayStart, int columnCount, int sortingColumn, boolean ascending) { + public PaginationParameters(String echo, String columnNames, int displayLength, int displayStart, int columnCount, Optional sortingColumn, Optional ascending) { this.echo = echo; this.columnNames = columnNames; this.displayLength = displayLength; @@ -104,19 +106,19 @@ public void setColumnCount(int columnCount) { this.columnCount = columnCount; } - public int getSortingColumn() { + public Optional getSortingColumn() { return sortingColumn; } - public void setSortingColumn(int sortingColumn) { + public void setSortingColumn(Optional sortingColumn) { this.sortingColumn = sortingColumn; } - public boolean isAscending() { + public Optional isAscending() { return ascending; } - public void setAscending(boolean ascending) { + public void setAscending(Optional ascending) { this.ascending = ascending; } } diff --git a/frontend/sw360-portlet/src/main/java/org/eclipse/sw360/portal/portlets/Sw360Portlet.java b/frontend/sw360-portlet/src/main/java/org/eclipse/sw360/portal/portlets/Sw360Portlet.java index e0f3ec6100..275de557b5 100644 --- a/frontend/sw360-portlet/src/main/java/org/eclipse/sw360/portal/portlets/Sw360Portlet.java +++ b/frontend/sw360-portlet/src/main/java/org/eclipse/sw360/portal/portlets/Sw360Portlet.java @@ -15,6 +15,7 @@ import com.google.common.base.Joiner; import com.google.common.base.Predicate; import com.google.common.collect.FluentIterable; +import com.google.common.collect.Sets; import com.liferay.portal.kernel.json.JSONFactoryUtil; import com.liferay.portal.kernel.json.JSONObject; import com.liferay.portal.kernel.servlet.SessionErrors; @@ -39,7 +40,10 @@ import javax.portlet.*; import java.io.IOException; -import java.util.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; import static com.google.common.base.Strings.isNullOrEmpty; @@ -338,9 +342,9 @@ protected List serveReleaseListBySearchText(String searchText, User use } else { List searchResult = componentClient.searchReleases(searchText); final VendorService.Iface vendorClient = thriftClients.makeVendorClient(); - final Set vendorIds = vendorClient.searchVendorIds(searchText); + List vendorIds = vendorClient.searchVendorIds(searchText); if (vendorIds != null && vendorIds.size() > 0) { - searchResult.addAll(componentClient.getReleasesFromVendorIds(vendorIds)); + searchResult.addAll(componentClient.getReleasesFromVendorIds(Sets.newHashSet(vendorIds))); } return searchResult; } diff --git a/frontend/sw360-portlet/src/main/java/org/eclipse/sw360/portal/portlets/components/ComponentPortlet.java b/frontend/sw360-portlet/src/main/java/org/eclipse/sw360/portal/portlets/components/ComponentPortlet.java index cc0333c60c..b7785d3087 100644 --- a/frontend/sw360-portlet/src/main/java/org/eclipse/sw360/portal/portlets/components/ComponentPortlet.java +++ b/frontend/sw360-portlet/src/main/java/org/eclipse/sw360/portal/portlets/components/ComponentPortlet.java @@ -97,6 +97,7 @@ public class ComponentPortlet extends FossologyAwarePortlet { private static final TSerializer JSON_THRIFT_SERIALIZER = new TSerializer(new TSimpleJSONProtocol.Factory()); // Component view datatables, index of columns + private static final int COMPONENT_NO_SORT = -1; private static final int COMPONENT_DT_ROW_VENDOR = 0; private static final int COMPONENT_DT_ROW_NAME = 1; private static final int COMPONENT_DT_ROW_MAIN_LICENSES = 2; @@ -1247,9 +1248,10 @@ private void updateVulnerabilityVerification(ResourceRequest request, ResourceRe private void serveComponentList(ResourceRequest request, ResourceResponse response) throws PortletException { HttpServletRequest originalServletRequest = PortalUtil.getOriginalServletRequest(PortalUtil.getHttpServletRequest(request)); PaginationParameters paginationParameters = PaginationParser.parametersFrom(originalServletRequest); + handlePaginationSortOrder(request, paginationParameters); List componentList = getFilteredComponentList(request); - JSONArray jsonComponents = getComponentData(componentList, paginationParameters); + JSONArray jsonComponents = getComponentData(componentList, paginationParameters); JSONObject jsonResult = createJSONObject(); jsonResult.put(DATATABLE_RECORDS_TOTAL, componentList.size()); jsonResult.put(DATATABLE_RECORDS_FILTERED, componentList.size()); @@ -1263,6 +1265,17 @@ private void serveComponentList(ResourceRequest request, ResourceResponse respon } } + private void handlePaginationSortOrder(ResourceRequest request, PaginationParameters paginationParameters) { + if (!paginationParameters.getSortingColumn().isPresent()) { + for (Component._Fields filteredField : componentFilteredFields) { + if (!isNullOrEmpty(request.getParameter(filteredField.toString()))) { + paginationParameters.setSortingColumn(Optional.of(COMPONENT_NO_SORT)); + break; + } + } + } + } + public JSONArray getComponentData(List componentList, PaginationParameters componentParameters) { List sortedComponents = sortComponentList(componentList, componentParameters); int count = getComponentDataCount(componentParameters, componentList.size()); @@ -1305,22 +1318,23 @@ private int getComponentDataCount(PaginationParameters componentParameters, int } private List sortComponentList(List componentList, PaginationParameters componentParameters) { + boolean isAsc = componentParameters.isAscending().orElse(true); - switch (componentParameters.getSortingColumn()) { + switch (componentParameters.getSortingColumn().orElse(COMPONENT_DT_ROW_NAME)) { case COMPONENT_DT_ROW_VENDOR: - Collections.sort(componentList, compareByVendor(componentParameters.isAscending())); + Collections.sort(componentList, compareByVendor(isAsc)); break; case COMPONENT_DT_ROW_NAME: - Collections.sort(componentList, compareByName(componentParameters.isAscending())); + Collections.sort(componentList, compareByName(isAsc)); break; case COMPONENT_DT_ROW_MAIN_LICENSES: - Collections.sort(componentList, compareByMainLicenses(componentParameters.isAscending())); + Collections.sort(componentList, compareByMainLicenses(isAsc)); break; case COMPONENT_DT_ROW_TYPE: - Collections.sort(componentList, compareByComponentType(componentParameters.isAscending())); + Collections.sort(componentList, compareByComponentType(isAsc)); break; case COMPONENT_DT_ROW_ACTION: - Collections.sort(componentList, compareById(componentParameters.isAscending())); + Collections.sort(componentList, compareById(isAsc)); break; default: break; diff --git a/frontend/sw360-portlet/src/main/java/org/eclipse/sw360/portal/portlets/projects/ProjectPortlet.java b/frontend/sw360-portlet/src/main/java/org/eclipse/sw360/portal/portlets/projects/ProjectPortlet.java index 39fa3a56b2..b853ccd650 100644 --- a/frontend/sw360-portlet/src/main/java/org/eclipse/sw360/portal/portlets/projects/ProjectPortlet.java +++ b/frontend/sw360-portlet/src/main/java/org/eclipse/sw360/portal/portlets/projects/ProjectPortlet.java @@ -98,6 +98,7 @@ public class ProjectPortlet extends FossologyAwarePortlet { private static final String LICENSE_NAME_WITH_TEXT_FILE = "file"; // Project view datatables, index of columns + private static final int PROJECT_NO_SORT = -1; private static final int PROJECT_DT_ROW_NAME = 0; private static final int PROJECT_DT_ROW_DESCRIPTION = 1; private static final int PROJECT_DT_ROW_RESPONSIBLE = 2; @@ -1147,6 +1148,7 @@ private String getProjectDefaultLicenseInfoHeaderText() { private void serveProjectList(ResourceRequest request, ResourceResponse response) throws IOException, PortletException { HttpServletRequest originalServletRequest = PortalUtil.getOriginalServletRequest(PortalUtil.getHttpServletRequest(request)); PaginationParameters paginationParameters = PaginationParser.parametersFrom(originalServletRequest); + handlePaginationSortOrder(request, paginationParameters); List projectList = getFilteredProjectList(request); JSONArray jsonProjects = getProjectData(projectList, paginationParameters); @@ -1162,6 +1164,17 @@ private void serveProjectList(ResourceRequest request, ResourceResponse response } } + private void handlePaginationSortOrder(ResourceRequest request, PaginationParameters paginationParameters) { + if (!paginationParameters.getSortingColumn().isPresent()) { + for (Project._Fields filteredField : projectFilteredFields) { + if (!isNullOrEmpty(request.getParameter(filteredField.toString()))) { + paginationParameters.setSortingColumn(Optional.of(PROJECT_NO_SORT)); + break; + } + } + } + } + public JSONArray getProjectData(List projectList, PaginationParameters projectParameters) { List sortedProjects = sortProjectList(projectList, projectParameters); int count = getProjectDataCount(projectParameters, projectList.size()); @@ -1196,19 +1209,20 @@ private int getProjectDataCount(PaginationParameters projectParameters, int maxS } private List sortProjectList(List projectList, PaginationParameters projectParameters) { + boolean isAsc = projectParameters.isAscending().orElse(true); - switch (projectParameters.getSortingColumn()) { + switch (projectParameters.getSortingColumn().orElse(PROJECT_DT_ROW_NAME)) { case PROJECT_DT_ROW_NAME: - Collections.sort(projectList, compareByName(projectParameters.isAscending())); + Collections.sort(projectList, compareByName(isAsc)); break; case PROJECT_DT_ROW_DESCRIPTION: - Collections.sort(projectList, compareByDescription(projectParameters.isAscending())); + Collections.sort(projectList, compareByDescription(isAsc)); break; case PROJECT_DT_ROW_RESPONSIBLE: - Collections.sort(projectList, compareByResponsible(projectParameters.isAscending())); + Collections.sort(projectList, compareByResponsible(isAsc)); break; case PROJECT_DT_ROW_STATE: - Collections.sort(projectList, compareByState(projectParameters.isAscending())); + Collections.sort(projectList, compareByState(isAsc)); break; case PROJECT_DT_ROW_CLEARING_STATE: break; diff --git a/frontend/sw360-portlet/src/main/webapp/html/components/view.jsp b/frontend/sw360-portlet/src/main/webapp/html/components/view.jsp index c5598d1b37..ef40ad3b63 100644 --- a/frontend/sw360-portlet/src/main/webapp/html/components/view.jsp +++ b/frontend/sw360-portlet/src/main/webapp/html/components/view.jsp @@ -270,7 +270,7 @@ {"title": "Component Type", data: "cType"}, {"title": "Actions", data: "id", render: {display: renderComponentActions}} ], - "order": [[1, 'asc']], + "aaSorting": [], "lengthMenu": [[10, 25, 50, 100, -1], [10, 25, 50, 100, "All"]], "autoWidth": false }); diff --git a/frontend/sw360-portlet/src/main/webapp/html/projects/view.jsp b/frontend/sw360-portlet/src/main/webapp/html/projects/view.jsp index a601e5d83c..7fc411fb9e 100644 --- a/frontend/sw360-portlet/src/main/webapp/html/projects/view.jsp +++ b/frontend/sw360-portlet/src/main/webapp/html/projects/view.jsp @@ -326,7 +326,7 @@ {title: "Clearing Status", data: "clearing"}, {title: "Actions", data: "id", render: {display: renderProjectActions}} ], - "order": [[0, 'asc']], + "aaSorting": [], "lengthMenu": [[10, 25, 50, 100, -1], [10, 25, 50, 100, "All"]], "autoWidth": false, "fnDrawCallback": function (oSettings) { diff --git a/frontend/sw360-portlet/src/main/webapp/html/utils/includes/searchReleases.jsp b/frontend/sw360-portlet/src/main/webapp/html/utils/includes/searchReleases.jsp index a442679395..aa6f4b3a0c 100644 --- a/frontend/sw360-portlet/src/main/webapp/html/utils/includes/searchReleases.jsp +++ b/frontend/sw360-portlet/src/main/webapp/html/utils/includes/searchReleases.jsp @@ -101,6 +101,7 @@ "bFilter": false, "language": {"processing": "Processing..."}, "processing": true, + "aaSorting": [], "initComplete": toggleReleasesSearchNotification }); } diff --git a/libraries/lib-datahandler/src/main/java/org/eclipse/sw360/datahandler/common/DatabaseSettings.java b/libraries/lib-datahandler/src/main/java/org/eclipse/sw360/datahandler/common/DatabaseSettings.java index ef60a47e7b..a878bd90f1 100644 --- a/libraries/lib-datahandler/src/main/java/org/eclipse/sw360/datahandler/common/DatabaseSettings.java +++ b/libraries/lib-datahandler/src/main/java/org/eclipse/sw360/datahandler/common/DatabaseSettings.java @@ -1,5 +1,5 @@ /* - * Copyright Siemens AG, 2014-2016. Part of the SW360 Portal Project. + * Copyright Siemens AG, 2014-2018. Part of the SW360 Portal Project. * * SPDX-License-Identifier: EPL-1.0 * @@ -10,14 +10,13 @@ */ package org.eclipse.sw360.datahandler.common; +import org.ektorp.http.HttpClient; +import org.ektorp.http.StdHttpClient; + import java.net.MalformedURLException; -import java.util.Optional; import java.util.Properties; import java.util.function.Supplier; -import org.ektorp.http.HttpClient; -import org.ektorp.http.StdHttpClient; - /** * Constants for the database address * @@ -36,6 +35,7 @@ public class DatabaseSettings { public static final String COUCH_DB_VM; public static final int LUCENE_SEARCH_LIMIT; + public static final boolean LUCENE_LEADING_WILDCARD; private static final String COUCH_DB_USERNAME; private static final String COUCH_DB_PASSWORD; @@ -53,6 +53,7 @@ public class DatabaseSettings { COUCH_DB_VM = props.getProperty("couchdb.vulnerability_management", "sw360vm"); LUCENE_SEARCH_LIMIT = Integer.parseInt(props.getProperty("lucenesearch.limit", "25")); + LUCENE_LEADING_WILDCARD = Boolean.parseBoolean(props.getProperty("lucenesearch.leading.wildcard", "false")); } public static Supplier getConfiguredHttpClient() throws MalformedURLException { diff --git a/libraries/lib-datahandler/src/main/java/org/eclipse/sw360/datahandler/couchdb/lucene/LuceneAwareDatabaseConnector.java b/libraries/lib-datahandler/src/main/java/org/eclipse/sw360/datahandler/couchdb/lucene/LuceneAwareDatabaseConnector.java index b208da718e..2803ab6f49 100644 --- a/libraries/lib-datahandler/src/main/java/org/eclipse/sw360/datahandler/couchdb/lucene/LuceneAwareDatabaseConnector.java +++ b/libraries/lib-datahandler/src/main/java/org/eclipse/sw360/datahandler/couchdb/lucene/LuceneAwareDatabaseConnector.java @@ -53,6 +53,8 @@ public class LuceneAwareDatabaseConnector extends LuceneAwareCouchDbConnector { private final DatabaseConnector connector; + private static final List LUCENE_SPECIAL_CHARACTERS = Arrays.asList("[\\\\\\+\\-\\!\\~\\*\\?\\^\\:\\(\\)\\{\\}\\[\\]]", "\\&\\&", "\\|\\|"); + /** * Maximum number of results to return */ @@ -91,7 +93,7 @@ public List searchView(Class type, LuceneSearchView function, String q /** * Search with lucene using the previously declared search function only for ids */ - public Set searchIds(Class type, LuceneSearchView function, String queryString) { + public List searchIds(Class type, LuceneSearchView function, String queryString) { LuceneResult queryLuceneResult = searchView(function, queryString, false); return getIdsFromResult(queryLuceneResult); } @@ -144,8 +146,8 @@ public void setResultLimit(int limit) { // HELPER METHODS // //////////////////// - private static Set getIdsFromResult(LuceneResult result) { - Set ids = new HashSet<>(); + private static List getIdsFromResult(LuceneResult result) { + List ids = new ArrayList<>(); if (result != null) { for (LuceneResult.Row row : result.getRows()) { ids.add(row.getId()); @@ -162,7 +164,7 @@ public List searchViewWithRestrictions(Class type,LuceneSearchView luc List subQueries = new ArrayList<>(); for (Map.Entry> restriction : subQueryRestrictions.entrySet()) { - final Set filterSet =restriction.getValue(); + final Set filterSet = restriction.getValue(); if (!filterSet.isEmpty()) { final String fieldName = restriction.getKey(); @@ -192,8 +194,6 @@ private static String formatSubquery(Set filterSet, final String fieldNa return fieldName + ":\"" + (enumByString(input, ProjectState.class).toString()) + "\""; } else if (fieldName.equals("projectType")) { return fieldName + ":\"" + (enumByString(input, ProjectType.class).toString()) + "\""; - } else if (input.contains(" ")){ - return fieldName + ":\"" + input + "\""; } else { return fieldName + ":" + input; } @@ -204,7 +204,11 @@ private static String formatSubquery(Set filterSet, final String fieldNa } public static String prepareWildcardQuery(String query) { - return sanitizeQueryInput(query) + "*"; + if (DatabaseSettings.LUCENE_LEADING_WILDCARD) { + return "*" + sanitizeQueryInput(query) + "*"; + } else { + return sanitizeQueryInput(query) + "*"; + } } public static String prepareFuzzyQuery(String query) { @@ -212,8 +216,13 @@ public static String prepareFuzzyQuery(String query) { } private static String sanitizeQueryInput(String input) { - // p{L}: matches any kind of letter from any language, such as accented character (é ä î...) - // p{nD}: matches a digit zero through nine in any script except ideographic scripts. - return nullToEmpty(input).replaceAll("[^\\p{L}\\p{Nd}]+", " ").trim(); + if (isNullOrEmpty(input)) { + return nullToEmpty(input); + } else { + for (String removeStr : LUCENE_SPECIAL_CHARACTERS) { + input = input.replaceAll(removeStr, " "); + } + return input.trim(); + } } } diff --git a/libraries/lib-datahandler/src/main/thrift/vendors.thrift b/libraries/lib-datahandler/src/main/thrift/vendors.thrift index 51643efff6..8643a70b15 100644 --- a/libraries/lib-datahandler/src/main/thrift/vendors.thrift +++ b/libraries/lib-datahandler/src/main/thrift/vendors.thrift @@ -55,7 +55,7 @@ service VendorService { /** * get set of vendorIds whose fullname or shortname starts with searchText **/ - set searchVendorIds(1: string searchText); + list searchVendorIds(1: string searchText); /** * write vendor to database and return id