mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-21 18:09:20 +00:00
Merged searchapi (5.2.1) to 5.2.N (5.2.1)
130107 gjames: SEARCH-122: Implementing spellcheck queries git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@130301 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -30,12 +30,14 @@ import org.alfresco.repo.search.impl.lucene.SolrJSONResultSet;
|
||||
import org.alfresco.rest.api.Nodes;
|
||||
import org.alfresco.rest.api.model.Node;
|
||||
import org.alfresco.rest.api.model.UserInfo;
|
||||
import org.alfresco.rest.api.search.context.SpellCheckContext;
|
||||
import org.alfresco.rest.api.search.model.SearchEntry;
|
||||
import org.alfresco.rest.api.search.model.SearchQuery;
|
||||
import org.alfresco.rest.framework.resource.parameters.CollectionWithPagingInfo;
|
||||
import org.alfresco.rest.api.search.context.SearchContext;
|
||||
import org.alfresco.rest.api.search.context.FacetQueryContext;
|
||||
import org.alfresco.service.cmr.search.ResultSet;
|
||||
import org.alfresco.service.cmr.search.SpellCheckResult;
|
||||
import org.alfresco.util.ParameterCheck;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
@@ -135,6 +137,7 @@ public class ResultMapper
|
||||
SearchContext context = null;
|
||||
Map<String, Integer> facetQueries = solrResultSet.getFacetQueries();
|
||||
List<FacetQueryContext> facetResults = null;
|
||||
SpellCheckContext spellCheckContext = null;
|
||||
|
||||
if(facetQueries!= null && !facetQueries.isEmpty())
|
||||
{
|
||||
@@ -144,7 +147,13 @@ public class ResultMapper
|
||||
facetResults.add(new FacetQueryContext(fq.getKey(), fq.getValue()));
|
||||
}
|
||||
}
|
||||
context = new SearchContext(solrResultSet.getLastIndexedTxId(), facetResults);
|
||||
|
||||
SpellCheckResult spell = solrResultSet.getSpellCheckResult();
|
||||
if (spell != null && spell.getResultName() != null && !spell.getResults().isEmpty())
|
||||
{
|
||||
spellCheckContext = new SpellCheckContext(spell.getResultName(),spell.getResults());
|
||||
}
|
||||
context = new SearchContext(solrResultSet.getLastIndexedTxId(), facetResults, spellCheckContext);
|
||||
return isNullContext(context)?null:context;
|
||||
}
|
||||
|
||||
@@ -155,7 +164,7 @@ public class ResultMapper
|
||||
*/
|
||||
protected boolean isNullContext(SearchContext context)
|
||||
{
|
||||
return (context.getFacetQueries() == null && context.getConsistency() == null);
|
||||
return (context.getFacetQueries() == null && context.getConsistency() == null && context.getSpellCheck() == null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -32,6 +32,7 @@ import org.alfresco.rest.api.search.model.FilterQuery;
|
||||
import org.alfresco.rest.api.search.model.Query;
|
||||
import org.alfresco.rest.api.search.model.SearchQuery;
|
||||
import org.alfresco.rest.api.search.model.SortDef;
|
||||
import org.alfresco.rest.api.search.model.Spelling;
|
||||
import org.alfresco.rest.api.search.model.Template;
|
||||
import org.alfresco.rest.framework.core.exceptions.InvalidArgumentException;
|
||||
import org.alfresco.rest.framework.resource.content.BasicContentInfo;
|
||||
@@ -82,7 +83,7 @@ public class SearchMapper
|
||||
public static final String AFTS = "afts";
|
||||
|
||||
/**
|
||||
* Turn the params into the Java SearchParameters object
|
||||
* Turn the SearchQuery params serialized by Jackson into the Java SearchParameters object
|
||||
* @param params
|
||||
* @return SearchParameters
|
||||
*/
|
||||
@@ -101,6 +102,7 @@ public class SearchMapper
|
||||
fromDefault(sp, searchQuery.getDefaults());
|
||||
fromFilterQuery(sp, searchQuery.getFilterQueries());
|
||||
fromFacetQuery(sp, searchQuery.getFacetQueries());
|
||||
fromSpellCheck(sp, searchQuery.getSpellcheck());
|
||||
|
||||
return sp;
|
||||
}
|
||||
@@ -304,4 +306,29 @@ public class SearchMapper
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* SearchParameters from SpellCheck object
|
||||
* @param sp SearchParameters
|
||||
* @param defaults SpellCheck
|
||||
*/
|
||||
public void fromSpellCheck(SearchParameters sp, Spelling spelling)
|
||||
{
|
||||
if (spelling != null)
|
||||
{
|
||||
if (spelling.getQuery() != null && !spelling.getQuery().isEmpty())
|
||||
{
|
||||
sp.setSearchTerm(spelling.getQuery());
|
||||
}
|
||||
else
|
||||
{
|
||||
if (sp.getSearchTerm() == null || sp.getSearchTerm().isEmpty())
|
||||
{
|
||||
//We don't have a valid search term to use with the spelling
|
||||
throw new InvalidArgumentException(InvalidArgumentException.DEFAULT_MESSAGE_ID,
|
||||
new Object[] { ": userQuery or spelling.query required." });
|
||||
}
|
||||
}
|
||||
sp.setSpellCheck(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user