Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Adding a field to CQL from OS_PROPERTYENTRY

BKippelt February 20, 2017

Is it possible to add a CQL field from OS_PROPERTYENTRY?

Sub-Question: https://answers.atlassian.com/questions/56039602

3 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Answer accepted
BKippelt March 7, 2017

Argh damn... just a little mistake in my LanguageFieldHandler


@Override
    public V2SearchQueryWrapper build(TextExpressionData expressionData, String value) {
        validateSupportedOp(expressionData.getOperator(), newHashSet(CONTAINS, NOT_CONTAINS));
        return wrapV2Search(new TextFieldQuery(LanguagePropertyExtractor.INDEXABLE_PROPERTY, value, BooleanOperator.AND), expressionData);
    }
@Override
    public V2SearchQueryWrapper build(TextExpressionData expressionData, String value) {
        validateSupportedOp(expressionData.getOperator(), newHashSet(CONTAINS, NOT_CONTAINS));
        return wrapV2Search(new TextFieldQuery(FIELD_NAME, value, BooleanOperator.AND), expressionData);
    }
0 votes
BKippelt March 7, 2017

I think i almost made it. But something is still missing/wrong with my code. Maybe someone can help me.

 

<cql-query-field fieldName="titleEn"
    key="title-en-field" name="Scroll Language EN Title"
    class="com.confluence.cql.LanguageFieldHandler">
    <ui-support value-type="string" default-operator="~" i18n-key="cql.field.titleEn"/>
</cql-query-field>
@Scanned
public class LanguagePropertyExtractor implements Extractor {
    public static final String INDEXABLE_PROPERTY = "com.k15t.scroll.versions.translations.title.en";
    private ContentPropertyManager contentPropertyManager;
    @Inject
    public LanguagePropertyExtractor(@ComponentImport ContentPropertyManager contentPropertyManager) {
        this.contentPropertyManager = contentPropertyManager;
    }
    public void addFields(Document document, StringBuffer defaultSearchableText, Searchable searchable) {
        if (searchable instanceof ContentEntityObject) {
            ContentEntityObject contentEntityObject = (ContentEntityObject) searchable;
            String value = contentPropertyManager.getTextProperty(contentEntityObject, INDEXABLE_PROPERTY);
            if(isNotNullOrEmpty(value)) {
                if (TextUtils.stringSet(value)) {
                    defaultSearchableText.append(value).append(" ");
                    document.add(new TextField("titleEn", value, Field.Store.YES));
                }
            }
        }
    }
}
public class LanguageFieldHandler extends BaseFieldHandler implements TextFieldHandler<V2SearchQueryWrapper>,
        EqualityFieldHandler<String, V2SearchQueryWrapper> {
    private static final String FIELD_NAME = "titleEn";
    public LanguageFieldHandler() {
        super(FIELD_NAME, true);
    }
    @Override
    public V2SearchQueryWrapper build(TextExpressionData expressionData, String value) {
        validateSupportedOp(expressionData.getOperator(), newHashSet(CONTAINS, NOT_CONTAINS));
        return wrapV2Search(new TextFieldQuery(LanguagePropertyExtractor.INDEXABLE_PROPERTY, value, BooleanOperator.AND), expressionData);
    }
    @Override
    public FieldOrder buildOrder(OrderDirection direction) {
        return new V2SearchSortWrapper(new TitleSort(V2SearchSortWrapper.convertOrder(direction)));
    }
    @Override
    public V2SearchQueryWrapper build(SetExpressionData expressionData, Iterable<String> values) {
        validateSupportedOp(expressionData.getOperator(), newHashSet(IN, NOT_IN));
        SearchQuery query = joinSingleValueQueries(values, new Function<String, TextFieldQuery>() {
            @Override
            public TextFieldQuery apply(@Nullable String value) {
                return createEqualityQuery(value);
            }
        });
        return wrapV2Search(query, expressionData);
    }
    @Override
    public V2SearchQueryWrapper build(EqualityExpressionData expressionData, String value) {
        validateSupportedOp(expressionData.getOperator(), newHashSet(EQUALS, NOT_EQUALS));
        return wrapV2Search(createEqualityQuery(value), expressionData);
    }
    private TextFieldQuery createEqualityQuery(String value) {
        return new TextFieldQuery(LanguagePropertyExtractor.INDEXABLE_PROPERTY, "\"" + value + "\"", BooleanOperator.AND);
    }
}

 

luke-translations.png

 

But if i use the Confluence search, i do not get any results:

{"results":[],"start":0,"limit":10,"size":0,"totalSize":0,"cqlQuery":"titleEn ~ \"Product\"","searchDuration":32,"archivedResultCount":0,"_links":{"base":"http://10.100.152.246:8090","context":""}}
0 votes
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 20, 2017

OS_Propertyentry does not contain field data.

TAGS
AUG Leaders

Atlassian Community Events