Class ExplainScoreServlet
- java.lang.Object
-
- javax.servlet.GenericServlet
-
- org.apache.sling.api.servlets.SlingSafeMethodsServlet
-
- org.apache.sling.api.servlets.SlingAllMethodsServlet
-
- com.adobe.acs.commons.oak.sql2scorer.impl.servlets.ExplainScoreServlet
-
- All Implemented Interfaces:
Serializable,javax.servlet.Servlet,javax.servlet.ServletConfig
public class ExplainScoreServlet extends org.apache.sling.api.servlets.SlingAllMethodsServletThis servlet submits a JCR-SQL2 query with an additional oak:scoreExplanation column that contains the explanation of the Lucene fulltext score, where applicable. Also executes the "explain" command to provide the index plan used in the same JSON response.The query result is returned as rows, not nodes, which means jcr:path must actually be selected in the query if it is to be returned as a column.
This servlet is intended to be used as a tool for development and exploration of oak:index definitions, and is not designed for running arbitrary queries, since the oak:scoreExplanation column will add considerable cost to each operation.
The response JSON object contains 4 properties: - stmt: the JCR-SQL2 query statement, as executed - plan: the 'explain' plan, which identifies the index used and the filter expression - cols: an array of column names specified in the executed query statement - rows: a 2-dimensional array of query result rows, as in '.rows[result index][column index]'. Each row has as many array elements as there are elements in the .cols array. A non-existing value for a row in a particular column will be represented by the json
nullvalue.The first column will always be 'oak:scoreExplanation', i.e. .cols[0] === 'oak:scoreExplanation', in order to make it possible to treat the score explanation as a special case in the UI.
The first element of each row, therefore, contains the text of the score explanation, which is a pre-formatted string with new lines and a 2-space shift-width indent. If a fulltext score is not computed for the query, i.e. because the statement did not use the 'contains()' function or because the plan selected a non-lucene index, the first element will contain the JSON null value.
For example, if you were to submit the following query:
select [jcr:path] from [cq:Page] where contains(*, 'we-retail')
Your plan might be something like:
[cq:Page] as [cq:Page] /* lucene:cqPageLucene(/oak:index/cqPageLucene) +:fulltext:we +:fulltext:retail ft:("we-retail") where contains([cq:Page].[*], 'we-retail')
You might get an explanation similar to this for the first result:
4.255377 = (MATCH) sum of: 2.0704787 = (MATCH) weight(:fulltext:we in 80137) [DefaultSimilarity], result of: 2.0704787 = score(doc=80137,freq=2.0 = termFreq=2.0 ), product of: 0.6975356 = queryWeight, product of: 4.1977777 = idf(docFreq=6362, maxDocs=155754) 0.16616783 = queryNorm 2.968277 = fieldWeight in 80137, product of: 1.4142135 = tf(freq=2.0), with freq of: 2.0 = termFreq=2.0 4.1977777 = idf(docFreq=6362, maxDocs=155754) 0.5 = fieldNorm(doc=80137) 2.1848981 = (MATCH) weight(:fulltext:retail in 80137) [DefaultSimilarity], result of: 2.1848981 = score(doc=80137,freq=2.0 = termFreq=2.0 ), product of: 0.7165501 = queryWeight, product of: 4.312207 = idf(docFreq=5674, maxDocs=155754) 0.16616783 = queryNorm 3.049191 = fieldWeight in 80137, product of: 1.4142135 = tf(freq=2.0), with freq of: 2.0 = termFreq=2.0 4.312207 = idf(docFreq=5674, maxDocs=155754) 0.5 = fieldNorm(doc=80137)- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description ExplainScoreServlet()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voiddoPost(org.apache.sling.api.SlingHttpServletRequest request, org.apache.sling.api.SlingHttpServletResponse response)-
Methods inherited from class org.apache.sling.api.servlets.SlingAllMethodsServlet
doDelete, doPut, getAllowedRequestMethods, isMethodValid, mayService
-
Methods inherited from class org.apache.sling.api.servlets.SlingSafeMethodsServlet
doGeneric, doGet, doHead, doOptions, doTrace, getServletInfo, handleMethodNotImplemented, service, service
-
-
-
-
Method Detail
-
doPost
protected void doPost(@Nonnull org.apache.sling.api.SlingHttpServletRequest request, @Nonnull org.apache.sling.api.SlingHttpServletResponse response) throws javax.servlet.ServletException, IOException
- Overrides:
doPostin classorg.apache.sling.api.servlets.SlingAllMethodsServlet- Throws:
javax.servlet.ServletExceptionIOException
-
-