ACS-4953 Add builder to TAS highlight POJO. (#2214)

* ACS-4953 Add builder to TAS highlight POJO.

Also rename ResponseHighLightModel to ResponseHighlightModel.
This commit is contained in:
Tom Page
2023-09-27 12:13:11 +01:00
committed by GitHub
parent d3498f4bc4
commit 248fecd030
3 changed files with 151 additions and 70 deletions

View File

@@ -44,6 +44,7 @@
package org.alfresco.rest.search; package org.alfresco.rest.search;
import java.util.List; import java.util.List;
import java.util.Objects;
import org.alfresco.rest.core.IRestModel; import org.alfresco.rest.core.IRestModel;
import org.alfresco.utility.model.TestModel; import org.alfresco.utility.model.TestModel;
@@ -52,11 +53,11 @@ import org.alfresco.utility.model.TestModel;
* @author Michael Suzuki * @author Michael Suzuki
* *
*/ */
public class ResponseHighLightModel extends TestModel implements IRestModel<ResponseHighLightModel> public class ResponseHighlightModel extends TestModel implements IRestModel<ResponseHighlightModel>
{ {
private ResponseHighLightModel model; private ResponseHighlightModel model;
private String field; private String field;
private List<Object> snippets; private List<String> snippets;
public String getField() public String getField()
{ {
@@ -66,19 +67,44 @@ public class ResponseHighLightModel extends TestModel implements IRestModel<Resp
{ {
this.field = field; this.field = field;
} }
public List<Object> getSnippets() public List<String> getSnippets()
{ {
return snippets; return snippets;
} }
public void setSnippets(List<Object> snippets) public void setSnippets(List<String> snippets)
{ {
this.snippets = snippets; this.snippets = snippets;
} }
@Override @Override
public ResponseHighLightModel onModel() public ResponseHighlightModel onModel()
{ {
return model; return model;
} }
@Override
public boolean equals(Object o)
{
if (this == o)
{
return true;
}
if (o == null || getClass() != o.getClass())
{
return false;
}
ResponseHighlightModel that = (ResponseHighlightModel) o;
return Objects.equals(model, that.model) && Objects.equals(field, that.field) && Objects.equals(snippets, that.snippets);
}
@Override
public int hashCode()
{
return Objects.hash(model, field, snippets);
}
@Override
public String toString()
{
return "ResponseHighlightModel{model=%s, field=%s, snippets=%s}".formatted(model, field, snippets);
}
} }

View File

@@ -2,7 +2,7 @@
* #%L * #%L
* alfresco-tas-restapi * alfresco-tas-restapi
* %% * %%
* Copyright (C) 2005 - 2022 Alfresco Software Limited * Copyright (C) 2005 - 2023 Alfresco Software Limited
* %% * %%
* This file is part of the Alfresco software. * This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of * If the software was purchased under a paid Alfresco license, the terms of
@@ -39,56 +39,32 @@ import org.alfresco.utility.model.TestModel;
*/ */
public class RestRequestHighlightModel extends TestModel implements IRestModel<RestRequestHighlightModel> public class RestRequestHighlightModel extends TestModel implements IRestModel<RestRequestHighlightModel>
{ {
@JsonProperty(value = "entry") @JsonProperty("entry")
RestRequestHighlightModel model; RestRequestHighlightModel model;
/** The string used to mark the start of a highlight in a fragment. */
private String prefix;
/** The string used to mark the end of a highlight in a fragment. */
private String postfix;
/** The maximum number of distinct highlight snippets to return for each highlight field. */
private int snippetCount;
/** The character length of each snippet. */
private int fragmentSize;
/** The number of characters to be considered for highlighting. Matches after this count will not be shown. */
private int maxAnalyzedChars;
/** If fragments overlap they can be merged into one larger fragment */
private boolean mergeContiguous;
/** Should phrases be identified. */
private boolean usePhraseHighlighter;
/** The fields to highlight and field specific configuration properties for each field */
private List<RestRequestFieldsModel> fields;
@Override @Override
public RestRequestHighlightModel onModel() public RestRequestHighlightModel onModel()
{ {
return model; return model;
} }
/**
The string used to mark the start of a highlight in a fragment.
*/
private String prefix;
/**
The string used to mark the end of a highlight in a fragment.
*/
private String postfix;
/**
The maximum number of distinct highlight snippets to return for each highlight field.
*/
private int snippetCount;
/**
The character length of each snippet.
*/
private int fragmentSize;
/**
The number of characters to be considered for highlighting. Matches after this count will not be shown.
*/
private int maxAnalyzedChars;
/**
If fragments over lap they can be merged into one larger fragment
*/
private boolean mergeContiguous;
/**
Should phrases be identified.
*/
private boolean usePhraseHighlighter;
/**
The fields to highlight and field specific configuration properties for each field
*/
private List<RestRequestFieldsModel> fields;
public String getPrefix() public String getPrefix()
{ {
return this.prefix; return this.prefix;
@@ -139,7 +115,7 @@ public class RestRequestHighlightModel extends TestModel implements IRestModel<R
this.maxAnalyzedChars = maxAnalyzedChars; this.maxAnalyzedChars = maxAnalyzedChars;
} }
public boolean getMergeContiguous() public boolean isMergeContiguous()
{ {
return this.mergeContiguous; return this.mergeContiguous;
} }
@@ -149,7 +125,7 @@ public class RestRequestHighlightModel extends TestModel implements IRestModel<R
this.mergeContiguous = mergeContiguous; this.mergeContiguous = mergeContiguous;
} }
public boolean getUsePhraseHighlighter() public boolean isUsePhraseHighlighter()
{ {
return this.usePhraseHighlighter; return this.usePhraseHighlighter;
} }
@@ -168,5 +144,84 @@ public class RestRequestHighlightModel extends TestModel implements IRestModel<R
{ {
this.fields = fields; this.fields = fields;
} }
public static RestRequestHighlightModelBuilder builder()
{
return new RestRequestHighlightModelBuilder();
}
public static class RestRequestHighlightModelBuilder
{
private String prefix;
private String postfix;
private int snippetCount;
private int fragmentSize;
private int maxAnalyzedChars;
private boolean mergeContiguous;
private boolean usePhraseHighlighter;
private List<RestRequestFieldsModel> fields;
public RestRequestHighlightModelBuilder prefix(String prefix)
{
this.prefix = prefix;
return this;
}
public RestRequestHighlightModelBuilder postfix(String postfix)
{
this.postfix = postfix;
return this;
}
public RestRequestHighlightModelBuilder snippetCount(int snippetCount)
{
this.snippetCount = snippetCount;
return this;
}
public RestRequestHighlightModelBuilder fragmentSize(int fragmentSize)
{
this.fragmentSize = fragmentSize;
return this;
}
public RestRequestHighlightModelBuilder maxAnalyzedChars(int maxAnalyzedChars)
{
this.maxAnalyzedChars = maxAnalyzedChars;
return this;
}
public RestRequestHighlightModelBuilder mergeContinuous(boolean mergeContiguous)
{
this.mergeContiguous = mergeContiguous;
return this;
}
public RestRequestHighlightModelBuilder usePhraseHighlighter(boolean usePhraseHighlighter)
{
this.usePhraseHighlighter = usePhraseHighlighter;
return this;
}
public RestRequestHighlightModelBuilder fields(List<String> fields)
{
this.fields = fields.stream().map(field -> new RestRequestFieldsModel(field)).toList();
return this;
}
public RestRequestHighlightModel build()
{
RestRequestHighlightModel highlightModel = new RestRequestHighlightModel();
highlightModel.setPrefix(prefix);
highlightModel.setPostfix(postfix);
highlightModel.setSnippetCount(snippetCount);
highlightModel.setFragmentSize(fragmentSize);
highlightModel.setMaxAnalyzedChars(maxAnalyzedChars);
highlightModel.setMergeContiguous(mergeContiguous);
highlightModel.setUsePhraseHighlighter(usePhraseHighlighter);
highlightModel.setFields(fields);
return highlightModel;
}
}
} }

View File

@@ -60,7 +60,7 @@ public class SearchScoreModel extends TestModel implements IRestModel<SearchScor
@JsonProperty(required = true) @JsonProperty(required = true)
private float score; private float score;
private List<ResponseHighLightModel> highlight; private List<ResponseHighlightModel> highlight;
public float getScore() public float getScore()
{ {
@@ -78,12 +78,12 @@ public class SearchScoreModel extends TestModel implements IRestModel<SearchScor
return this; return this;
} }
public List<ResponseHighLightModel> getHighlight() public List<ResponseHighlightModel> getHighlight()
{ {
return highlight; return highlight;
} }
public void setHighlight(List<ResponseHighLightModel> highlight) public void setHighlight(List<ResponseHighlightModel> highlight)
{ {
this.highlight = highlight; this.highlight = highlight;
} }