Querying hidden fields
Hello,
Querying by document fields work fine, however, the same query but with hidden fields doesn't return any document when it should.
Here's my code to query:
DocumentField registryIdField = DocumentField.createStringField(
REGISTRY_ID_FIELD_NAME,
REGISTRY_ID_FIELD_DESCRIPTION,
REGISTRY_ID_FIELD_ID);
DocumentField recordIdField = DocumentField.createStringField(
RECORD_ID_FIELD_NAME,
RECORD_ID_FIELD_DESCRIPTION,
RECORD_ID_FIELD_ID);
DocumentField fieldIdField = DocumentField.createStringField(
FIELD_ID_FIELD_NAME,
FIELD_ID_FIELD_DESCRIPTION,
FIELD_ID_FIELD_ID);
Query registryIdQuery = Query.Factory.createFieldQuery(registryIdField, Condition.EQUAL, tableId);
Query recordIdQuery = Query.Factory.createFieldQuery(recordIdField, Condition.EQUAL, recordId);
Query fieldIdQuery = Query.Factory.createFieldQuery(fieldIdField, Condition.EQUAL, fieldId);
Query[] queries = new Query[]{registryIdQuery, recordIdQuery, fieldIdQuery};
Query query = Query.Factory.createAndQuery(queries, new HashMap<>());
List<AnnotatedPluginDocument> existingDocs = registryFolderService.retrieve(query, ProgressListener.EMPTY)
And here is my code to create the fields:
DocumentField registryIdField = DocumentField.createStringField(
REGISTRY_ID_FIELD_NAME, REGISTRY_ID_FIELD_DESCRIPTION, REGISTRY_ID_FIELD_ID);
documentInFolder.setHiddenFieldValue(registryIdField, registryId);
DocumentField recordIdField = DocumentField.createStringField(
RECORD_ID_FIELD_NAME, RECORD_ID_FIELD_DESCRIPTION, RECORD_ID_FIELD_ID);
documentInFolder.setHiddenFieldValue(recordIdField, recordId);
DocumentField fieldIdField = DocumentField.createStringField(
FIELD_ID_FIELD_NAME, FIELD_ID_FIELD_DESCRIPTION, FIELD_ID_FIELD_ID);
documentInFolder.setHiddenFieldValue(fieldIdField, fieldId);
documentInFolder.save()
This same code but with setFieldValue instead returns results as expected.
Is there a way to query using hidden fields?
Thanks!
Guzman
-
Unfortunately hidden fields are not indexed for searching by design. Sorry about the lack of documentation on this, we'll improve that.
The best I can suggest for a work-around is to change your fields to be not visible by default and non-editable by replacing
DocumentField recordIdField = DocumentField.createStringField(
RECORD_ID_FIELD_NAME,
RECORD_ID_FIELD_DESCRIPTION,
RECORD_ID_FIELD_ID);with
DocumentField recordIdField = new DocumentField(
RECORD_ID_FIELD_NAME,
RECORD_ID_FIELD_DESCRIPTION,
RECORD_ID_FIELD_ID,
String.class,
false,
false);Alternatively, if you're implementing your own PluginDocument class (which is a lot more involved and I wouldn't recommend it unless you really need to), there's the AdditionalSearchContent interface that PluginDocuments may implement to provide search content for data which is not stored as a field.
0 -
Yes, however, setting the fields as non-editable doesn't prevent the user from actually modifying those fields, it just throws a warning. Is that correct?
0 -
Yes, that's correct that they will see this warning
This value is read-only because it has been provided by a database or operation. Are you sure you want to change it?
But they can go ahead with editing it anyway. I don't think there's a way to prevent that unless you happen to be viewing documents in a PartiallyWritableDatabaseService, in which case you could use PartiallyWritableDatabaseService.canEditDocumentField, but if you aren't already using a PartiallyWritableDatabaseService that won't help.
0 -
Sounds good, thanks. Would be a good feature to have.
Guzman0
Please sign in to leave a comment.
Comments
4 comments