Skip to content

Commit

Permalink
Merge branch 'feature/codition-for-facet-item' into 0.3.9
Browse files Browse the repository at this point in the history
  • Loading branch information
alegauss committed Oct 10, 2024
2 parents 6998022 + 1337c93 commit a3aff81
Show file tree
Hide file tree
Showing 11 changed files with 362 additions and 151 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
import com.viglet.turing.persistence.model.nlp.TurNLPVendor;
import com.viglet.turing.persistence.model.se.TurSEInstance;
import com.viglet.turing.persistence.model.sn.TurSNSite;
import com.viglet.turing.persistence.model.sn.TurSNSiteFacetEnum;
import com.viglet.turing.persistence.model.sn.TurSNSiteFacetSortEnum;
import com.viglet.turing.persistence.model.sn.field.TurSNSiteFacetFieldEnum;
import com.viglet.turing.persistence.model.sn.locale.TurSNSiteLocale;
import com.viglet.turing.persistence.repository.sn.TurSNSiteRepository;
import com.viglet.turing.persistence.repository.sn.locale.TurSNSiteLocaleRepository;
Expand Down Expand Up @@ -103,7 +103,7 @@ public List<TurSNSite> turSNSiteList(Principal principal) {
public TurSNSite turSNSiteStructure() {
TurSNSite turSNSite = new TurSNSite();
turSNSite.setFacetSort(TurSNSiteFacetSortEnum.COUNT);
turSNSite.setFacetType(TurSNSiteFacetEnum.AND);
turSNSite.setFacetType(TurSNSiteFacetFieldEnum.AND);
turSNSite.setTurSEInstance(new TurSEInstance());
turSNSite.setTurNLPVendor(new TurNLPVendor());
return turSNSite;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.viglet.turing.persistence.model.nlp.TurNLPVendor;
import com.viglet.turing.persistence.model.se.TurSEInstance;
import com.viglet.turing.persistence.model.sn.field.TurSNSiteFacetFieldEnum;
import com.viglet.turing.persistence.model.sn.field.TurSNSiteField;
import com.viglet.turing.persistence.model.sn.field.TurSNSiteFieldExt;
import com.viglet.turing.persistence.model.sn.locale.TurSNSiteLocale;
Expand Down Expand Up @@ -99,10 +100,10 @@ public class TurSNSite extends TurAuditable<String> implements Serializable {
private Integer mlt;

@Column
private TurSNSiteFacetEnum facetType = TurSNSiteFacetEnum.AND;
private TurSNSiteFacetFieldEnum facetType = TurSNSiteFacetFieldEnum.AND;

@Column
private TurSNSiteFacetEnum facetItemType = TurSNSiteFacetEnum.AND;
private TurSNSiteFacetFieldEnum facetItemType = TurSNSiteFacetFieldEnum.AND;

@Column
private TurSNSiteFacetSortEnum facetSort = TurSNSiteFacetSortEnum.COUNT;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.viglet.turing.persistence.model.sn;

public enum TurSNSiteFacetRangeEnum {

DISABLED,
DAY,
MONTH,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import com.viglet.turing.persistence.dto.sn.field.TurSNSiteFieldExtDto;
import com.viglet.turing.persistence.dto.sn.field.TurSNSiteFieldExtFacetDto;
import com.viglet.turing.persistence.model.sn.TurSNSite;
import com.viglet.turing.persistence.model.sn.field.TurSNSiteFieldExt;
import com.viglet.turing.persistence.model.sn.field.TurSNSiteFieldExtFacet;
import com.viglet.turing.persistence.model.sn.metric.TurSNSiteMetricAccess;
import com.viglet.turing.persistence.repository.sn.TurSNSiteRepository;
Expand Down Expand Up @@ -128,15 +129,7 @@ private TurSNSiteSearchBean searchResponse(TurSNSiteSearchContext context,
.findByTurSNSiteAndFacetAndEnabled(turSNSite, 1, 1).stream()
.map(turSNSiteFieldExt -> {
TurSNSiteFieldExtDto turSNSiteFieldExtDto = new TurSNSiteFieldExtDto(turSNSiteFieldExt);
turSNSiteFieldExtDto.setFacetLocales(
new HashSet<>(
Collections.singletonList(turSNSiteFieldExtFacetRepository
.findByTurSNSiteFieldExtAndLocale(turSNSiteFieldExt, context.getLocale())
.stream().findFirst()
.orElse(TurSNSiteFieldExtFacet.builder()
.locale(context.getLocale())
.label(turSNSiteFieldExt.getFacetName())
.build()))));
turSNSiteFieldExtDto.setFacetLocales(getFacetLocales(context, turSNSiteFieldExt));
return turSNSiteFieldExtDto;
}).toList();
Map<String, TurSNSiteFieldExtDto> facetMap = setFacetMap(turSNSiteFieldExtDtoList);
Expand All @@ -148,6 +141,18 @@ private TurSNSiteSearchBean searchResponse(TurSNSiteSearchContext context,
}).orElse(new TurSNSiteSearchBean());
}

@NotNull
private HashSet<TurSNSiteFieldExtFacet> getFacetLocales(TurSNSiteSearchContext context, TurSNSiteFieldExt turSNSiteFieldExt) {
return new HashSet<>(
Collections.singletonList(turSNSiteFieldExtFacetRepository
.findByTurSNSiteFieldExtAndLocale(turSNSiteFieldExt, context.getLocale())
.stream().findFirst()
.orElse(TurSNSiteFieldExtFacet.builder()
.locale(context.getLocale())
.label(turSNSiteFieldExt.getFacetName())
.build())));
}

private TurSNSiteSearchBean getSearchBeanForResults(TurSNSiteSearchContext context, TurSolrInstance turSolrInstance,
TurSEResults turSEResults, TurSNSite turSNSite,
Map<String, TurSNSiteFieldExtDto> facetMap) {
Expand Down Expand Up @@ -373,7 +378,8 @@ private TurSNSiteSearchQueryContextBean responseQueryContext(TurSNSite turSNSite
.setOffset(0)
.setResponseTime(turSEResults.getElapsedTime())
.setIndex(turSNSite.getName())
.setFacetType(turSNSite.getFacetType().toString());
.setFacetType(turSNSite.getFacetType().toString())
.setFacetItemType(turSNSite.getFacetItemType().toString());
}

private TurSNSiteSearchDefaultFieldsBean defaultFields(TurSNSite turSNSite) {
Expand Down Expand Up @@ -447,19 +453,19 @@ private List<TurSNSiteSearchFacetBean> responseFacet(TurSNSiteSearchContext cont
return Collections.emptyList();
}

private static boolean showFacetByFacetType(TurSNSite turSNSite) {
if (turSNSite.getFacetType() == null) return false;
else return switch (turSNSite.getFacetType()) {
private static boolean showFacetByFacetItemType(TurSNSite turSNSite) {
if (turSNSite.getFacetItemType() == null) return false;
else return switch (turSNSite.getFacetItemType()) {
case OR -> true;
case AND -> false;
case AND, DEFAULT -> false;
};
}

private static boolean showFacet(List<String> hiddenFilterQuery,
Map<String, TurSNSiteFieldExtDto> facetMap,
TurSEFacetResult facet, TurSNSite turSNSite) {
return facetMap.containsKey(facet.getFacet())
&& (!hiddenFilterQuery.contains(facet.getFacet()) || showFacetByFacetType(turSNSite))
&& (!hiddenFilterQuery.contains(facet.getFacet()) || showFacetByFacetItemType(turSNSite))
&& !facet.getTurSEFacetResultAttr().isEmpty();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
*
* Copyright (C) 2016-2024 the original author or authors.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 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 <https://www.gnu.org/licenses/>.
*/

package com.viglet.turing.sn.facet;

import java.util.HashMap;

/**
* @author Alexandre Oliveira
* @since 0.3.9
*/
public class TurSNFacetMapForFilterQuery extends HashMap<String, TurSNFacetProperties> {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
*
* Copyright (C) 2016-2024 the original author or authors.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 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 <https://www.gnu.org/licenses/>.
*/

package com.viglet.turing.sn.facet;

import com.viglet.turing.persistence.model.sn.field.TurSNSiteFacetFieldEnum;
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;

import java.util.List;

/**
* @author Alexandre Oliveira
* @since 0.3.9
*/
@Builder
@Getter
@Setter
public class TurSNFacetProperties {
private TurSNSiteFacetFieldEnum facetType;
private TurSNSiteFacetFieldEnum facetItemType;
private List<String> facetItems;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
*
* Copyright (C) 2016-2024 the original author or authors.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 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 <https://www.gnu.org/licenses/>.
*/

package com.viglet.turing.sn.facet;

import com.viglet.turing.commons.se.TurSEFilterQueryParameters;
import com.viglet.turing.persistence.model.sn.TurSNSite;
import com.viglet.turing.persistence.model.sn.field.TurSNSiteFieldExt;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;

/**
* @author Alexandre Oliveira
* @since 0.3.9
*/
@AllArgsConstructor
@Getter
@Setter
public class TurSNFacetTypeContext {
private TurSNSiteFieldExt turSNSiteFacetFieldExt;
private TurSNSite turSNSite;
private TurSEFilterQueryParameters queryParameters;


public TurSNFacetTypeContext(TurSNSite turSNSite, TurSEFilterQueryParameters queryParameters) {
this.turSNSiteFacetFieldExt = null;
this.turSNSite = turSNSite;
this.queryParameters = queryParameters;
}
public boolean isSpecificField() {
return turSNSiteFacetFieldExt != null;
}
}
Loading

0 comments on commit a3aff81

Please sign in to comment.