DB search query parse
@@ -2,16 +2,18 @@ package org.carlspring.strongbox.services.impl;
import java.io.IOException;
import java.util.Collection;
+import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
import java.util.stream.Collectors;
import org.apache.lucene.queryparser.classic.ParseException;
import org.carlspring.strongbox.configuration.Configuration;
import org.carlspring.strongbox.configuration.ConfigurationManager;
-import org.carlspring.strongbox.domain.ArtifactEntry;
import org.carlspring.strongbox.services.ArtifactEntryService;
import org.carlspring.strongbox.services.ArtifactSearchService;
import org.carlspring.strongbox.services.ConfigurationService;
@@ -35,6 +37,8 @@ public class ArtifactSearchServiceImpl
implements ArtifactSearchService, ConfigurationService
{
+ private static final String QUERY_PATTERN_DB = "([\\w]+)?=([^;]+);?";
+
private static final Logger logger = LoggerFactory.getLogger(ArtifactSearchServiceImpl.class);
@Autowired
@@ -53,26 +57,41 @@ public class ArtifactSearchServiceImpl
{
SearchResults searchResults = new SearchResults();
- final String repositoryId = searchRequest.getRepositoryId();
+ String storageId = searchRequest.getStorageId();
+ String repositoryId = searchRequest.getRepositoryId();
+ String query = searchRequest.getQuery();
+
+ Pattern pattern = Pattern.compile(QUERY_PATTERN_DB);
+ Matcher matcher = pattern.matcher(query);
+ //If query matches then we have a DataBase search request
+ if (matcher.matches())
+ {
+ Map<String, String> coordinates = new HashMap<>();
+ while (matcher.find())
+ {
+ coordinates.put(matcher.group(1), matcher.group(2));
+ }
+ searchResults.getResults()
+ .addAll(dbSearch(coordinates, storageId, repositoryId));
+ return searchResults;
+ }
final Collection<Storage> storages = getConfiguration().getStorages().values();
if (repositoryId != null && !repositoryId.isEmpty())
{
logger.debug("Repository: {}", repositoryId);
-
- final String storageId = searchRequest.getStorageId();
if (storageId == null)
{
- searchResults.getResults().addAll(indexSearch(searchRequest.getQuery(), repositoryId, storages));
+ searchResults.getResults().addAll(indexSearch(query, repositoryId, storages));
}
else
{
- searchResults.getResults().addAll(indexSearch(searchRequest.getQuery(), storageId, repositoryId));
+ searchResults.getResults().addAll(indexSearch(query, storageId, repositoryId));
}
}
else
{
- searchResults.getResults().addAll(indexSearch(searchRequest.getQuery(), storages));
+ searchResults.getResults().addAll(indexSearch(query, storages));
}
logger.debug("Results: {}", searchResults.getResults().size());
return searchResults;
