From 9001874a475432659132d5ae839ccf21d2b8e692 Mon Sep 17 00:00:00 2001 From: Martijn van Groningen Date: Wed, 19 Mar 2014 11:12:14 +0700 Subject: [PATCH] Invoke super.clone() instead of creating a new instance in the clone methods. --- .../index/search/child/ChildrenConstantScoreQuery.java | 8 +++----- .../index/search/child/ChildrenQuery.java | 8 +++----- .../index/search/child/ParentConstantScoreQuery.java | 8 +++----- .../elasticsearch/index/search/child/ParentQuery.java | 7 +++---- .../index/search/child/TopChildrenQuery.java | 10 +++------- 5 files changed, 15 insertions(+), 26 deletions(-) diff --git a/src/main/java/org/elasticsearch/index/search/child/ChildrenConstantScoreQuery.java b/src/main/java/org/elasticsearch/index/search/child/ChildrenConstantScoreQuery.java index 2a8f3523c89..ce6e46ef2e9 100644 --- a/src/main/java/org/elasticsearch/index/search/child/ChildrenConstantScoreQuery.java +++ b/src/main/java/org/elasticsearch/index/search/child/ChildrenConstantScoreQuery.java @@ -51,7 +51,7 @@ import java.util.Set; public class ChildrenConstantScoreQuery extends Query { private final ParentChildIndexFieldData parentChildIndexFieldData; - private final Query originalChildQuery; + private Query originalChildQuery; private final String parentType; private final String childType; private final Filter parentFilter; @@ -88,12 +88,10 @@ public class ChildrenConstantScoreQuery extends Query { @Override public Query clone() { - ChildrenConstantScoreQuery q = new ChildrenConstantScoreQuery(parentChildIndexFieldData, originalChildQuery.clone(), - parentType, childType, parentFilter, shortCircuitParentDocSet, nonNestedDocsFilter); - q.setBoost(getBoost()); + ChildrenConstantScoreQuery q = (ChildrenConstantScoreQuery) super.clone(); + q.originalChildQuery = originalChildQuery.clone(); if (q.rewrittenChildQuery != null) { q.rewrittenChildQuery = rewrittenChildQuery.clone(); - q.rewriteIndexReader = rewriteIndexReader; } return q; } diff --git a/src/main/java/org/elasticsearch/index/search/child/ChildrenQuery.java b/src/main/java/org/elasticsearch/index/search/child/ChildrenQuery.java index 18ced6b98ae..f1c28a8c5a8 100644 --- a/src/main/java/org/elasticsearch/index/search/child/ChildrenQuery.java +++ b/src/main/java/org/elasticsearch/index/search/child/ChildrenQuery.java @@ -63,7 +63,7 @@ public class ChildrenQuery extends Query { private final String childType; private final Filter parentFilter; private final ScoreType scoreType; - private final Query originalChildQuery; + private Query originalChildQuery; private final int shortCircuitParentDocSet; private final Filter nonNestedDocsFilter; @@ -131,12 +131,10 @@ public class ChildrenQuery extends Query { @Override public Query clone() { - ChildrenQuery q = new ChildrenQuery(parentChildIndexFieldData, parentType, childType, parentFilter, - originalChildQuery, scoreType, shortCircuitParentDocSet, nonNestedDocsFilter); - q.setBoost(getBoost()); + ChildrenQuery q = (ChildrenQuery) super.clone(); + q.originalChildQuery = originalChildQuery.clone(); if (q.rewrittenChildQuery != null) { q.rewrittenChildQuery = rewrittenChildQuery.clone(); - q.rewriteIndexReader = rewriteIndexReader; } return q; } diff --git a/src/main/java/org/elasticsearch/index/search/child/ParentConstantScoreQuery.java b/src/main/java/org/elasticsearch/index/search/child/ParentConstantScoreQuery.java index 4c231be4c9a..11095773f2c 100644 --- a/src/main/java/org/elasticsearch/index/search/child/ParentConstantScoreQuery.java +++ b/src/main/java/org/elasticsearch/index/search/child/ParentConstantScoreQuery.java @@ -46,7 +46,7 @@ import java.util.Set; public class ParentConstantScoreQuery extends Query { private final ParentChildIndexFieldData parentChildIndexFieldData; - private final Query originalParentQuery; + private Query originalParentQuery; private final String parentType; private final Filter childrenFilter; @@ -77,12 +77,10 @@ public class ParentConstantScoreQuery extends Query { @Override public Query clone() { - ParentConstantScoreQuery q = new ParentConstantScoreQuery(parentChildIndexFieldData, originalParentQuery, - parentType, childrenFilter); - q.setBoost(getBoost()); + ParentConstantScoreQuery q = (ParentConstantScoreQuery) super.clone(); + q.originalParentQuery = originalParentQuery.clone(); if (q.rewrittenParentQuery != null) { q.rewrittenParentQuery = rewrittenParentQuery.clone(); - q.rewriteIndexReader = rewriteIndexReader; } return q; } diff --git a/src/main/java/org/elasticsearch/index/search/child/ParentQuery.java b/src/main/java/org/elasticsearch/index/search/child/ParentQuery.java index ab0f7019c81..6750c7cde8f 100644 --- a/src/main/java/org/elasticsearch/index/search/child/ParentQuery.java +++ b/src/main/java/org/elasticsearch/index/search/child/ParentQuery.java @@ -52,7 +52,7 @@ import java.util.Set; public class ParentQuery extends Query { private final ParentChildIndexFieldData parentChildIndexFieldData; - private final Query originalParentQuery; + private Query originalParentQuery; private final String parentType; private final Filter childrenFilter; @@ -122,11 +122,10 @@ public class ParentQuery extends Query { @Override public Query clone() { - ParentQuery q = new ParentQuery(parentChildIndexFieldData, originalParentQuery, parentType, childrenFilter); - q.setBoost(getBoost()); + ParentQuery q = (ParentQuery) super.clone(); + q.originalParentQuery = originalParentQuery.clone(); if (q.rewrittenParentQuery != null) { q.rewrittenParentQuery = rewrittenParentQuery.clone(); - q.rewriteIndexReader = rewriteIndexReader; } return q; } diff --git a/src/main/java/org/elasticsearch/index/search/child/TopChildrenQuery.java b/src/main/java/org/elasticsearch/index/search/child/TopChildrenQuery.java index 5e68e92c66c..0fad99e6685 100644 --- a/src/main/java/org/elasticsearch/index/search/child/TopChildrenQuery.java +++ b/src/main/java/org/elasticsearch/index/search/child/TopChildrenQuery.java @@ -69,7 +69,7 @@ public class TopChildrenQuery extends Query { private final ScoreType scoreType; private final int factor; private final int incrementalFactor; - private final Query originalChildQuery; + private Query originalChildQuery; private final Filter nonNestedDocsFilter; // This field will hold the rewritten form of originalChildQuery, so that we can reuse it @@ -108,14 +108,10 @@ public class TopChildrenQuery extends Query { @Override public Query clone() { - TopChildrenQuery q = new TopChildrenQuery( - parentChildIndexFieldData, originalChildQuery.clone(), childType, parentType, - scoreType, factor, incrementalFactor, cacheRecycler, nonNestedDocsFilter - ); - q.setBoost(getBoost()); + TopChildrenQuery q = (TopChildrenQuery) super.clone(); + q.originalChildQuery = originalChildQuery.clone(); if (q.rewrittenChildQuery != null) { q.rewrittenChildQuery = rewrittenChildQuery.clone(); - q.rewriteIndexReader = rewriteIndexReader; } return q; }