You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@lucene.apache.org by "shubhamvishu (via GitHub)" <gi...@apache.org> on 2024/04/30 02:25:46 UTC
[PR] Convert more classes to record classes [lucene]
shubhamvishu opened a new pull request, #13328:
URL: https://github.com/apache/lucene/pull/13328
### Description
- This PR addresses #13207 to convert more classes on `main` branch to record classes on main (Lucene 10 only).
- It moves a lot of data classes(120 to be precise) to use record classes that were flagged suitable in my IDE and seemed good candidate in general.
- I left a couple of them like `TotalHits` and `SynonymMap` as the PR is already very big and including those were leading to a lot more changes. Maybe we could do those as a separate PR.
Raising this PR since all the tests are passing(`./gradlew test`) but `renderJavadoc` task is complaining about missing java docs on some record classes(converted in this PR) which I see has the javadocs already eg: `TermStats`, `ReaderSlice`. I'm not sure why its flagging those incorrectly or if maybe I'm missing something.
<!--
If this is your first contribution to Lucene, please make sure you have reviewed the contribution guide.
https://github.com/apache/lucene/blob/main/CONTRIBUTING.md
-->
--
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: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
Re: [PR] Convert more classes to record classes [lucene]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #13328:
URL: https://github.com/apache/lucene/pull/13328#issuecomment-2116414026
This PR has not had activity in the past 2 weeks, labeling it as stale. If the PR is waiting for review, notify the dev@lucene.apache.org list. Thank you for your contribution!
--
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: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
Re: [PR] Convert more classes to record classes [lucene]
Posted by "shubhamvishu (via GitHub)" <gi...@apache.org>.
shubhamvishu commented on code in PR #13328:
URL: https://github.com/apache/lucene/pull/13328#discussion_r1751550108
##########
lucene/misc/src/java/org/apache/lucene/misc/util/fst/UpToTwoPositiveIntOutputs.java:
##########
@@ -42,36 +42,11 @@
public final class UpToTwoPositiveIntOutputs extends Outputs<Object> {
/** Holds two long outputs. */
- public static final class TwoLongs {
- public final long first;
- public final long second;
-
- public TwoLongs(long first, long second) {
- this.first = first;
- this.second = second;
+ public record TwoLongs(long first, long second) {
+ public TwoLongs {
assert first >= 0;
assert second >= 0;
}
-
- @Override
- public String toString() {
- return "TwoLongs:" + first + "," + second;
- }
Review Comment:
Yes, its fine in this case.
--
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: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
Re: [PR] Convert more classes to record classes [lucene]
Posted by "shubhamvishu (via GitHub)" <gi...@apache.org>.
shubhamvishu commented on code in PR #13328:
URL: https://github.com/apache/lucene/pull/13328#discussion_r1751557625
##########
lucene/test-framework/src/java/org/apache/lucene/tests/codecs/asserting/AssertingLiveDocsFormat.java:
##########
@@ -68,9 +68,7 @@ public String toString() {
return "Asserting(" + in + ")";
}
- static class AssertingBits implements Bits {
- final Bits in;
-
+ record AssertingBits(Bits in) implements Bits {
Review Comment:
I agree, lets keep it as is.
--
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: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
Re: [PR] Convert more classes to record classes [lucene]
Posted by "uschindler (via GitHub)" <gi...@apache.org>.
uschindler commented on code in PR #13328:
URL: https://github.com/apache/lucene/pull/13328#discussion_r1584332062
##########
lucene/core/src/java/org/apache/lucene/codecs/TermStats.java:
##########
@@ -16,24 +16,10 @@
*/
package org.apache.lucene.codecs;
-import org.apache.lucene.index.TermsEnum; // javadocs
-
/**
* Holder for per-term statistics.
*
- * @see TermsEnum#docFreq
- * @see TermsEnum#totalTermFreq
+ * @param docFreq How many documents have at least one occurrence of this term.
+ * @param totalTermFreq Total number of times this term occurs across all documents in the field.
*/
-public class TermStats {
- /** How many documents have at least one occurrence of this term. */
- public final int docFreq;
-
- /** Total number of times this term occurs across all documents in the field. */
- public final long totalTermFreq;
-
- /** Sole constructor. */
- public TermStats(int docFreq, long totalTermFreq) {
- this.docFreq = docFreq;
- this.totalTermFreq = totalTermFreq;
- }
-}
+public record TermStats(int docFreq, long totalTermFreq) {}
Review Comment:
I think to fix this we have to check for "mandated" elements: https://docs.oracle.com/en/java/javase/21/docs/api/java.compiler/javax/lang/model/util/Elements.Origin.html#MANDATED
Not sure how to do this, so let's do this in a separate issue.
--
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: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
Re: [PR] Convert more classes to record classes [lucene]
Posted by "shubhamvishu (via GitHub)" <gi...@apache.org>.
shubhamvishu commented on PR #13328:
URL: https://github.com/apache/lucene/pull/13328#issuecomment-2144096151
Hi @uschindler , thanks for the review. I took another pass at the changes and pushed some commits addressing your comments. Please have a look when you get a chance. Thanks!
--
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: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
Re: [PR] Convert more classes to record classes [lucene]
Posted by "shubhamvishu (via GitHub)" <gi...@apache.org>.
shubhamvishu commented on code in PR #13328:
URL: https://github.com/apache/lucene/pull/13328#discussion_r1751558206
##########
lucene/core/src/java/org/apache/lucene/util/FixedBits.java:
##########
@@ -17,15 +17,7 @@
package org.apache.lucene.util;
/** Immutable twin of FixedBitSet. */
-final class FixedBits implements Bits {
-
- final long[] bits;
- final int length;
-
- FixedBits(long[] bits, int length) {
- this.bits = bits;
- this.length = length;
- }
+record FixedBits(long[] bits, int length) implements Bits {
Review Comment:
Sure!
--
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: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
Re: [PR] Convert more classes to record classes [lucene]
Posted by "uschindler (via GitHub)" <gi...@apache.org>.
uschindler commented on code in PR #13328:
URL: https://github.com/apache/lucene/pull/13328#discussion_r1752842660
##########
lucene/sandbox/src/java/org/apache/lucene/sandbox/search/CombinedFieldQuery.java:
##########
@@ -163,11 +156,6 @@ public boolean equals(Object o) {
FieldAndWeight that = (FieldAndWeight) o;
return Float.compare(that.weight, weight) == 0 && Objects.equals(field, that.field);
}
Review Comment:
Hi,
The equals methods for floats is generated by invokedynamic using a helper. When a record component is a float, the autogenerated impl is generated at runtime as combination of several Method handles. It compares them using this code:
https://github.com/openjdk/jdk/blob/9785e19f3f87306cabc26a862d35b89d41cfef93/src/java.base/share/classes/java/lang/runtime/ObjectMethods.java#L157
The method handles used by the code generator are saved in a map:
https://github.com/openjdk/jdk/blob/9785e19f3f87306cabc26a862d35b89d41cfef93/src/java.base/share/classes/java/lang/runtime/ObjectMethods.java#L101
This is equivalent to the already existing code. So please remove all custom equals methods.
Unfortunately in the merged PR there are so one more. I will add a not on them. Please remove them in a followup.
--
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: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
Re: [PR] Convert more classes to record classes [lucene]
Posted by "uschindler (via GitHub)" <gi...@apache.org>.
uschindler commented on code in PR #13328:
URL: https://github.com/apache/lucene/pull/13328#discussion_r1752842660
##########
lucene/sandbox/src/java/org/apache/lucene/sandbox/search/CombinedFieldQuery.java:
##########
@@ -163,11 +156,6 @@ public boolean equals(Object o) {
FieldAndWeight that = (FieldAndWeight) o;
return Float.compare(that.weight, weight) == 0 && Objects.equals(field, that.field);
}
Review Comment:
Hi,
The equals methods for floats is generated by invokedynamic at runtime using a bootstrapping:
https://github.com/openjdk/jdk/blob/9785e19f3f87306cabc26a862d35b89d41cfef93/src/java.base/share/classes/java/lang/runtime/ObjectMethods.java#L382
The class file of a record only contains a stub equals/hashcode/to string which delegates to an invokedynamic call passing the class which allows the bootstrapped to get all record components and construct a method handle for the whole method implementation.
When a record component is a float, the autogenerated impl using this impl to handle floats. It compares them using this code:
https://github.com/openjdk/jdk/blob/9785e19f3f87306cabc26a862d35b89d41cfef93/src/java.base/share/classes/java/lang/runtime/ObjectMethods.java#L157
The method handles used by the code generator are saved in a map:
https://github.com/openjdk/jdk/blob/9785e19f3f87306cabc26a862d35b89d41cfef93/src/java.base/share/classes/java/lang/runtime/ObjectMethods.java#L101
This is equivalent to the already existing code. So please remove all custom equals methods.
Unfortunately in the merged PR there are some more. Please remove them in a followup.
--
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: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
Re: [PR] Convert more classes to record classes [lucene]
Posted by "shubhamvishu (via GitHub)" <gi...@apache.org>.
shubhamvishu commented on code in PR #13328:
URL: https://github.com/apache/lucene/pull/13328#discussion_r1752258294
##########
lucene/CHANGES.txt:
##########
@@ -118,6 +118,8 @@ API Changes
argument with a `FacetsCollectorManager` and update the return type to include both `TopDocs` results as well as
facets results. (Luca Cavanna)
+* GITHUB#13328: Convert CollectionStatistics, TermStatistics and LeafMetadata etc. to record classes. (Shubham Chaudhary)
Review Comment:
This looks better indeed. I'll reword it.
##########
lucene/MIGRATE.md:
##########
@@ -193,6 +193,7 @@ access the members using method calls instead of field accesses. Affected classe
- `IOContext`, `MergeInfo`, and `FlushInfo` (GITHUB#13205)
- `BooleanClause` (GITHUB#13261)
+- `CollectionStatistics`, `TermStatistics` and `LeafMetadata` (GITHUB#13328)
Review Comment:
Sure, I'll reword. I haven't changed `TopDocs` in this PR and hence I didn't include it. Maybe some confusion(prolly because there are just too many classes changed here)
--
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: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
Re: [PR] Convert more classes to record classes [lucene]
Posted by "uschindler (via GitHub)" <gi...@apache.org>.
uschindler commented on code in PR #13328:
URL: https://github.com/apache/lucene/pull/13328#discussion_r1584221042
##########
lucene/core/src/java/org/apache/lucene/codecs/TermStats.java:
##########
@@ -16,24 +16,10 @@
*/
package org.apache.lucene.codecs;
-import org.apache.lucene.index.TermsEnum; // javadocs
-
/**
* Holder for per-term statistics.
*
- * @see TermsEnum#docFreq
- * @see TermsEnum#totalTermFreq
+ * @param docFreq How many documents have at least one occurrence of this term.
+ * @param totalTermFreq Total number of times this term occurs across all documents in the field.
*/
-public class TermStats {
- /** How many documents have at least one occurrence of this term. */
- public final int docFreq;
-
- /** Total number of times this term occurs across all documents in the field. */
- public final long totalTermFreq;
-
- /** Sole constructor. */
- public TermStats(int docFreq, long totalTermFreq) {
- this.docFreq = docFreq;
- this.totalTermFreq = totalTermFreq;
- }
-}
+public record TermStats(int docFreq, long totalTermFreq) {}
Review Comment:
I could only imagine that MissingDoclet can't correctly handle inner classes!? But on the other hand it works fine with enums and it also operates recursively.
I have no time now to check all this out, so the error message and/or stack trace would be good.
--
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: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
Re: [PR] Convert more classes to record classes [lucene]
Posted by "shubhamvishu (via GitHub)" <gi...@apache.org>.
shubhamvishu commented on code in PR #13328:
URL: https://github.com/apache/lucene/pull/13328#discussion_r1584391143
##########
lucene/core/src/java/org/apache/lucene/codecs/TermStats.java:
##########
@@ -16,24 +16,10 @@
*/
package org.apache.lucene.codecs;
-import org.apache.lucene.index.TermsEnum; // javadocs
-
/**
* Holder for per-term statistics.
*
- * @see TermsEnum#docFreq
- * @see TermsEnum#totalTermFreq
+ * @param docFreq How many documents have at least one occurrence of this term.
+ * @param totalTermFreq Total number of times this term occurs across all documents in the field.
*/
-public class TermStats {
- /** How many documents have at least one occurrence of this term. */
- public final int docFreq;
-
- /** Total number of times this term occurs across all documents in the field. */
- public final long totalTermFreq;
-
- /** Sole constructor. */
- public TermStats(int docFreq, long totalTermFreq) {
- this.docFreq = docFreq;
- this.totalTermFreq = totalTermFreq;
- }
-}
+public record TermStats(int docFreq, long totalTermFreq) {}
Review Comment:
Thank you so much for looking into this @uschindler! I like the idea of having a quick fix and exclude the records ctor and methods for now. Also, I even tried to somehow get rid of the earlier issues with records `TermStats` and `ReaderSlice` but explicitly declaring the ctor and methods but it then started complaining about some other public records we added in this PR from the list of packages you shared above where we always expect javadocs. Disabling the check for records till its fixed in a separate issue makes sense to me.💯
--
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: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
Re: [PR] Convert more classes to record classes [lucene]
Posted by "uschindler (via GitHub)" <gi...@apache.org>.
uschindler commented on code in PR #13328:
URL: https://github.com/apache/lucene/pull/13328#discussion_r1752842660
##########
lucene/sandbox/src/java/org/apache/lucene/sandbox/search/CombinedFieldQuery.java:
##########
@@ -163,11 +156,6 @@ public boolean equals(Object o) {
FieldAndWeight that = (FieldAndWeight) o;
return Float.compare(that.weight, weight) == 0 && Objects.equals(field, that.field);
}
Review Comment:
Hi,
The equals methods for floats is generated by invokedynamic using a helper. When a record component is a float, the autogenerated impl is generated at runtime as combination of several Method handles. It compares them using this code:
https://github.com/openjdk/jdk/blob/9785e19f3f87306cabc26a862d35b89d41cfef93/src/java.base/share/classes/java/lang/runtime/ObjectMethods.java#L157
This is equivalent to the already existing code. So please remove all custom equals methods.
Unfortunately in the merged PR there are so one more. I will add a not on them. Please remove them in a followup.
--
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: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
Re: [PR] Convert more classes to record classes [lucene]
Posted by "uschindler (via GitHub)" <gi...@apache.org>.
uschindler commented on code in PR #13328:
URL: https://github.com/apache/lucene/pull/13328#discussion_r1584264324
##########
lucene/core/src/java/org/apache/lucene/codecs/TermStats.java:
##########
@@ -16,24 +16,10 @@
*/
package org.apache.lucene.codecs;
-import org.apache.lucene.index.TermsEnum; // javadocs
-
/**
* Holder for per-term statistics.
*
- * @see TermsEnum#docFreq
- * @see TermsEnum#totalTermFreq
+ * @param docFreq How many documents have at least one occurrence of this term.
+ * @param totalTermFreq Total number of times this term occurs across all documents in the field.
*/
-public class TermStats {
- /** How many documents have at least one occurrence of this term. */
- public final int docFreq;
-
- /** Total number of times this term occurs across all documents in the field. */
- public final long totalTermFreq;
-
- /** Sole constructor. */
- public TermStats(int docFreq, long totalTermFreq) {
- this.docFreq = docFreq;
- this.totalTermFreq = totalTermFreq;
- }
-}
+public record TermStats(int docFreq, long totalTermFreq) {}
Review Comment:
The fix should be a separate PR, as this is too large. Maybe we do some small PR first with only the TermStats class and make it pass the tester. Would this be OK to you? I will help to fix the linter.
--
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: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
Re: [PR] Convert more classes to record classes [lucene]
Posted by "uschindler (via GitHub)" <gi...@apache.org>.
uschindler commented on code in PR #13328:
URL: https://github.com/apache/lucene/pull/13328#discussion_r1585147534
##########
lucene/core/src/java/org/apache/lucene/util/TermAndVector.java:
##########
@@ -24,23 +24,7 @@
*
* @lucene.experimental
*/
-public class TermAndVector {
-
- private final BytesRef term;
- private final float[] vector;
-
- public TermAndVector(BytesRef term, float[] vector) {
- this.term = term;
- this.vector = vector;
- }
-
- public BytesRef getTerm() {
- return this.term;
- }
-
- public float[] getVector() {
- return this.vector;
- }
+public record TermAndVector(BytesRef term, float[] vector) {
Review Comment:
this class has the problem that it supplies a method to normalize the inner vector. This is against immutability of records. It is possible to do this, but feels bad.
--
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: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
Re: [PR] Convert more classes to record classes [lucene]
Posted by "shubhamvishu (via GitHub)" <gi...@apache.org>.
shubhamvishu commented on code in PR #13328:
URL: https://github.com/apache/lucene/pull/13328#discussion_r1586937485
##########
lucene/core/src/java/org/apache/lucene/util/TermAndVector.java:
##########
@@ -24,23 +24,7 @@
*
* @lucene.experimental
*/
-public class TermAndVector {
-
- private final BytesRef term;
- private final float[] vector;
-
- public TermAndVector(BytesRef term, float[] vector) {
- this.term = term;
- this.vector = vector;
- }
-
- public BytesRef getTerm() {
- return this.term;
- }
-
- public float[] getVector() {
- return this.vector;
- }
+public record TermAndVector(BytesRef term, float[] vector) {
Review Comment:
Makes sense! I changed it back to a class in the new revision
--
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: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
Re: [PR] Convert more classes to record classes [lucene]
Posted by "shubhamvishu (via GitHub)" <gi...@apache.org>.
shubhamvishu commented on code in PR #13328:
URL: https://github.com/apache/lucene/pull/13328#discussion_r1623688659
##########
lucene/core/src/java/org/apache/lucene/document/NearestNeighbor.java:
##########
@@ -34,20 +34,16 @@
/** KNN search on top of 2D lat/lon indexed points. */
class NearestNeighbor {
- static class Cell implements Comparable<Cell> {
- final int readerIndex;
- final byte[] minPacked;
- final byte[] maxPacked;
- final PointTree index;
-
- /**
- * The closest distance from a point in this cell to the query point, computed as a sort key
- * through {@link SloppyMath#haversinSortKey}. Note that this is an approximation to the closest
- * distance, and there could be a point in the cell that is closer.
- */
- final double distanceSortKey;
-
- public Cell(
+ /**
+ * @param distanceSortKey The closest distance from a point in this cell to the query point,
+ * computed as a sort key through {@link SloppyMath#haversinSortKey}. Note that this is an
+ * approximation to the closest distance, and there could be a point in the cell that is
+ * closer.
+ */
+ record Cell(
+ PointTree index, int readerIndex, byte[] minPacked, byte[] maxPacked, double distanceSortKey)
+ implements Comparable<Cell> {
+ Cell(
Review Comment:
done
--
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: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
Re: [PR] Convert more classes to record classes [lucene]
Posted by "shubhamvishu (via GitHub)" <gi...@apache.org>.
shubhamvishu commented on code in PR #13328:
URL: https://github.com/apache/lucene/pull/13328#discussion_r1623687790
##########
lucene/analysis/common/src/java/org/apache/lucene/analysis/hunspell/GeneratingSuggester.java:
##########
@@ -447,14 +446,8 @@ private static int commonCharacterPositionScore(String s1, String s2) {
return commonScore;
}
- private static class Weighted<T extends Comparable<T>> implements Comparable<Weighted<T>> {
- final T word;
- final int score;
-
- Weighted(T word, int score) {
- this.word = word;
- this.score = score;
- }
+ private record Weighted<T extends Comparable<T>>(T word, int score)
+ implements Comparable<Weighted<T>> {
@Override
public boolean equals(Object o) {
Review Comment:
Removed
--
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: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
Re: [PR] Convert more classes to record classes [lucene]
Posted by "shubhamvishu (via GitHub)" <gi...@apache.org>.
shubhamvishu commented on code in PR #13328:
URL: https://github.com/apache/lucene/pull/13328#discussion_r1584467051
##########
lucene/core/src/java/org/apache/lucene/codecs/TermStats.java:
##########
@@ -16,24 +16,10 @@
*/
package org.apache.lucene.codecs;
-import org.apache.lucene.index.TermsEnum; // javadocs
-
/**
* Holder for per-term statistics.
*
- * @see TermsEnum#docFreq
- * @see TermsEnum#totalTermFreq
+ * @param docFreq How many documents have at least one occurrence of this term.
+ * @param totalTermFreq Total number of times this term occurs across all documents in the field.
*/
-public class TermStats {
- /** How many documents have at least one occurrence of this term. */
- public final int docFreq;
-
- /** Total number of times this term occurs across all documents in the field. */
- public final long totalTermFreq;
-
- /** Sole constructor. */
- public TermStats(int docFreq, long totalTermFreq) {
- this.docFreq = docFreq;
- this.totalTermFreq = totalTermFreq;
- }
-}
+public record TermStats(int docFreq, long totalTermFreq) {}
Review Comment:
I opened #13329 with above quickfix change to temporarily disable the javadoc checks and confirmed the tasks passes for this PR with that change.
--
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: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
Re: [PR] Convert more classes to record classes [lucene]
Posted by "uschindler (via GitHub)" <gi...@apache.org>.
uschindler commented on code in PR #13328:
URL: https://github.com/apache/lucene/pull/13328#discussion_r1584262673
##########
lucene/core/src/java/org/apache/lucene/codecs/TermStats.java:
##########
@@ -16,24 +16,10 @@
*/
package org.apache.lucene.codecs;
-import org.apache.lucene.index.TermsEnum; // javadocs
-
/**
* Holder for per-term statistics.
*
- * @see TermsEnum#docFreq
- * @see TermsEnum#totalTermFreq
+ * @param docFreq How many documents have at least one occurrence of this term.
+ * @param totalTermFreq Total number of times this term occurs across all documents in the field.
*/
-public class TermStats {
- /** How many documents have at least one occurrence of this term. */
- public final int docFreq;
-
- /** Total number of times this term occurs across all documents in the field. */
- public final long totalTermFreq;
-
- /** Sole constructor. */
- public TermStats(int docFreq, long totalTermFreq) {
- this.docFreq = docFreq;
- this.totalTermFreq = totalTermFreq;
- }
-}
+public record TermStats(int docFreq, long totalTermFreq) {}
Review Comment:
Hi,
I know where this comes from: https://github.com/apache/lucene/blob/9af3ef8952597ead37a5a9ce5373ed3bbd40238e/gradle/documentation/render-javadoc.gradle#L196-L218
Actually for the codecs package we require javadocs for all methods, but not for the utils package.
The problem here is that it complains about synthetic methods. Let me play around with that a bit later. For enums the missing doclets checker has some code, i think thats exactly the same problem here. Maybe we can fix it in the same way like for synthetic methods and constructors of enums.
--
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: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
Re: [PR] Convert more classes to record classes [lucene]
Posted by "uschindler (via GitHub)" <gi...@apache.org>.
uschindler commented on PR #13328:
URL: https://github.com/apache/lucene/pull/13328#issuecomment-2091805740
Thanks, looks fine. I have no time to do another closer review, please give me some time to proceed.
--
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: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
Re: [PR] Convert more classes to record classes [lucene]
Posted by "shubhamvishu (via GitHub)" <gi...@apache.org>.
shubhamvishu commented on code in PR #13328:
URL: https://github.com/apache/lucene/pull/13328#discussion_r1623688408
##########
lucene/codecs/src/java/org/apache/lucene/codecs/blocktreeords/OrdsBlockTreeTermsWriter.java:
##########
@@ -139,18 +139,17 @@ public final class OrdsBlockTreeTermsWriter extends FieldsConsumer {
final PostingsWriterBase postingsWriter;
final FieldInfos fieldInfos;
- private static class FieldMetaData {
- public final FieldInfo fieldInfo;
- public final Output rootCode;
- public final long numTerms;
- public final long indexStartFP;
- public final long sumTotalTermFreq;
- public final long sumDocFreq;
- public final int docCount;
- public final BytesRef minTerm;
- public final BytesRef maxTerm;
-
- public FieldMetaData(
+ private record FieldMetaData(
Review Comment:
addressed in the new revision
--
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: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
Re: [PR] Convert more classes to record classes [lucene]
Posted by "uschindler (via GitHub)" <gi...@apache.org>.
uschindler commented on code in PR #13328:
URL: https://github.com/apache/lucene/pull/13328#discussion_r1752895892
##########
lucene/core/src/java/org/apache/lucene/search/MaxScoreAccumulator.java:
##########
@@ -101,11 +93,6 @@ public boolean equals(Object o) {
return docBase == result.docBase && Float.compare(result.score, score) == 0;
}
- @Override
Review Comment:
To string is also useless here. Please remove, too
--
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: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
Re: [PR] Convert more classes to record classes [lucene]
Posted by "uschindler (via GitHub)" <gi...@apache.org>.
uschindler commented on code in PR #13328:
URL: https://github.com/apache/lucene/pull/13328#discussion_r1584223935
##########
lucene/core/src/java/org/apache/lucene/codecs/TermStats.java:
##########
@@ -16,24 +16,10 @@
*/
package org.apache.lucene.codecs;
-import org.apache.lucene.index.TermsEnum; // javadocs
-
/**
* Holder for per-term statistics.
*
- * @see TermsEnum#docFreq
- * @see TermsEnum#totalTermFreq
+ * @param docFreq How many documents have at least one occurrence of this term.
+ * @param totalTermFreq Total number of times this term occurs across all documents in the field.
*/
-public class TermStats {
- /** How many documents have at least one occurrence of this term. */
- public final int docFreq;
-
- /** Total number of times this term occurs across all documents in the field. */
- public final long totalTermFreq;
-
- /** Sole constructor. */
- public TermStats(int docFreq, long totalTermFreq) {
- this.docFreq = docFreq;
- this.totalTermFreq = totalTermFreq;
- }
-}
+public record TermStats(int docFreq, long totalTermFreq) {}
Review Comment:
oh it is a top-level class. no idea whats wrong!
--
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: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
Re: [PR] Convert more classes to record classes [lucene]
Posted by "uschindler (via GitHub)" <gi...@apache.org>.
uschindler commented on PR #13328:
URL: https://github.com/apache/lucene/pull/13328#issuecomment-2085780025
Hi, you can merge main into your branch and hopefully checks pass. For some packages like the "codecs" one the new code requires you to also document all record components with `@param`.
--
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: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
Re: [PR] Convert more classes to record classes [lucene]
Posted by "shubhamvishu (via GitHub)" <gi...@apache.org>.
shubhamvishu commented on code in PR #13328:
URL: https://github.com/apache/lucene/pull/13328#discussion_r1584056472
##########
lucene/core/src/java/org/apache/lucene/codecs/TermStats.java:
##########
@@ -16,24 +16,10 @@
*/
package org.apache.lucene.codecs;
-import org.apache.lucene.index.TermsEnum; // javadocs
-
/**
* Holder for per-term statistics.
*
- * @see TermsEnum#docFreq
- * @see TermsEnum#totalTermFreq
+ * @param docFreq How many documents have at least one occurrence of this term.
+ * @param totalTermFreq Total number of times this term occurs across all documents in the field.
*/
-public class TermStats {
- /** How many documents have at least one occurrence of this term. */
- public final int docFreq;
-
- /** Total number of times this term occurs across all documents in the field. */
- public final long totalTermFreq;
-
- /** Sole constructor. */
- public TermStats(int docFreq, long totalTermFreq) {
- this.docFreq = docFreq;
- this.totalTermFreq = totalTermFreq;
- }
-}
+public record TermStats(int docFreq, long totalTermFreq) {}
Review Comment:
The `renderJavaDoc` fails for this even though java docs are present. If I see earlier PR #13205 that moved some classes I don't see it failing for such classes. If this is not expected, then maybe we need to fix something in `MissingDoclet.java`?(not sure).
cc - @uschindler
--
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: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
Re: [PR] Convert more classes to record classes [lucene]
Posted by "shubhamvishu (via GitHub)" <gi...@apache.org>.
shubhamvishu commented on PR #13328:
URL: https://github.com/apache/lucene/pull/13328#issuecomment-2209345556
Hi @uschindler, Could you please review the current code changes once you get some time and if it looks good maybe we can move this forward?
--
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: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
Re: [PR] Convert more classes to record classes [lucene]
Posted by "jpountz (via GitHub)" <gi...@apache.org>.
jpountz commented on PR #13328:
URL: https://github.com/apache/lucene/pull/13328#issuecomment-2342059732
@javanna just fixed it, thanks @javanna !
--
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: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
Re: [PR] Convert more classes to record classes [lucene]
Posted by "shubhamvishu (via GitHub)" <gi...@apache.org>.
shubhamvishu commented on code in PR #13328:
URL: https://github.com/apache/lucene/pull/13328#discussion_r1755293825
##########
lucene/core/src/java/org/apache/lucene/search/MaxScoreAccumulator.java:
##########
@@ -101,11 +93,6 @@ public boolean equals(Object o) {
return docBase == result.docBase && Float.compare(result.score, score) == 0;
}
- @Override
Review Comment:
I opened a followup PR #13769. Thanks!
--
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: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
Re: [PR] Convert more classes to record classes [lucene]
Posted by "shubhamvishu (via GitHub)" <gi...@apache.org>.
shubhamvishu commented on PR #13328:
URL: https://github.com/apache/lucene/pull/13328#issuecomment-2338611763
Hi @uschindler @mikemccand @jpountz , I fixed the recent merge conflicts and looking for reviews as 10.0 release is blocked on this change. This PR has been attracting merge conflicts frequently since its touching 200+ files, so hoping we could close this sooner. Let me know if there is any concerns here(I'm up for quick followups). Thanks!
--
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: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
Re: [PR] Convert more classes to record classes [lucene]
Posted by "uschindler (via GitHub)" <gi...@apache.org>.
uschindler commented on code in PR #13328:
URL: https://github.com/apache/lucene/pull/13328#discussion_r1585004047
##########
lucene/core/src/java/org/apache/lucene/codecs/TermStats.java:
##########
@@ -16,24 +16,10 @@
*/
package org.apache.lucene.codecs;
-import org.apache.lucene.index.TermsEnum; // javadocs
-
/**
* Holder for per-term statistics.
*
- * @see TermsEnum#docFreq
- * @see TermsEnum#totalTermFreq
+ * @param docFreq How many documents have at least one occurrence of this term.
+ * @param totalTermFreq Total number of times this term occurs across all documents in the field.
*/
-public class TermStats {
- /** How many documents have at least one occurrence of this term. */
- public final int docFreq;
-
- /** Total number of times this term occurs across all documents in the field. */
- public final long totalTermFreq;
-
- /** Sole constructor. */
- public TermStats(int docFreq, long totalTermFreq) {
- this.docFreq = docFreq;
- this.totalTermFreq = totalTermFreq;
- }
-}
+public record TermStats(int docFreq, long totalTermFreq) {}
Review Comment:
I fixed the issue and added support for records and also its components (as `@param`) in the missing doclet linter: #13332
Once this is merged we can update this PR.
--
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: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
Re: [PR] Convert more classes to record classes [lucene]
Posted by "uschindler (via GitHub)" <gi...@apache.org>.
uschindler commented on code in PR #13328:
URL: https://github.com/apache/lucene/pull/13328#discussion_r1585152280
##########
lucene/core/src/java/org/apache/lucene/util/packed/PackedInts.java:
##########
@@ -171,14 +171,7 @@ public final float overheadRatio(int bitsPerValue) {
}
/** Simple class that holds a format and a number of bits per value. */
- public static class FormatAndBits {
- public final Format format;
- public final int bitsPerValue;
-
- public FormatAndBits(Format format, int bitsPerValue) {
- this.format = format;
- this.bitsPerValue = bitsPerValue;
- }
+ public record FormatAndBits(Format format, int bitsPerValue) {
@Override
public String toString() {
Review Comment:
do we need toString(), this one can be autogenerated, just the output is different.
--
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: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
Re: [PR] Convert more classes to record classes [lucene]
Posted by "uschindler (via GitHub)" <gi...@apache.org>.
uschindler commented on code in PR #13328:
URL: https://github.com/apache/lucene/pull/13328#discussion_r1584267265
##########
lucene/core/src/java/org/apache/lucene/codecs/TermStats.java:
##########
@@ -16,24 +16,10 @@
*/
package org.apache.lucene.codecs;
-import org.apache.lucene.index.TermsEnum; // javadocs
-
/**
* Holder for per-term statistics.
*
- * @see TermsEnum#docFreq
- * @see TermsEnum#totalTermFreq
+ * @param docFreq How many documents have at least one occurrence of this term.
+ * @param totalTermFreq Total number of times this term occurs across all documents in the field.
*/
-public class TermStats {
- /** How many documents have at least one occurrence of this term. */
- public final int docFreq;
-
- /** Total number of times this term occurs across all documents in the field. */
- public final long totalTermFreq;
-
- /** Sole constructor. */
- public TermStats(int docFreq, long totalTermFreq) {
- this.docFreq = docFreq;
- this.totalTermFreq = totalTermFreq;
- }
-}
+public record TermStats(int docFreq, long totalTermFreq) {}
Review Comment:
I think the fix needs to be done here: https://github.com/apache/lucene/blob/9af3ef8952597ead37a5a9ce5373ed3bbd40238e/dev-tools/missing-doclet/src/main/java/org/apache/lucene/missingdoclet/MissingDoclet.java#L260
The problem is: how to know which of the ctors and methods are not synthetic?
--
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: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
Re: [PR] Convert more classes to record classes [lucene]
Posted by "uschindler (via GitHub)" <gi...@apache.org>.
uschindler commented on code in PR #13328:
URL: https://github.com/apache/lucene/pull/13328#discussion_r1584314019
##########
lucene/core/src/java/org/apache/lucene/codecs/TermStats.java:
##########
@@ -16,24 +16,10 @@
*/
package org.apache.lucene.codecs;
-import org.apache.lucene.index.TermsEnum; // javadocs
-
/**
* Holder for per-term statistics.
*
- * @see TermsEnum#docFreq
- * @see TermsEnum#totalTermFreq
+ * @param docFreq How many documents have at least one occurrence of this term.
+ * @param totalTermFreq Total number of times this term occurs across all documents in the field.
*/
-public class TermStats {
- /** How many documents have at least one occurrence of this term. */
- public final int docFreq;
-
- /** Total number of times this term occurs across all documents in the field. */
- public final long totalTermFreq;
-
- /** Sole constructor. */
- public TermStats(int docFreq, long totalTermFreq) {
- this.docFreq = docFreq;
- this.totalTermFreq = totalTermFreq;
- }
-}
+public record TermStats(int docFreq, long totalTermFreq) {}
Review Comment:
Maybe as a quick fix we can exclude analysis of record ctors and methods until we have a fix for that. Let's rename that method to `isSyntheticMethod` (remove "enum" from name):
https://github.com/apache/lucene/blob/9af3ef8952597ead37a5a9ce5373ed3bbd40238e/dev-tools/missing-doclet/src/main/java/org/apache/lucene/missingdoclet/MissingDoclet.java#L274-L282
and modify it:
```java
private boolean isSyntheticMethod(Element element) {
if (element.getEnclosingElement().getKind() == ElementKind.RECORD) {
// TODO: fix this to exclude autogenerated accessors and ctors of records, which is hard
return true;
}
String simpleName = element.getSimpleName().toString();
if (simpleName.equals("values") || simpleName.equals("valueOf")) {
if (element.getEnclosingElement().getKind() == ElementKind.ENUM) {
return true;
}
}
return false;
}
```
--
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: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
Re: [PR] Convert more classes to record classes [lucene]
Posted by "shubhamvishu (via GitHub)" <gi...@apache.org>.
shubhamvishu commented on code in PR #13328:
URL: https://github.com/apache/lucene/pull/13328#discussion_r1586937659
##########
lucene/core/src/java/org/apache/lucene/util/packed/PackedInts.java:
##########
@@ -171,14 +171,7 @@ public final float overheadRatio(int bitsPerValue) {
}
/** Simple class that holds a format and a number of bits per value. */
- public static class FormatAndBits {
- public final Format format;
- public final int bitsPerValue;
-
- public FormatAndBits(Format format, int bitsPerValue) {
- this.format = format;
- this.bitsPerValue = bitsPerValue;
- }
+ public record FormatAndBits(Format format, int bitsPerValue) {
@Override
public String toString() {
Review Comment:
Removed this now
--
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: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
Re: [PR] Convert more classes to record classes [lucene]
Posted by "shubhamvishu (via GitHub)" <gi...@apache.org>.
shubhamvishu commented on code in PR #13328:
URL: https://github.com/apache/lucene/pull/13328#discussion_r1586937485
##########
lucene/core/src/java/org/apache/lucene/util/TermAndVector.java:
##########
@@ -24,23 +24,7 @@
*
* @lucene.experimental
*/
-public class TermAndVector {
-
- private final BytesRef term;
- private final float[] vector;
-
- public TermAndVector(BytesRef term, float[] vector) {
- this.term = term;
- this.vector = vector;
- }
-
- public BytesRef getTerm() {
- return this.term;
- }
-
- public float[] getVector() {
- return this.vector;
- }
+public record TermAndVector(BytesRef term, float[] vector) {
Review Comment:
Makes sense! I changed it back to class in the new revision
--
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: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
Re: [PR] Convert more classes to record classes [lucene]
Posted by "shubhamvishu (via GitHub)" <gi...@apache.org>.
shubhamvishu commented on code in PR #13328:
URL: https://github.com/apache/lucene/pull/13328#discussion_r1586937857
##########
lucene/core/src/java/org/apache/lucene/search/CollectionStatistics.java:
##########
@@ -116,7 +105,8 @@ public CollectionStatistics(
*
* @return field's name, not {@code null}
*/
- public final String field() {
Review Comment:
Done! I also changed some more records I could find to be as leaner as possible.
--
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: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
Re: [PR] Convert more classes to record classes [lucene]
Posted by "uschindler (via GitHub)" <gi...@apache.org>.
uschindler commented on code in PR #13328:
URL: https://github.com/apache/lucene/pull/13328#discussion_r1585133751
##########
lucene/core/src/java/org/apache/lucene/codecs/TermStats.java:
##########
@@ -16,24 +16,10 @@
*/
package org.apache.lucene.codecs;
-import org.apache.lucene.index.TermsEnum; // javadocs
-
/**
* Holder for per-term statistics.
*
- * @see TermsEnum#docFreq
- * @see TermsEnum#totalTermFreq
+ * @param docFreq How many documents have at least one occurrence of this term.
+ * @param totalTermFreq Total number of times this term occurs across all documents in the field.
*/
-public class TermStats {
- /** How many documents have at least one occurrence of this term. */
- public final int docFreq;
-
- /** Total number of times this term occurs across all documents in the field. */
- public final long totalTermFreq;
-
- /** Sole constructor. */
- public TermStats(int docFreq, long totalTermFreq) {
- this.docFreq = docFreq;
- this.totalTermFreq = totalTermFreq;
- }
-}
+public record TermStats(int docFreq, long totalTermFreq) {}
Review Comment:
It's merged and you can update this branch.
--
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: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
Re: [PR] Convert more classes to record classes [lucene]
Posted by "uschindler (via GitHub)" <gi...@apache.org>.
uschindler commented on code in PR #13328:
URL: https://github.com/apache/lucene/pull/13328#discussion_r1752842660
##########
lucene/sandbox/src/java/org/apache/lucene/sandbox/search/CombinedFieldQuery.java:
##########
@@ -163,11 +156,6 @@ public boolean equals(Object o) {
FieldAndWeight that = (FieldAndWeight) o;
return Float.compare(that.weight, weight) == 0 && Objects.equals(field, that.field);
}
Review Comment:
Hi,
The equals methods for floats is generated by invokedynamic at runtime using a bootstrapping:
https://github.com/openjdk/jdk/blob/9785e19f3f87306cabc26a862d35b89d41cfef93/src/java.base/share/classes/java/lang/runtime/ObjectMethods.java#L382
The class file of a record only contains a stub equals/hashcode/to string which delegates to an invokedynamic call passing the class which allows the bootstrapped to get all record components and construct a method handle for the whole method implementation.
When a record component is a float, the autogenerated impl is generated at runtime as combination of several Method handles. It compares them using this code:
https://github.com/openjdk/jdk/blob/9785e19f3f87306cabc26a862d35b89d41cfef93/src/java.base/share/classes/java/lang/runtime/ObjectMethods.java#L157
The method handles used by the code generator are saved in a map:
https://github.com/openjdk/jdk/blob/9785e19f3f87306cabc26a862d35b89d41cfef93/src/java.base/share/classes/java/lang/runtime/ObjectMethods.java#L101
This is equivalent to the already existing code. So please remove all custom equals methods.
Unfortunately in the merged PR there are some more. Please remove them in a followup.
--
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: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
Re: [PR] Convert more classes to record classes [lucene]
Posted by "mikemccand (via GitHub)" <gi...@apache.org>.
mikemccand commented on code in PR #13328:
URL: https://github.com/apache/lucene/pull/13328#discussion_r1752005115
##########
lucene/sandbox/src/java/org/apache/lucene/sandbox/search/CombinedFieldQuery.java:
##########
@@ -163,11 +156,6 @@ public boolean equals(Object o) {
FieldAndWeight that = (FieldAndWeight) o;
return Float.compare(that.weight, weight) == 0 && Objects.equals(field, that.field);
}
Review Comment:
> (I tried to quickly look up what record does wrt equality for floats and doubles but couldn't find it, will look later)
I found one mention of floating point numbers in the [JEP for records](https://openjdk.org/jeps/395):
```
In addition, for all record classes the implicitly declared equals method is implemented so that it is reflexive and that it behaves consistently with hashCode for record classes that have floating point components. Again, explicitly declared equals and hashCode methods should behave similarly.
```
I'm not sure I understand that paragraph :)
##########
lucene/MIGRATE.md:
##########
@@ -193,6 +193,7 @@ access the members using method calls instead of field accesses. Affected classe
- `IOContext`, `MergeInfo`, and `FlushInfo` (GITHUB#13205)
- `BooleanClause` (GITHUB#13261)
+- `CollectionStatistics`, `TermStatistics` and `LeafMetadata` (GITHUB#13328)
Review Comment:
And maybe change this wording too (same as `CHANGES.txt`)? I think @jpountz asked for `TopDocs` to also be mentioned?
##########
lucene/CHANGES.txt:
##########
@@ -118,6 +118,8 @@ API Changes
argument with a `FacetsCollectorManager` and update the return type to include both `TopDocs` results as well as
facets results. (Luca Cavanna)
+* GITHUB#13328: Convert CollectionStatistics, TermStatistics and LeafMetadata etc. to record classes. (Shubham Chaudhary)
Review Comment:
Maybe reword to `Convert many basic Lucene classes to record classes, including X, Y, and Z`? It's not just these three classes, if I'm reading the PR correctly, and the `etc.` should not have so much power ;)
--
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: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
Re: [PR] Convert more classes to record classes [lucene]
Posted by "shubhamvishu (via GitHub)" <gi...@apache.org>.
shubhamvishu commented on code in PR #13328:
URL: https://github.com/apache/lucene/pull/13328#discussion_r1753129302
##########
lucene/sandbox/src/java/org/apache/lucene/sandbox/search/CombinedFieldQuery.java:
##########
@@ -163,11 +156,6 @@ public boolean equals(Object o) {
FieldAndWeight that = (FieldAndWeight) o;
return Float.compare(that.weight, weight) == 0 && Objects.equals(field, that.field);
}
Review Comment:
Nice! I'll check and followup with removing others I could find.
--
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: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
Re: [PR] Convert more classes to record classes [lucene]
Posted by "jpountz (via GitHub)" <gi...@apache.org>.
jpountz merged PR #13328:
URL: https://github.com/apache/lucene/pull/13328
--
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: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
Re: [PR] Convert more classes to record classes [lucene]
Posted by "shubhamvishu (via GitHub)" <gi...@apache.org>.
shubhamvishu commented on code in PR #13328:
URL: https://github.com/apache/lucene/pull/13328#discussion_r1623688124
##########
lucene/analysis/common/src/java/org/apache/lucene/analysis/synonym/word2vec/TermAndBoost.java:
##########
@@ -18,14 +18,13 @@
import org.apache.lucene.util.BytesRef;
-/** Wraps a term and boost */
-public class TermAndBoost {
- /** the term */
- public final BytesRef term;
-
- /** the boost */
- public final float boost;
-
+/**
+ * Wraps a term and boost
+ *
+ * @param term the term
+ * @param boost the boost
+ */
+public record TermAndBoost(BytesRef term, float boost) {
/** Creates a new TermAndBoost */
public TermAndBoost(BytesRef term, float boost) {
Review Comment:
Done!.....I changed others such occurrences that I could find as well
--
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: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
Re: [PR] Convert more classes to record classes [lucene]
Posted by "uschindler (via GitHub)" <gi...@apache.org>.
uschindler commented on PR #13328:
URL: https://github.com/apache/lucene/pull/13328#issuecomment-2118884788
Hi @shubhamvishu,
can you check my comments? The changes here look fine, please fix the remaining issues.
Uwe
--
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: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
Re: [PR] Convert more classes to record classes [lucene]
Posted by "shubhamvishu (via GitHub)" <gi...@apache.org>.
shubhamvishu commented on code in PR #13328:
URL: https://github.com/apache/lucene/pull/13328#discussion_r1623687790
##########
lucene/analysis/common/src/java/org/apache/lucene/analysis/hunspell/GeneratingSuggester.java:
##########
@@ -447,14 +446,8 @@ private static int commonCharacterPositionScore(String s1, String s2) {
return commonScore;
}
- private static class Weighted<T extends Comparable<T>> implements Comparable<Weighted<T>> {
- final T word;
- final int score;
-
- Weighted(T word, int score) {
- this.word = word;
- this.score = score;
- }
+ private record Weighted<T extends Comparable<T>>(T word, int score)
+ implements Comparable<Weighted<T>> {
@Override
public boolean equals(Object o) {
Review Comment:
Removed
--
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: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
Re: [PR] Convert more classes to record classes [lucene]
Posted by "shubhamvishu (via GitHub)" <gi...@apache.org>.
shubhamvishu commented on code in PR #13328:
URL: https://github.com/apache/lucene/pull/13328#discussion_r1584249124
##########
lucene/core/src/java/org/apache/lucene/codecs/TermStats.java:
##########
@@ -16,24 +16,10 @@
*/
package org.apache.lucene.codecs;
-import org.apache.lucene.index.TermsEnum; // javadocs
-
/**
* Holder for per-term statistics.
*
- * @see TermsEnum#docFreq
- * @see TermsEnum#totalTermFreq
+ * @param docFreq How many documents have at least one occurrence of this term.
+ * @param totalTermFreq Total number of times this term occurs across all documents in the field.
*/
-public class TermStats {
- /** How many documents have at least one occurrence of this term. */
- public final int docFreq;
-
- /** Total number of times this term occurs across all documents in the field. */
- public final long totalTermFreq;
-
- /** Sole constructor. */
- public TermStats(int docFreq, long totalTermFreq) {
- this.docFreq = docFreq;
- this.totalTermFreq = totalTermFreq;
- }
-}
+public record TermStats(int docFreq, long totalTermFreq) {}
Review Comment:
Here is what the failure message looks like :
```
> Task :lucene:core:renderSiteJavadoc
/home/runner/work/lucene/lucene/lucene/core/src/java/org/apache/lucene/codecs/TermStats.java:25: error: TermStats.<init> (constructor): javadocs are missing
public record TermStats(int docFreq, long totalTermFreq) {}
^
error: TermStats.docFreq (method): javadocs are missing
error: TermStats.totalTermFreq (method): javadocs are missing
/home/runner/work/lucene/lucene/lucene/core/src/java/org/apache/lucene/index/ReaderSlice.java:27: error: ReaderSlice.<init> (constructor): javadocs are missing
public record ReaderSlice(int start, int length, int readerIndex) {
^
error: ReaderSlice.start (method): javadocs are missing
error: ReaderSlice.length (method): javadocs are missing
error: ReaderSlice.readerIndex (method): javadocs are missing
```
--
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: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
Re: [PR] Convert more classes to record classes [lucene]
Posted by "shubhamvishu (via GitHub)" <gi...@apache.org>.
shubhamvishu commented on code in PR #13328:
URL: https://github.com/apache/lucene/pull/13328#discussion_r1584056472
##########
lucene/core/src/java/org/apache/lucene/codecs/TermStats.java:
##########
@@ -16,24 +16,10 @@
*/
package org.apache.lucene.codecs;
-import org.apache.lucene.index.TermsEnum; // javadocs
-
/**
* Holder for per-term statistics.
*
- * @see TermsEnum#docFreq
- * @see TermsEnum#totalTermFreq
+ * @param docFreq How many documents have at least one occurrence of this term.
+ * @param totalTermFreq Total number of times this term occurs across all documents in the field.
*/
-public class TermStats {
- /** How many documents have at least one occurrence of this term. */
- public final int docFreq;
-
- /** Total number of times this term occurs across all documents in the field. */
- public final long totalTermFreq;
-
- /** Sole constructor. */
- public TermStats(int docFreq, long totalTermFreq) {
- this.docFreq = docFreq;
- this.totalTermFreq = totalTermFreq;
- }
-}
+public record TermStats(int docFreq, long totalTermFreq) {}
Review Comment:
The `renderJavaDoc` fails for this even though java docs are present. If I see earlier PR #13205 that moved some classes I don't see it failing for such cases (eg : [FlushInfo](https://github.com/apache/lucene/pull/13205/files#diff-a1c80d9a8aa2cd33e8828902daa7089f350833dc8bf0a7f71e237937aaf323cb)). If this is not expected, then maybe we need to fix something in `MissingDoclet.java`?(not sure).
cc - @uschindler
--
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: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
Re: [PR] Convert more classes to record classes [lucene]
Posted by "uschindler (via GitHub)" <gi...@apache.org>.
uschindler commented on code in PR #13328:
URL: https://github.com/apache/lucene/pull/13328#discussion_r1585154771
##########
lucene/core/src/java/org/apache/lucene/search/CollectionStatistics.java:
##########
@@ -116,7 +105,8 @@ public CollectionStatistics(
*
* @return field's name, not {@code null}
*/
- public final String field() {
Review Comment:
we can remove all accessor methods and add the documentation into `@param` on the record declaration.
--
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: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
Re: [PR] Convert more classes to record classes [lucene]
Posted by "shubhamvishu (via GitHub)" <gi...@apache.org>.
shubhamvishu commented on PR #13328:
URL: https://github.com/apache/lucene/pull/13328#issuecomment-2089321284
I addressed your comments in the new revision and all the checks are passing now after your fix. Thanks!
--
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: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
Re: [PR] Convert more classes to record classes [lucene]
Posted by "uschindler (via GitHub)" <gi...@apache.org>.
uschindler commented on code in PR #13328:
URL: https://github.com/apache/lucene/pull/13328#discussion_r1752842660
##########
lucene/sandbox/src/java/org/apache/lucene/sandbox/search/CombinedFieldQuery.java:
##########
@@ -163,11 +156,6 @@ public boolean equals(Object o) {
FieldAndWeight that = (FieldAndWeight) o;
return Float.compare(that.weight, weight) == 0 && Objects.equals(field, that.field);
}
Review Comment:
Hi,
The equals methods for floats is generated by invokedynamic using a helper. When a record component is a float, the autogenerated impl is generated at runtime as combination of several Method handles. It compares them using this code:
https://github.com/openjdk/jdk/blob/9785e19f3f87306cabc26a862d35b89d41cfef93/src/java.base/share/classes/java/lang/runtime/ObjectMethods.java#L157
The method handles used by the code generator are saved in a map:
https://github.com/openjdk/jdk/blob/9785e19f3f87306cabc26a862d35b89d41cfef93/src/java.base/share/classes/java/lang/runtime/ObjectMethods.java#L101
This is equivalent to the already existing code. So please remove all custom equals methods.
Unfortunately in the merged PR there are some more. Please remove them in a followup.
--
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: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
Re: [PR] Convert more classes to record classes [lucene]
Posted by "uschindler (via GitHub)" <gi...@apache.org>.
uschindler commented on code in PR #13328:
URL: https://github.com/apache/lucene/pull/13328#discussion_r1752860507
##########
lucene/core/src/java/org/apache/lucene/search/MaxScoreAccumulator.java:
##########
@@ -101,11 +93,6 @@ public boolean equals(Object o) {
return docBase == result.docBase && Float.compare(result.score, score) == 0;
}
- @Override
Review Comment:
Please also remove the equals, see this comment: https://github.com/apache/lucene/pull/13328#discussion_r1752842660
--
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: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
Re: [PR] Convert more classes to record classes [lucene]
Posted by "stefanvodita (via GitHub)" <gi...@apache.org>.
stefanvodita commented on PR #13328:
URL: https://github.com/apache/lucene/pull/13328#issuecomment-2342037249
I think we've run into a conflict with #13689. @jpountz - should I fix that or are you already doing it?
--
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: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
Re: [PR] Convert more classes to record classes [lucene]
Posted by "shubhamvishu (via GitHub)" <gi...@apache.org>.
shubhamvishu commented on PR #13328:
URL: https://github.com/apache/lucene/pull/13328#issuecomment-2120851082
Hi @uschindler , sorry I was on vacation until last week, so this PR stalled. I'll take a look at the comments today or tomorrow.
--
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: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
Re: [PR] Convert more classes to record classes [lucene]
Posted by "stefanvodita (via GitHub)" <gi...@apache.org>.
stefanvodita commented on PR #13328:
URL: https://github.com/apache/lucene/pull/13328#issuecomment-2338478237
Added the blocker label to draw attention to this PR for the Lucene 10 release.
--
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: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
Re: [PR] Convert more classes to record classes [lucene]
Posted by "jpountz (via GitHub)" <gi...@apache.org>.
jpountz commented on code in PR #13328:
URL: https://github.com/apache/lucene/pull/13328#discussion_r1750630925
##########
lucene/monitor/src/java/org/apache/lucene/monitor/HighlightsMatch.java:
##########
@@ -180,47 +180,16 @@ void addHit(String field, int startPos, int endPos, int startOffset, int endOffs
hitSet.add(new Hit(startPos, startOffset, endPos, endOffset));
}
- /** Represents an individual hit */
- public static class Hit implements Comparable<Hit> {
-
- /** The start position */
- public final int startPosition;
-
- /** The start offset */
- public final int startOffset;
-
- /** The end positions */
- public final int endPosition;
-
- /** The end offset */
- public final int endOffset;
-
- public Hit(int startPosition, int startOffset, int endPosition, int endOffset) {
- this.startPosition = startPosition;
- this.startOffset = startOffset;
- this.endPosition = endPosition;
- this.endOffset = endOffset;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) return true;
- if (!(obj instanceof Hit)) return false;
- Hit other = (Hit) obj;
- return this.startOffset == other.startOffset
- && this.endOffset == other.endOffset
- && this.startPosition == other.startPosition
- && this.endPosition == other.endPosition;
- }
-
- @Override
- public int hashCode() {
- int result = startPosition;
- result = 31 * result + startOffset;
- result = 31 * result + endPosition;
- result = 31 * result + endOffset;
- return result;
- }
+ /**
+ * Represents an individual hit
+ *
+ * @param startPosition The start position
+ * @param startOffset The start offset
+ * @param endPosition The end positions
Review Comment:
```suggestion
* @param endPosition The end position
```
##########
lucene/core/src/java/org/apache/lucene/search/CollectionStatistics.java:
##########
@@ -17,8 +17,9 @@
package org.apache.lucene.search;
import java.util.Objects;
-import org.apache.lucene.index.IndexReader; // javadocs
-import org.apache.lucene.index.Terms; // javadocs
+
+// javadocs
+// javadocs
Review Comment:
you can remove these 2 comments
##########
lucene/test-framework/src/java/org/apache/lucene/tests/codecs/asserting/AssertingLiveDocsFormat.java:
##########
@@ -68,9 +68,7 @@ public String toString() {
return "Asserting(" + in + ")";
}
- static class AssertingBits implements Bits {
- final Bits in;
-
+ record AssertingBits(Bits in) implements Bits {
Review Comment:
While it's not incorrect, I'm not sure if this class fits my mental model for a record as it's more about behaviors than about packaging other objects tohether.
##########
lucene/sandbox/src/java/org/apache/lucene/sandbox/search/CombinedFieldQuery.java:
##########
@@ -163,11 +156,6 @@ public boolean equals(Object o) {
FieldAndWeight that = (FieldAndWeight) o;
return Float.compare(that.weight, weight) == 0 && Objects.equals(field, that.field);
}
Review Comment:
Did you note remove this equals override because the record would behave differently? (I tried to quickly look up what record does wrt equality for floats and doubles but couldn't find it, will look later)
##########
lucene/core/src/java/org/apache/lucene/util/FixedBits.java:
##########
@@ -17,15 +17,7 @@
package org.apache.lucene.util;
/** Immutable twin of FixedBitSet. */
-final class FixedBits implements Bits {
-
- final long[] bits;
- final int length;
-
- FixedBits(long[] bits, int length) {
- this.bits = bits;
- this.length = length;
- }
+record FixedBits(long[] bits, int length) implements Bits {
Review Comment:
it doesn't really fit my mental model for a record, maybe undo the refactoring on this class?
##########
lucene/test-framework/src/java/org/apache/lucene/tests/index/AssertingLeafReader.java:
##########
@@ -1357,15 +1357,8 @@ public int getDocCount() {
}
}
- static class AssertingPointTree implements PointValues.PointTree {
-
- final PointValues pointValues;
- final PointValues.PointTree in;
-
- AssertingPointTree(PointValues pointValues, PointValues.PointTree in) {
- this.pointValues = pointValues;
- this.in = in;
- }
+ record AssertingPointTree(PointValues pointValues, PointValues.PointTree in)
+ implements PointValues.PointTree {
Review Comment:
likewise: keep it a regular class?
##########
lucene/misc/src/java/org/apache/lucene/misc/util/fst/UpToTwoPositiveIntOutputs.java:
##########
@@ -42,36 +42,11 @@
public final class UpToTwoPositiveIntOutputs extends Outputs<Object> {
/** Holds two long outputs. */
- public static final class TwoLongs {
- public final long first;
- public final long second;
-
- public TwoLongs(long first, long second) {
- this.first = first;
- this.second = second;
+ public record TwoLongs(long first, long second) {
+ public TwoLongs {
assert first >= 0;
assert second >= 0;
}
-
- @Override
- public String toString() {
- return "TwoLongs:" + first + "," + second;
- }
Review Comment:
we'll get a different toString() but I think it's fine in this case
--
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: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
Re: [PR] Convert more classes to record classes [lucene]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #13328:
URL: https://github.com/apache/lucene/pull/13328#issuecomment-2237834830
This PR has not had activity in the past 2 weeks, labeling it as stale. If the PR is waiting for review, notify the dev@lucene.apache.org list. Thank you for your contribution!
--
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: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
Re: [PR] Convert more classes to record classes [lucene]
Posted by "shubhamvishu (via GitHub)" <gi...@apache.org>.
shubhamvishu commented on code in PR #13328:
URL: https://github.com/apache/lucene/pull/13328#discussion_r1751555877
##########
lucene/sandbox/src/java/org/apache/lucene/sandbox/search/CombinedFieldQuery.java:
##########
@@ -163,11 +156,6 @@ public boolean equals(Object o) {
FieldAndWeight that = (FieldAndWeight) o;
return Float.compare(that.weight, weight) == 0 && Objects.equals(field, that.field);
}
Review Comment:
Nope, I think its a leftover.I'll change it. Found similar one `TermAndBoost` in `SynonymQuery` also.
--
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: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
Re: [PR] Convert more classes to record classes [lucene]
Posted by "shubhamvishu (via GitHub)" <gi...@apache.org>.
shubhamvishu commented on code in PR #13328:
URL: https://github.com/apache/lucene/pull/13328#discussion_r1753134745
##########
lucene/core/src/java/org/apache/lucene/search/MaxScoreAccumulator.java:
##########
@@ -101,11 +93,6 @@ public boolean equals(Object o) {
return docBase == result.docBase && Float.compare(result.score, score) == 0;
}
- @Override
Review Comment:
Sure, I'll fix it in a followup PR. I could only find this instance in the classes changed to records where we have removable custom equals/toString but I'll take another pass to be sure.
--
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: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
Re: [PR] Convert more classes to record classes [lucene]
Posted by "shubhamvishu (via GitHub)" <gi...@apache.org>.
shubhamvishu commented on PR #13328:
URL: https://github.com/apache/lucene/pull/13328#issuecomment-2340172026
@jpountz I addressed your comments and added a CHANGES, MIGRATE entry now. Thanks for reviewing!
--
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: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
Re: [PR] Convert more classes to record classes [lucene]
Posted by "uschindler (via GitHub)" <gi...@apache.org>.
uschindler commented on code in PR #13328:
URL: https://github.com/apache/lucene/pull/13328#discussion_r1588461460
##########
lucene/analysis/common/src/java/org/apache/lucene/analysis/hunspell/GeneratingSuggester.java:
##########
@@ -447,14 +446,8 @@ private static int commonCharacterPositionScore(String s1, String s2) {
return commonScore;
}
- private static class Weighted<T extends Comparable<T>> implements Comparable<Weighted<T>> {
- final T word;
- final int score;
-
- Weighted(T word, int score) {
- this.word = word;
- this.score = score;
- }
+ private record Weighted<T extends Comparable<T>>(T word, int score)
+ implements Comparable<Weighted<T>> {
@Override
public boolean equals(Object o) {
Review Comment:
needs to be removed, too
##########
lucene/analysis/common/src/java/org/apache/lucene/analysis/synonym/word2vec/TermAndBoost.java:
##########
@@ -18,14 +18,13 @@
import org.apache.lucene.util.BytesRef;
-/** Wraps a term and boost */
-public class TermAndBoost {
- /** the term */
- public final BytesRef term;
-
- /** the boost */
- public final float boost;
-
+/**
+ * Wraps a term and boost
+ *
+ * @param term the term
+ * @param boost the boost
+ */
+public record TermAndBoost(BytesRef term, float boost) {
/** Creates a new TermAndBoost */
public TermAndBoost(BytesRef term, float boost) {
Review Comment:
this can be converted to the generic ctor without parameters:
```java
public TermAndBoost {
term = BytesRef.deepCopyOf(term);
}
```
##########
lucene/core/src/java/org/apache/lucene/document/NearestNeighbor.java:
##########
@@ -34,20 +34,16 @@
/** KNN search on top of 2D lat/lon indexed points. */
class NearestNeighbor {
- static class Cell implements Comparable<Cell> {
- final int readerIndex;
- final byte[] minPacked;
- final byte[] maxPacked;
- final PointTree index;
-
- /**
- * The closest distance from a point in this cell to the query point, computed as a sort key
- * through {@link SloppyMath#haversinSortKey}. Note that this is an approximation to the closest
- * distance, and there could be a point in the cell that is closer.
- */
- final double distanceSortKey;
-
- public Cell(
+ /**
+ * @param distanceSortKey The closest distance from a point in this cell to the query point,
+ * computed as a sort key through {@link SloppyMath#haversinSortKey}. Note that this is an
+ * approximation to the closest distance, and there could be a point in the cell that is
+ * closer.
+ */
+ record Cell(
+ PointTree index, int readerIndex, byte[] minPacked, byte[] maxPacked, double distanceSortKey)
+ implements Comparable<Cell> {
+ Cell(
Review Comment:
remove that ctor and replace by default ctor and only copy minPacked and maxPacked (see above).
##########
lucene/codecs/src/java/org/apache/lucene/codecs/blocktreeords/FSTOrdsOutputs.java:
##########
@@ -68,16 +63,6 @@ public int hashCode() {
hash = (int) (hash ^ endOrd);
return hash;
}
-
Review Comment:
remove hashCode, too ^^
##########
lucene/analysis/common/src/java/org/apache/lucene/analysis/hunspell/GeneratingSuggester.java:
##########
@@ -465,11 +458,6 @@ public boolean equals(Object o) {
return score == that.score && word.equals(that.word);
}
- @Override
- public int hashCode() {
- return Objects.hash(word, score);
- }
-
@Override
Review Comment:
let's keep that one, as the toString output is different from default
##########
lucene/codecs/src/java/org/apache/lucene/codecs/blocktreeords/OrdsBlockTreeTermsWriter.java:
##########
@@ -139,18 +139,17 @@ public final class OrdsBlockTreeTermsWriter extends FieldsConsumer {
final PostingsWriterBase postingsWriter;
final FieldInfos fieldInfos;
- private static class FieldMetaData {
- public final FieldInfo fieldInfo;
- public final Output rootCode;
- public final long numTerms;
- public final long indexStartFP;
- public final long sumTotalTermFreq;
- public final long sumDocFreq;
- public final int docCount;
- public final BytesRef minTerm;
- public final BytesRef maxTerm;
-
- public FieldMetaData(
+ private record FieldMetaData(
Review Comment:
make this the default ctor (see above and remove the field assignments), just keep asserts or other checks
--
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: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
Re: [PR] Convert more classes to record classes [lucene]
Posted by "uschindler (via GitHub)" <gi...@apache.org>.
uschindler commented on code in PR #13328:
URL: https://github.com/apache/lucene/pull/13328#discussion_r1584211054
##########
lucene/core/src/java/org/apache/lucene/codecs/TermStats.java:
##########
@@ -16,24 +16,10 @@
*/
package org.apache.lucene.codecs;
-import org.apache.lucene.index.TermsEnum; // javadocs
-
/**
* Holder for per-term statistics.
*
- * @see TermsEnum#docFreq
- * @see TermsEnum#totalTermFreq
+ * @param docFreq How many documents have at least one occurrence of this term.
+ * @param totalTermFreq Total number of times this term occurs across all documents in the field.
*/
-public class TermStats {
- /** How many documents have at least one occurrence of this term. */
- public final int docFreq;
-
- /** Total number of times this term occurs across all documents in the field. */
- public final long totalTermFreq;
-
- /** Sole constructor. */
- public TermStats(int docFreq, long totalTermFreq) {
- this.docFreq = docFreq;
- this.totalTermFreq = totalTermFreq;
- }
-}
+public record TermStats(int docFreq, long totalTermFreq) {}
Review Comment:
What's exactly he message?
--
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: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org
Re: [PR] Convert more classes to record classes [lucene]
Posted by "uschindler (via GitHub)" <gi...@apache.org>.
uschindler commented on code in PR #13328:
URL: https://github.com/apache/lucene/pull/13328#discussion_r1584276533
##########
lucene/core/src/java/org/apache/lucene/codecs/TermStats.java:
##########
@@ -16,24 +16,10 @@
*/
package org.apache.lucene.codecs;
-import org.apache.lucene.index.TermsEnum; // javadocs
-
/**
* Holder for per-term statistics.
*
- * @see TermsEnum#docFreq
- * @see TermsEnum#totalTermFreq
+ * @param docFreq How many documents have at least one occurrence of this term.
+ * @param totalTermFreq Total number of times this term occurs across all documents in the field.
*/
-public class TermStats {
- /** How many documents have at least one occurrence of this term. */
- public final int docFreq;
-
- /** Total number of times this term occurs across all documents in the field. */
- public final long totalTermFreq;
-
- /** Sole constructor. */
- public TermStats(int docFreq, long totalTermFreq) {
- this.docFreq = docFreq;
- this.totalTermFreq = totalTermFreq;
- }
-}
+public record TermStats(int docFreq, long totalTermFreq) {}
Review Comment:
It's complicated: we need to find all accessor methods and automatically generated ctors and exclude them. You can get the accessor method from the record component. Maybe we should build a set of them and exclude them from the checks: https://docs.oracle.com/en/java/javase/21/docs/api/java.compiler/javax/lang/model/element/RecordComponentElement.html
Let's make a separate issue and remove all problematic records from this PR.
--
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: issues-unsubscribe@lucene.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org