mirror of
https://github.com/Alfresco/SearchServices.git
synced 2026-09-16 18:12:56 +00:00
Complete spellcheck rest tests
This commit is contained in:
@@ -20,32 +20,100 @@ package org.alfresco.rest.search;
|
||||
|
||||
import org.alfresco.rest.model.RestRequestSpellcheckModel;
|
||||
import org.alfresco.utility.model.TestGroup;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.junit.Assert;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/**
|
||||
* Search end point Public API test with spell checking enabled.
|
||||
* @author Michael Suzuki
|
||||
*
|
||||
*5
|
||||
*/
|
||||
public class SearchSpellCheckTest extends AbstractSearchTest
|
||||
{
|
||||
// @Test(groups={TestGroup.SEARCH, TestGroup.REST_API})
|
||||
/**
|
||||
* Perform the below query
|
||||
* {
|
||||
* "spellcheck" : { },
|
||||
* "query" : {
|
||||
* "userQuery" : "alfrezco",
|
||||
* "query" : "cm:title:alfrezco"
|
||||
* }
|
||||
* to yeild the following result.
|
||||
* {
|
||||
* "list": {
|
||||
* "pagination": {
|
||||
* "count": 22,
|
||||
* "hasMoreItems": false,
|
||||
* "totalItems": 22,
|
||||
* "skipCount": 0,
|
||||
* "maxItems": 100
|
||||
* },
|
||||
* "context": {
|
||||
* "spellCheck": {
|
||||
* "type": "searchInsteadFor",
|
||||
* "suggestions": [
|
||||
* "alfresco"
|
||||
* ]
|
||||
* }
|
||||
* },
|
||||
* "entries": [...]
|
||||
* }
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test(groups={TestGroup.SEARCH, TestGroup.REST_API})
|
||||
public void searchMissSpelled() throws Exception
|
||||
{
|
||||
|
||||
SearchResponse nodes = query("carz");
|
||||
restClient.assertStatusCodeIs(HttpStatus.OK);
|
||||
nodes.assertThat().entriesListIsEmpty();
|
||||
|
||||
SearchRequest searchReq = new SearchRequest();
|
||||
RestRequestQueryModel queryReq = new RestRequestQueryModel();
|
||||
queryReq.setQuery("cm:content:carz");
|
||||
queryReq.setUserQuery("carz");
|
||||
queryReq.setQuery("cm:title:alfrezco");
|
||||
queryReq.setUserQuery("alfrezco");
|
||||
searchReq.setQuery(queryReq);
|
||||
searchReq.setSpellcheck(new RestRequestSpellcheckModel());
|
||||
nodes = query(searchReq);
|
||||
assertResponse(query(searchReq));
|
||||
}
|
||||
private void assertResponse(SearchResponse nodes) throws Exception
|
||||
{
|
||||
nodes.assertThat().entriesListIsNotEmpty();
|
||||
nodes.getContext().assertThat().field("spellCheck").isNotEmpty();
|
||||
nodes.getContext().getSpellCheck().assertThat().field("suggestions").contains("alfresco");
|
||||
}
|
||||
@Test
|
||||
/**
|
||||
* Perform alternative way by setting the value in spellcheck object.
|
||||
*
|
||||
* {
|
||||
* "query": {
|
||||
* "query": "cm:title:alfrezco",
|
||||
* "language": "afts"
|
||||
* },
|
||||
* "spellcheck": {"query": "alfrezco"}
|
||||
* }
|
||||
* @throws Exception
|
||||
*/
|
||||
public void searchMissSpelledVersion2() throws Exception
|
||||
{
|
||||
SearchRequest searchReq = new SearchRequest();
|
||||
RestRequestQueryModel queryReq = new RestRequestQueryModel();
|
||||
queryReq.setQuery("cm:title:alfrezco");
|
||||
searchReq.setQuery(queryReq);
|
||||
|
||||
RestRequestSpellcheckModel spellCheck = new RestRequestSpellcheckModel();
|
||||
spellCheck.setQuery("alfrezco");
|
||||
searchReq.setSpellcheck(spellCheck);
|
||||
assertResponse(query(searchReq));
|
||||
}
|
||||
@Test
|
||||
public void searchWithSpellcheckerAndCorrectSpelling() throws Exception
|
||||
{
|
||||
SearchRequest searchReq = new SearchRequest();
|
||||
RestRequestQueryModel queryReq = new RestRequestQueryModel();
|
||||
queryReq.setQuery("cm:title:alfresco");
|
||||
queryReq.setUserQuery("alfresco");
|
||||
searchReq.setQuery(queryReq);
|
||||
searchReq.setSpellcheck(new RestRequestSpellcheckModel());
|
||||
SearchResponse res = query(searchReq);
|
||||
Assert.assertNull(res.getContext());
|
||||
res.assertThat().entriesListIsNotEmpty();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user