diff --git a/solidify-index-controller/src/main/java/ch/unige/solidify/index/indexing/elasticsearch/ElasticsearchService.java b/solidify-index-controller/src/main/java/ch/unige/solidify/index/indexing/elasticsearch/ElasticsearchService.java index dd3d7fb73029756f680d382f2ddf13be5125e0f8..dcad09ec836ee34ca1ed11e22694b50cb5fff67c 100644 --- a/solidify-index-controller/src/main/java/ch/unige/solidify/index/indexing/elasticsearch/ElasticsearchService.java +++ b/solidify-index-controller/src/main/java/ch/unige/solidify/index/indexing/elasticsearch/ElasticsearchService.java @@ -268,6 +268,8 @@ public abstract class ElasticsearchService<T extends IndexMetadata> extends Inde builder = this.getMatchQueryBuilder(condition); } else if (condition.getType() == SearchConditionType.TERM) { builder = this.getTermQueryBuilder(condition); + } else if (condition.getType() == SearchConditionType.WILDCARD) { + builder = this.getWildcardQueryBuilder(condition); } else if (condition.getType() == SearchConditionType.RANGE) { builder = this.getRangeQueryBuilder(condition); } else if (condition.getType() == SearchConditionType.QUERY) { @@ -316,6 +318,15 @@ public abstract class ElasticsearchService<T extends IndexMetadata> extends Inde } } + private QueryBuilder getWildcardQueryBuilder(SearchCondition condition) { + if (!StringTool.isNullOrEmpty(condition.getField()) && !StringTool.isNullOrEmpty(condition.getValue())) { + // 'wildcard' query + return QueryBuilders.wildcardQuery(condition.getField(), condition.getValue()); + } else { + throw new SolidifyRuntimeException("Invalid 'wildcard' search condition"); + } + } + private QueryBuilder getRangeQueryBuilder(SearchCondition condition) { if (StringTool.isNullOrEmpty(condition.getLowerValue()) && StringTool.isNullOrEmpty(condition.getUpperValue())) { throw new SolidifyRuntimeException("Invalid 'range' search condition"); diff --git a/solidify-model/src/main/java/ch/unige/solidify/rest/SearchConditionType.java b/solidify-model/src/main/java/ch/unige/solidify/rest/SearchConditionType.java index ec6ffd5c238461ffdd7b53066189a6d95bf42b16..d51f4cffc661c9d7ca707197724c1df960faef17 100644 --- a/solidify-model/src/main/java/ch/unige/solidify/rest/SearchConditionType.java +++ b/solidify-model/src/main/java/ch/unige/solidify/rest/SearchConditionType.java @@ -9,12 +9,12 @@ * it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 2 of the * License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public * License along with this program. If not, see * <http://www.gnu.org/licenses/gpl-2.0.html>. @@ -26,6 +26,7 @@ package ch.unige.solidify.rest; public enum SearchConditionType { MATCH, // fulltext search TERM, // search on exact term + WILDCARD, // search on exact term, but allow the use of wildcard characters such as * and ? RANGE, // search values within a provided range QUERY, // search with query syntax SIMPLE_QUERY, // search with simple query syntax