Hi @DamianKedzierski ,
I have faced with problem during indexation of own custom field.
I have added own NonNullCustomFieldProvider
public class TestCFProvider implements NonNullCustomFieldProvider {
private final IssueManager issueManager;
private final CustomFieldValuePersister customFieldValuePersister;
private final CustomFieldManager customFieldManager;
public TestCFProvider(IssueManager issueManager, CustomFieldValuePersister customFieldValuePersister, CustomFieldManager customFieldManager) {
this.issueManager = issueManager;
this.customFieldValuePersister = customFieldValuePersister;
this.customFieldManager = customFieldManager;
}
@Override
public Map<Long, Map<String, CustomFieldPrefetchedData>> getCustomFieldInfo(List<Issue> issues) {
Map<Long, Map<String, CustomFieldPrefetchedData>> data = new HashMap<>();
for (Issue issue : issues) {
Map<String, CustomFieldPrefetchedData> dataMap = new HashMap<>();
List<CustomField> cfs = customFieldManager.getCustomFieldObjects(issue);
cfs = cfs.stream().filter(cf -> cf.getCustomFieldType().getKey().equals(Constants.MY_CF_TYPE)).collect(Collectors.toList());
for (CustomField cf : cfs) {
Collection<Issue> selectedIssues = ((IndexedCF) cf.getCustomFieldType())
.getLinkedIssuesList(cf, issue);
dataMap.put(cf.getId(), new CustomFieldPrefetchedData(selectedIssues));
}
data.put(issue.getId(), dataMap);
}
return data;
}
@Override
public Object getIdentity() {
return customFieldValuePersister.getIdentity();
}
}
And here is the indexer
public class FieldIndexer extends AbstractCustomFieldIndexer implements FieldIndexer {
private final CustomField customField;
protected FieldIndexer(final FieldVisibilityManager fieldVisibilityManager, CustomField customField) {
super(fieldVisibilityManager, customField);
this.customField = customField;
}
public Boolean skipsIndexingNull() {
return true;
}
private void addOwnIndex(Document doc, Issue issue) {
Collection<Issue> selectedIssues = ((IndexedCF) customField.getCustomFieldType())
.getLinkedIssuesList(customField, issue);
String idIndexValue;
String keyIndexValue;
String keyIndexValueFolded;
if (selectedIssues.isEmpty()) {
idIndexValue = NO_VALUE_INDEX_VALUE;
keyIndexValue = NO_VALUE_INDEX_VALUE;
keyIndexValueFolded = NO_VALUE_INDEX_VALUE;
indexField(doc, idIndexValue, keyIndexValue, keyIndexValueFolded, issue);
} else {
for (Issue referredIssue : selectedIssues) {
idIndexValue = referredIssue.getId().toString();
keyIndexValue = referredIssue.getKey();
keyIndexValueFolded = getKeyFoldedValue(referredIssue.getKey());
indexField(doc, idIndexValue, keyIndexValue, keyIndexValueFolded, issue);
}
}
}
/**
*
* @param doc
* @param idIndexValue
* @param keyIndexValue
* @param keyIndexValueFolded
*/
private void indexField(Document doc, String idIndexValue, String keyIndexValue, String keyIndexValueFolded,
Issue issue) {
if (isFieldVisibleAndInScope(issue)) {
doc.add(new StringField(getIdFieldId(customField), idIndexValue, Field.Store.YES));
// store the unchanged key, index the folded one for consistent searching
doc.add(new StoredField(getKeyFieldId(customField), new BytesRef(keyIndexValue)));
doc.add(new StringField(getKeyFoldedFieldId(customField), keyIndexValueFolded, Field.Store.NO));
//for gadgets
doc.add(new SortedSetDocValuesField(getIdFieldId(customField), new BytesRef(idIndexValue)));
doc.add(new SortedSetDocValuesField(getKeyFieldId(customField), new BytesRef(keyIndexValue)));
} else {
doc.add(new StoredField(getIdFieldId(customField), new BytesRef(idIndexValue)));
doc.add(new StoredField(getKeyFieldId(customField), new BytesRef(keyIndexValue)));
}
SecurityIndexingUtils.indexPermissions(doc, issue, getIdFieldId(customField), idIndexValue);
}
public static String getIdFieldId(CustomField customField) {
return customField.getId();
}
private static String getKeyFieldId(CustomField customField) {
return customField.getId() + "_key";
}
private static String getKeyFoldedFieldId(CustomField customField) {
return customField.getId() + "_key_folded";
}
private static String getKeyFoldedValue(String key) {
return CaseFolding.foldString(key);
}
@Override
public void addDocumentFieldsNotSearchable(Document doc, Issue issue, com.atlassian.jira.issue.customfields.vdi.CustomFieldPrefetchedData data) {
addOwnIndex(doc, issue);
}
@Override
public void addDocumentFieldsSearchable(Document doc, Issue issue, CustomFieldPrefetchedData data) {
addOwnIndex(doc, issue);
}
Here is the problem:
- Not global context (have set one or more issue type(s))
JQL:
project = crm and cf[10021] is not EMPTY
returns all out of context issues + correctly filtered in context issues.
- Global context
same JQL returns correctly filtered issues only those that have not empty value in CF.
Maybe I something miss or made some mistake in indexer?
Custom field store list of issues as comma separated string.