dsmiley commented on a change in pull request #712:
URL: https://github.com/apache/solr/pull/712#discussion_r815349461



##########
File path: solr/core/src/java/org/apache/solr/schema/FieldType.java
##########
@@ -502,24 +502,52 @@ public Query getPrefixQuery(QParser parser, SchemaField 
sf, String termStr) {
     @Override
     public TokenStreamComponents createComponents(String fieldName) {
       Tokenizer ts = new Tokenizer() {
+        private boolean done = false;
+        private int finalOffset;
+
         final char[] cbuf = new char[maxChars];
         final CharTermAttribute termAtt = 
addAttribute(CharTermAttribute.class);
         final BytesTermAttribute bytesAtt = isPointField() ? 
addAttribute(BytesTermAttribute.class) : null;
         final OffsetAttribute offsetAtt = addAttribute(OffsetAttribute.class);
+
         @Override
         public boolean incrementToken() throws IOException {
-          clearAttributes();
-          int n = input.read(cbuf,0,maxChars);
-          if (n<=0) return false;
-          if (isPointField()) {
-            BytesRef b = ((PointField)FieldType.this).toInternalByteRef(new 
String(cbuf, 0, n));
-            bytesAtt.setBytesRef(b);
-          } else {
-            String s = toInternal(new String(cbuf, 0, n));
-            termAtt.setEmpty().append(s);
+          if (!done) {

Review comment:
       This may be a matter of taste but I think checking for `done` == true 
first allows for the vast majority of this method to have one less indentation 
level, which just looks/reads better.

##########
File path: solr/core/src/java/org/apache/solr/schema/FieldType.java
##########
@@ -502,24 +502,52 @@ public Query getPrefixQuery(QParser parser, SchemaField 
sf, String termStr) {
     @Override
     public TokenStreamComponents createComponents(String fieldName) {
       Tokenizer ts = new Tokenizer() {
+        private boolean done = false;

Review comment:
       This should also be reset to false in `reset()`.

##########
File path: solr/core/src/java/org/apache/solr/schema/FieldType.java
##########
@@ -502,24 +502,52 @@ public Query getPrefixQuery(QParser parser, SchemaField 
sf, String termStr) {
     @Override
     public TokenStreamComponents createComponents(String fieldName) {
       Tokenizer ts = new Tokenizer() {
+        private boolean done = false;
+        private int finalOffset;
+
         final char[] cbuf = new char[maxChars];
         final CharTermAttribute termAtt = 
addAttribute(CharTermAttribute.class);
         final BytesTermAttribute bytesAtt = isPointField() ? 
addAttribute(BytesTermAttribute.class) : null;
         final OffsetAttribute offsetAtt = addAttribute(OffsetAttribute.class);
+
         @Override
         public boolean incrementToken() throws IOException {
-          clearAttributes();
-          int n = input.read(cbuf,0,maxChars);
-          if (n<=0) return false;
-          if (isPointField()) {
-            BytesRef b = ((PointField)FieldType.this).toInternalByteRef(new 
String(cbuf, 0, n));
-            bytesAtt.setBytesRef(b);
-          } else {
-            String s = toInternal(new String(cbuf, 0, n));
-            termAtt.setEmpty().append(s);
+          if (!done) {

Review comment:
       This may be a matter of taste but I think checking for `done` == true 
first allows for the vast majority of this method to have one less indentation 
level, which just looks/reads better.




-- 
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]

Reply via email to