dsmiley commented on code in PR #4880:
URL: https://github.com/apache/solr/pull/4880#discussion_r3953726304
##########
solr/core/src/java/org/apache/solr/search/join/ScoreJoinQParserPlugin.java:
##########
@@ -132,8 +138,14 @@ public Weight createWeight(
final Query joinQuery;
try {
joinQuery =
- JoinUtil.createJoinQuery(
- fromField, true, toField, fromQuery, fromHolder.get(),
this.scoreMode);
+ createJoinQuery(
+ fromField,
+ fromCore.getLatestSchema(),
Review Comment:
no; avoid calling `gettLatestSchema`. Notice it's javadocs. Instead, get
it from the request.
##########
solr/core/src/java/org/apache/solr/search/join/ScoreJoinQParserPlugin.java:
##########
@@ -237,6 +256,94 @@ public void visit(QueryVisitor visitor) {
}
}
+ /**
+ * Creates a join query, delegating to {@link
JoinUtil#createJoinQuery(String, boolean, String,
+ * Class, Query, IndexSearcher, ScoreMode)} for a numeric {@code
fromField}/Point {@code toField}
+ * pair, or to {@link JoinUtil#createJoinQuery(String, boolean, String,
Query, IndexSearcher,
+ * ScoreMode)} otherwise.
+ *
+ * @param fromField "foreign key" field name; any field type with a numeric
{@link NumberType}
+ * (not necessarily a Point field type) qualifies, as long as {@code
docValues="true"} is set.
+ * It doesn't need to be {@code indexed}.
+ * @param fromSchema schema holding {@code fromField}, used to detect
numeric doc values
+ * @param toField "primary key" field name
+ * @param toSchema schema holding {@code toField}, used to detect numeric
Point fields
+ * @param fromQuery the query to match documents on the from side
+ * @param fromSearcher the searcher that executed the specified fromQuery
+ * @param scoreMode instructs how scores from the fromQuery are mapped to
the returned query
+ * @return a {@link Query} instance that can be used to join documents based
on the values in the
+ * from and to field
+ */
+ static Query createJoinQuery(
+ String fromField,
+ IndexSchema fromSchema,
+ String toField,
+ IndexSchema toSchema,
+ Query fromQuery,
+ IndexSearcher fromSearcher,
+ ScoreMode scoreMode)
+ throws IOException {
+ final SchemaField fromSchemaField = fromSchema.getFieldOrNull(fromField);
+ final NumberType fromNumberType =
+ fromSchemaField == null ? null :
fromSchemaField.getType().getNumberType();
+ if (fromNumberType != null) {
+ if (!fromSchemaField.hasDocValues()) {
+ throw new SolrException(
+ SolrException.ErrorCode.BAD_REQUEST,
+ "Numeric join 'from' field '"
+ + fromField
+ + "' must have docValues enabled; it doesn't need to be
indexed.");
+ }
+ final SchemaField toSchemaField = toSchema.getFieldOrNull(toField);
Review Comment:
It's not clear we can actually deal with not finding the field. Thus I
question your choice of `OrNull` suffix.
##########
solr/core/src/java/org/apache/solr/search/join/ScoreJoinQParserPlugin.java:
##########
@@ -237,6 +256,94 @@ public void visit(QueryVisitor visitor) {
}
}
+ /**
+ * Creates a join query, delegating to {@link
JoinUtil#createJoinQuery(String, boolean, String,
+ * Class, Query, IndexSearcher, ScoreMode)} for a numeric {@code
fromField}/Point {@code toField}
+ * pair, or to {@link JoinUtil#createJoinQuery(String, boolean, String,
Query, IndexSearcher,
+ * ScoreMode)} otherwise.
+ *
+ * @param fromField "foreign key" field name; any field type with a numeric
{@link NumberType}
+ * (not necessarily a Point field type) qualifies, as long as {@code
docValues="true"} is set.
+ * It doesn't need to be {@code indexed}.
+ * @param fromSchema schema holding {@code fromField}, used to detect
numeric doc values
+ * @param toField "primary key" field name
+ * @param toSchema schema holding {@code toField}, used to detect numeric
Point fields
+ * @param fromQuery the query to match documents on the from side
+ * @param fromSearcher the searcher that executed the specified fromQuery
+ * @param scoreMode instructs how scores from the fromQuery are mapped to
the returned query
+ * @return a {@link Query} instance that can be used to join documents based
on the values in the
+ * from and to field
+ */
+ static Query createJoinQuery(
+ String fromField,
+ IndexSchema fromSchema,
+ String toField,
+ IndexSchema toSchema,
+ Query fromQuery,
+ IndexSearcher fromSearcher,
+ ScoreMode scoreMode)
+ throws IOException {
+ final SchemaField fromSchemaField = fromSchema.getFieldOrNull(fromField);
Review Comment:
It's not clear we can actually deal with not finding the field. Thus I
question your choice of `OrNull` suffix.
##########
solr/core/src/java/org/apache/solr/search/join/ScoreJoinQParserPlugin.java:
##########
@@ -189,9 +201,16 @@ public Weight createWeight(
IndexSearcher searcher, org.apache.lucene.search.ScoreMode scoreMode,
float boost)
throws IOException {
SolrRequestInfo info = SolrRequestInfo.getRequestInfo();
+ final IndexSchema schema = info.getReq().getSchema();
final Query jq =
- JoinUtil.createJoinQuery(
- fromField, true, toField, fromQuery,
info.getReq().getSearcher(), this.scoreMode);
+ createJoinQuery(
+ fromField,
+ schema,
+ toField,
+ schema,
+ fromQuery,
+ info.getReq().getSearcher(),
Review Comment:
Why not use `searcher` in-scope?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]