From a87c5520d677fcd390b3d45d199546f993e53126 Mon Sep 17 00:00:00 2001 From: eliaporciani Date: Mon, 24 Feb 2020 16:28:45 +0100 Subject: [PATCH 1/2] [SEARCH-2090] code refactoring --- .../org/alfresco/solr/AlfrescoSolrDataModel.java | 12 ++++++++---- .../solr/component/RewriteFieldListComponent.java | 7 ++----- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/search-services/alfresco-search/src/main/java/org/alfresco/solr/AlfrescoSolrDataModel.java b/search-services/alfresco-search/src/main/java/org/alfresco/solr/AlfrescoSolrDataModel.java index de57cfd87..cdd0b0132 100644 --- a/search-services/alfresco-search/src/main/java/org/alfresco/solr/AlfrescoSolrDataModel.java +++ b/search-services/alfresco-search/src/main/java/org/alfresco/solr/AlfrescoSolrDataModel.java @@ -63,7 +63,6 @@ import org.alfresco.repo.search.impl.parsers.AlfrescoFunctionEvaluationContext; import org.alfresco.repo.search.impl.parsers.FTSParser; import org.alfresco.repo.search.impl.parsers.FTSQueryParser; import org.alfresco.repo.search.impl.querymodel.Constraint; -import org.alfresco.repo.search.impl.querymodel.Ordering; import org.alfresco.repo.search.impl.querymodel.QueryModelFactory; import org.alfresco.repo.search.impl.querymodel.QueryOptions.Connective; import org.alfresco.repo.search.impl.querymodel.impl.lucene.LuceneQueryBuilder; @@ -1592,11 +1591,10 @@ public class AlfrescoSolrDataModel implements QueryConstants } /** - * TODO refactor this method * * return the stored field associated to potentialProperty parameter */ - public String mapStoredProperty(String potentialProperty, FieldUse fieldUse, SolrQueryRequest req) + public String mapStoredProperty(String potentialProperty, SolrQueryRequest req) { if(potentialProperty.equals("asc") || potentialProperty.equals("desc") || potentialProperty.equals("_docid_")) { @@ -1648,7 +1646,7 @@ public class AlfrescoSolrDataModel implements QueryConstants } else { - return mapProperty(potentialProperty, fieldUse, req, 0); + return mapAlfrescoField(FieldUse.FTS, 0, fieldNameAndEnding, luceneField, propertyDef); } } @@ -1689,6 +1687,12 @@ public class AlfrescoSolrDataModel implements QueryConstants propertyDef = getPropertyDefinition(luceneField.substring(index +1)); } } + String solrSortField; + solrSortField = mapAlfrescoField(fieldUse, position, fieldNameAndEnding, luceneField, propertyDef); + return solrSortField; + } + + private String mapAlfrescoField(FieldUse fieldUse, int position, Pair fieldNameAndEnding, String luceneField, PropertyDefinition propertyDef) { String solrSortField; if(propertyDef != null) { diff --git a/search-services/alfresco-search/src/main/java/org/alfresco/solr/component/RewriteFieldListComponent.java b/search-services/alfresco-search/src/main/java/org/alfresco/solr/component/RewriteFieldListComponent.java index 75fc0c562..f8b511ad5 100644 --- a/search-services/alfresco-search/src/main/java/org/alfresco/solr/component/RewriteFieldListComponent.java +++ b/search-services/alfresco-search/src/main/java/org/alfresco/solr/component/RewriteFieldListComponent.java @@ -87,12 +87,9 @@ public class RewriteFieldListComponent extends SearchComponent { - List fieldUsed = List.of(FTS, FACET, ID, SORT); fieldListSet.addAll(solrReturnFields.getLuceneFieldNames().stream() - .flatMap(field -> - fieldUsed.stream() - .map( fieldUse -> AlfrescoSolrDataModel.getInstance() - .mapStoredProperty(field, fieldUse, req))) + .map( field -> AlfrescoSolrDataModel.getInstance() + .mapStoredProperty(field, req)) .filter(schemaFieldName -> schemaFieldName != null) .map(schemaFieldName -> schemaFieldName.chars() .mapToObj(c -> (char) c) From b3580e0f3ebbbff633033ac8326656f208221ae2 Mon Sep 17 00:00:00 2001 From: eliaporciani Date: Mon, 24 Feb 2020 16:43:52 +0100 Subject: [PATCH 2/2] [SEARCH-2090] added headers --- .../generate-solr-config.py | 17 +++++++++++++- .../alfresco/solr/AlfrescoSolrDataModel.java | 3 --- .../alfresco/solr/SolrInformationServer.java | 2 +- .../alfresco/solr/StripLocaleStrField.java | 18 +++++++++++++++ .../component/RewriteFieldListComponent.java | 23 +++++++++++++++---- 5 files changed, 53 insertions(+), 10 deletions(-) diff --git a/search-services/alfresco-search/generator-solr-config/generate-solr-config.py b/search-services/alfresco-search/generator-solr-config/generate-solr-config.py index 6a952f180..de19b66c0 100644 --- a/search-services/alfresco-search/generator-solr-config/generate-solr-config.py +++ b/search-services/alfresco-search/generator-solr-config/generate-solr-config.py @@ -1,4 +1,19 @@ -import itertools +# Copyright (C) 2020 Alfresco Software Limited. +# This file is part of Alfresco +# +# Alfresco is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Alfresco 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 Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with Alfresco. If not, see . +import itertools tokenized = "tokenized" string = "string" diff --git a/search-services/alfresco-search/src/main/java/org/alfresco/solr/AlfrescoSolrDataModel.java b/search-services/alfresco-search/src/main/java/org/alfresco/solr/AlfrescoSolrDataModel.java index cdd0b0132..7bec1000c 100644 --- a/search-services/alfresco-search/src/main/java/org/alfresco/solr/AlfrescoSolrDataModel.java +++ b/search-services/alfresco-search/src/main/java/org/alfresco/solr/AlfrescoSolrDataModel.java @@ -774,7 +774,6 @@ public class AlfrescoSolrDataModel implements QueryConstants } } - // TODO: make it better private void addHighlightSearchFields( PropertyDefinition propertyDefinition , IndexedField indexedField) { @@ -999,7 +998,6 @@ public class AlfrescoSolrDataModel implements QueryConstants } - public String getStoredContentField(QName propertyQName) { PropertyDefinition propertyDefinition = getPropertyDefinition(propertyQName); @@ -1029,7 +1027,6 @@ public class AlfrescoSolrDataModel implements QueryConstants } - /** * Get all the field names into which we must copy the source data * diff --git a/search-services/alfresco-search/src/main/java/org/alfresco/solr/SolrInformationServer.java b/search-services/alfresco-search/src/main/java/org/alfresco/solr/SolrInformationServer.java index c664c48af..b19707aab 100644 --- a/search-services/alfresco-search/src/main/java/org/alfresco/solr/SolrInformationServer.java +++ b/search-services/alfresco-search/src/main/java/org/alfresco/solr/SolrInformationServer.java @@ -2209,7 +2209,7 @@ public class SolrInformationServer implements InformationServer dataModel.getIndexedFieldNamesForProperty(propertyQName).getFields() .stream() - .filter(field -> field.getField().startsWith("text@sd___@") || field.getField().startsWith("text@m__sort")) + .filter(field -> field.getField().startsWith("text@sd___@")) .forEach(field -> addStringProperty(valueHolder, field, value, locale)); } else { diff --git a/search-services/alfresco-search/src/main/java/org/alfresco/solr/StripLocaleStrField.java b/search-services/alfresco-search/src/main/java/org/alfresco/solr/StripLocaleStrField.java index ff43064f9..71f993ff9 100644 --- a/search-services/alfresco-search/src/main/java/org/alfresco/solr/StripLocaleStrField.java +++ b/search-services/alfresco-search/src/main/java/org/alfresco/solr/StripLocaleStrField.java @@ -1,3 +1,21 @@ +/* + * Copyright (C) 2020 Alfresco Software Limited. + * + * This file is part of Alfresco + * + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Alfresco 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + */ package org.alfresco.solr; diff --git a/search-services/alfresco-search/src/main/java/org/alfresco/solr/component/RewriteFieldListComponent.java b/search-services/alfresco-search/src/main/java/org/alfresco/solr/component/RewriteFieldListComponent.java index f8b511ad5..22240edee 100644 --- a/search-services/alfresco-search/src/main/java/org/alfresco/solr/component/RewriteFieldListComponent.java +++ b/search-services/alfresco-search/src/main/java/org/alfresco/solr/component/RewriteFieldListComponent.java @@ -1,3 +1,21 @@ +/* + * Copyright (C) 2020 Alfresco Software Limited. + * + * This file is part of Alfresco + * + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Alfresco 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + */ package org.alfresco.solr.component; import org.alfresco.solr.AlfrescoSolrDataModel; @@ -39,8 +57,6 @@ public class RewriteFieldListComponent extends SearchComponent { private void transformFieldList(SolrQueryRequest req) { - - Set fieldListSet = new HashSet<>(); Set defaultNonCachedFields = Set.of("id","DBID", "_version_"); @@ -84,9 +100,6 @@ public class RewriteFieldListComponent extends SearchComponent { } else { - - - fieldListSet.addAll(solrReturnFields.getLuceneFieldNames().stream() .map( field -> AlfrescoSolrDataModel.getInstance() .mapStoredProperty(field, req))