mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
SEARCH-106: Adding Highlight parameters to SearchParameters api
This commit is contained in:
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Data model classes
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.service.cmr.search;
|
||||
|
||||
import org.alfresco.api.AlfrescoPublicApi;
|
||||
import org.codehaus.jackson.annotate.JsonCreator;
|
||||
import org.codehaus.jackson.annotate.JsonProperty;
|
||||
|
||||
/**
|
||||
* Parameters used for search hightlighting that are Field Specific
|
||||
*/
|
||||
|
||||
@AlfrescoPublicApi
|
||||
public class FieldHighlightParameters extends HighlightParameters
|
||||
{
|
||||
private final String field;
|
||||
|
||||
@JsonCreator
|
||||
public FieldHighlightParameters(
|
||||
@JsonProperty("field") String field,
|
||||
@JsonProperty("snippetCount") Integer snippetCount,
|
||||
@JsonProperty("fragmentSize") Integer fragmentSize,
|
||||
@JsonProperty("mergeContiguous") Boolean mergeContiguous,
|
||||
@JsonProperty("prefix") String prefix,
|
||||
@JsonProperty("postfix") String postfix)
|
||||
{
|
||||
super(snippetCount, fragmentSize, mergeContiguous, prefix, postfix);
|
||||
this.field = field;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "FieldHighlightParameters{" +
|
||||
"snippetCount=" + snippetCount +
|
||||
", fragmentSize=" + fragmentSize +
|
||||
", mergeContiguous=" + mergeContiguous +
|
||||
", prefix='" + prefix + '\'' +
|
||||
", postfix='" + postfix + '\'' +
|
||||
", field='" + field + '\'' +
|
||||
'}';
|
||||
}
|
||||
|
||||
public String getField()
|
||||
{
|
||||
return field;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o)
|
||||
{
|
||||
if (this == o)
|
||||
return true;
|
||||
if (o == null || getClass() != o.getClass())
|
||||
return false;
|
||||
if (!super.equals(o))
|
||||
return false;
|
||||
|
||||
FieldHighlightParameters that = (FieldHighlightParameters) o;
|
||||
|
||||
if (field != null ? !field.equals(that.field) : that.field != null)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
int result = super.hashCode();
|
||||
result = 31 * result + (field != null ? field.hashCode() : 0);
|
||||
return result;
|
||||
}
|
||||
}
|
@@ -0,0 +1,127 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Data model classes
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.service.cmr.search;
|
||||
|
||||
import org.alfresco.api.AlfrescoPublicApi;
|
||||
import org.codehaus.jackson.annotate.JsonCreator;
|
||||
import org.codehaus.jackson.annotate.JsonProperty;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Parameters used for search hightlighting that apply to all fields
|
||||
*/
|
||||
|
||||
@AlfrescoPublicApi
|
||||
public class GeneralHighlightParameters extends HighlightParameters
|
||||
{
|
||||
private final Integer maxAnalyzedChars;
|
||||
private final Boolean usePhraseHighlighter;
|
||||
|
||||
private final List<FieldHighlightParameters> fields;
|
||||
|
||||
@JsonCreator
|
||||
public GeneralHighlightParameters(
|
||||
@JsonProperty("snippetCount") Integer snippetCount,
|
||||
@JsonProperty("fragmentSize") Integer fragmentSize,
|
||||
@JsonProperty("mergeContiguous") Boolean mergeContiguous,
|
||||
@JsonProperty("prefix") String prefix,
|
||||
@JsonProperty("postfix") String postfix,
|
||||
@JsonProperty("maxAnalyzedChars") Integer maxAnalyzedChars,
|
||||
@JsonProperty("usePhraseHighlighter") Boolean usePhraseHighlighter,
|
||||
@JsonProperty("fields") List<FieldHighlightParameters> fields)
|
||||
{
|
||||
super(snippetCount, fragmentSize, mergeContiguous, prefix, postfix);
|
||||
this.maxAnalyzedChars = maxAnalyzedChars;
|
||||
this.usePhraseHighlighter = usePhraseHighlighter;
|
||||
this.fields = fields;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "GeneralHighlightParameters{" +
|
||||
"snippetCount=" + snippetCount +
|
||||
", fragmentSize=" + fragmentSize +
|
||||
", mergeContiguous=" + mergeContiguous +
|
||||
", prefix='" + prefix + '\'' +
|
||||
", postfix='" + postfix + '\'' +
|
||||
", maxAnalyzedChars=" + maxAnalyzedChars +
|
||||
", usePhraseHighlighter=" + usePhraseHighlighter +
|
||||
", fields=" + fields +
|
||||
'}';
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o)
|
||||
{
|
||||
if (this == o)
|
||||
return true;
|
||||
if (o == null || getClass() != o.getClass())
|
||||
return false;
|
||||
if (!super.equals(o))
|
||||
return false;
|
||||
|
||||
GeneralHighlightParameters that = (GeneralHighlightParameters) o;
|
||||
|
||||
if (getMaxAnalyzedChars() != null ? !getMaxAnalyzedChars().equals(that.getMaxAnalyzedChars()) : that.getMaxAnalyzedChars() != null)
|
||||
return false;
|
||||
if (getUsePhraseHighlighter() != null ?
|
||||
!getUsePhraseHighlighter().equals(that.getUsePhraseHighlighter()) :
|
||||
that.getUsePhraseHighlighter() != null)
|
||||
return false;
|
||||
if (getFields() != null ? !getFields().equals(that.getFields()) : that.getFields() != null)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
int result = super.hashCode();
|
||||
result = 31 * result + (getMaxAnalyzedChars() != null ? getMaxAnalyzedChars().hashCode() : 0);
|
||||
result = 31 * result + (getUsePhraseHighlighter() != null ? getUsePhraseHighlighter().hashCode() : 0);
|
||||
result = 31 * result + (getFields() != null ? getFields().hashCode() : 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
public Integer getMaxAnalyzedChars()
|
||||
{
|
||||
return maxAnalyzedChars;
|
||||
}
|
||||
|
||||
public Boolean getUsePhraseHighlighter()
|
||||
{
|
||||
return usePhraseHighlighter;
|
||||
}
|
||||
|
||||
public List<FieldHighlightParameters> getFields()
|
||||
{
|
||||
return fields;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,128 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Data model classes
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.service.cmr.search;
|
||||
|
||||
import org.alfresco.api.AlfrescoPublicApi;
|
||||
import org.codehaus.jackson.annotate.JsonCreator;
|
||||
import org.codehaus.jackson.annotate.JsonProperty;
|
||||
|
||||
/**
|
||||
* Parameters used for search hightlighting.
|
||||
*/
|
||||
|
||||
@AlfrescoPublicApi
|
||||
public abstract class HighlightParameters
|
||||
{
|
||||
final Integer snippetCount;
|
||||
final Integer fragmentSize;
|
||||
|
||||
final Boolean mergeContiguous;
|
||||
|
||||
final String prefix;
|
||||
final String postfix;
|
||||
|
||||
public HighlightParameters(Integer snippetCount, Integer fragmentSize,
|
||||
Boolean mergeContiguous, String prefix, String postfix)
|
||||
{
|
||||
this.snippetCount = snippetCount;
|
||||
this.fragmentSize = fragmentSize;
|
||||
this.mergeContiguous = mergeContiguous;
|
||||
this.prefix = prefix;
|
||||
this.postfix = postfix;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o)
|
||||
{
|
||||
if (this == o)
|
||||
return true;
|
||||
if (o == null || getClass() != o.getClass())
|
||||
return false;
|
||||
|
||||
HighlightParameters that = (HighlightParameters) o;
|
||||
|
||||
if (snippetCount != null ? !snippetCount.equals(that.snippetCount) : that.snippetCount != null)
|
||||
return false;
|
||||
if (fragmentSize != null ? !fragmentSize.equals(that.fragmentSize) : that.fragmentSize != null)
|
||||
return false;
|
||||
if (mergeContiguous != null ? !mergeContiguous.equals(that.mergeContiguous) : that.mergeContiguous != null)
|
||||
return false;
|
||||
if (prefix != null ? !prefix.equals(that.prefix) : that.prefix != null)
|
||||
return false;
|
||||
if (postfix != null ? !postfix.equals(that.postfix) : that.postfix != null)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
int result = snippetCount != null ? snippetCount.hashCode() : 0;
|
||||
result = 31 * result + (fragmentSize != null ? fragmentSize.hashCode() : 0);
|
||||
result = 31 * result + (mergeContiguous != null ? mergeContiguous.hashCode() : 0);
|
||||
result = 31 * result + (prefix != null ? prefix.hashCode() : 0);
|
||||
result = 31 * result + (postfix != null ? postfix.hashCode() : 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "HighlightParameters{" +
|
||||
"snippetCount=" + snippetCount +
|
||||
", fragmentSize=" + fragmentSize +
|
||||
", mergeContiguous=" + mergeContiguous +
|
||||
", prefix='" + prefix + '\'' +
|
||||
", postfix='" + postfix + '\'' +
|
||||
'}';
|
||||
}
|
||||
|
||||
public Integer getSnippetCount()
|
||||
{
|
||||
return snippetCount;
|
||||
}
|
||||
|
||||
public Integer getFragmentSize()
|
||||
{
|
||||
return fragmentSize;
|
||||
}
|
||||
|
||||
public Boolean getMergeContiguous()
|
||||
{
|
||||
return mergeContiguous;
|
||||
}
|
||||
|
||||
public String getPrefix()
|
||||
{
|
||||
return prefix;
|
||||
}
|
||||
|
||||
public String getPostfix()
|
||||
{
|
||||
return postfix;
|
||||
}
|
||||
}
|
@@ -187,6 +187,8 @@ public class SearchParameters implements BasicSearchParameters
|
||||
|
||||
private boolean spellCheck;
|
||||
|
||||
private GeneralHighlightParameters hightlight;
|
||||
|
||||
/**
|
||||
* Default constructor
|
||||
*/
|
||||
@@ -231,6 +233,7 @@ public class SearchParameters implements BasicSearchParameters
|
||||
sp.filterQueries.addAll(this.filterQueries);
|
||||
sp.searchTerm = this.searchTerm;
|
||||
sp.spellCheck = this.spellCheck;
|
||||
sp.hightlight = this.hightlight;
|
||||
return sp;
|
||||
}
|
||||
|
||||
@@ -277,6 +280,11 @@ public class SearchParameters implements BasicSearchParameters
|
||||
return query;
|
||||
}
|
||||
|
||||
public void setHightlight(GeneralHighlightParameters hightlight)
|
||||
{
|
||||
this.hightlight = hightlight;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the query language.
|
||||
*
|
||||
@@ -370,6 +378,24 @@ public class SearchParameters implements BasicSearchParameters
|
||||
sortDefinitions.add(sortDefinition);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds parameters used for search highlighing
|
||||
* @param hightlight - the highlighting parameters
|
||||
*/
|
||||
public void addHightlight(GeneralHighlightParameters hightlight)
|
||||
{
|
||||
this.hightlight = hightlight;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the parameters used for search highlighing
|
||||
* @return GeneralHighlightParameters - the highlighting parameters
|
||||
*/
|
||||
public GeneralHighlightParameters getHightlight()
|
||||
{
|
||||
return hightlight;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is data in the current transaction excluded from the search.
|
||||
*
|
||||
|
Reference in New Issue
Block a user