madrob commented on code in PR #962:
URL: https://github.com/apache/solr/pull/962#discussion_r938188572
##########
solr/core/src/java/org/apache/solr/handler/component/QueryElevationComponent.java:
##########
@@ -413,35 +409,30 @@ private ElevationProvider loadElevationProvider(SolrCore
core) throws Exception
* @throws RuntimeException If the config does not provide an XML content of
the expected format
* (either {@link RuntimeException} or {@link
org.apache.solr.common.SolrException}).
*/
- protected ElevationProvider loadElevationProvider(XmlConfigFile config) {
+ protected ElevationProvider loadElevationProvider(Document doc) {
Map<ElevatingQuery, ElevationBuilder> elevationBuilderMap = new
LinkedHashMap<>();
- XPath xpath = XPathFactory.newInstance().newXPath();
Review Comment:
why did we move away from the XPath model? because it's slow or for some
other reason?
##########
solr/core/src/java/org/apache/solr/handler/component/QueryElevationComponent.java:
##########
@@ -376,19 +375,19 @@ protected long getConfigVersion(SolrCore core) {
*
* @return The loaded {@link ElevationProvider}; not null.
*/
- private ElevationProvider loadElevationProvider(SolrCore core) throws
Exception {
- XmlConfigFile cfg;
- try {
- cfg = new XmlConfigFile(core.getResourceLoader(), configFileName);
+ private ElevationProvider loadElevationProvider(SolrCore core) throws
IOException, SAXException {
+ try (var inputStream =
core.getResourceLoader().openResource(configFileName)) {
Review Comment:
Yea, there's something strange about the flow here, where we open the
resource once and then again open the same resource to check if it's empty
(line 391)
##########
solr/core/src/java/org/apache/solr/handler/component/QueryElevationComponent.java:
##########
@@ -413,35 +409,30 @@ private ElevationProvider loadElevationProvider(SolrCore
core) throws Exception
* @throws RuntimeException If the config does not provide an XML content of
the expected format
* (either {@link RuntimeException} or {@link
org.apache.solr.common.SolrException}).
*/
- protected ElevationProvider loadElevationProvider(XmlConfigFile config) {
+ protected ElevationProvider loadElevationProvider(Document doc) {
Map<ElevatingQuery, ElevationBuilder> elevationBuilderMap = new
LinkedHashMap<>();
- XPath xpath = XPathFactory.newInstance().newXPath();
- NodeList nodes = (NodeList) config.evaluate("elevate/query",
XPathConstants.NODESET);
- for (int i = 0; i < nodes.getLength(); i++) {
- Node node = nodes.item(i);
- String queryString = DOMUtil.getAttr(node, "text", "missing query
'text'");
- String matchString = DOMUtil.getAttr(node, "match");
- ElevatingQuery elevatingQuery =
- new ElevatingQuery(queryString, isSubsetMatchPolicy(matchString));
-
- NodeList children;
- try {
- children = (NodeList) xpath.evaluate("doc", node,
XPathConstants.NODESET);
- } catch (XPathExpressionException e) {
- throw new SolrException(
- SolrException.ErrorCode.SERVER_ERROR, "query requires '<doc .../>'
child");
- }
-
- if (children.getLength() == 0) { // weird
+ if (!doc.getDocumentElement().getNodeName().equals("elevate")) {
+ throw new SolrException(
+ SolrException.ErrorCode.BAD_REQUEST, "Root element must be
<elevate>");
+ }
+ NodeList queryNodes =
doc.getDocumentElement().getElementsByTagName("query");
+ for (int i = 0; i < queryNodes.getLength(); i++) {
+ var queryNode = (Element) queryNodes.item(i);
+ var queryString = DOMUtil.getAttr(queryNode, "text", "missing query
'text'");
+ var matchString = DOMUtil.getAttr(queryNode, "match");
+ var elevatingQuery = new ElevatingQuery(queryString,
isSubsetMatchPolicy(matchString));
+
+ NodeList docNodes = queryNode.getElementsByTagName("doc");
+ if (docNodes.getLength() == 0) { // weird
continue;
}
- ElevationBuilder elevationBuilder = new ElevationBuilder();
- for (int j = 0; j < children.getLength(); j++) {
- Node child = children.item(j);
- String id = DOMUtil.getAttr(child, "id", "missing 'id'");
- String e = DOMUtil.getAttr(child, EXCLUDE, null);
+ var elevationBuilder = new ElevationBuilder();
+ for (int j = 0; j < docNodes.getLength(); j++) {
+ var docNode = (Element) docNodes.item(j);
Review Comment:
unnecessary cast
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]