All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.rbmhtechnology.vind.parser.queryparser.TermsLiteral Maven / Gradle / Ivy

There is a newer version: 3.2.0
Show newest version
package com.rbmhtechnology.vind.parser.queryparser;

import com.google.common.base.Strings;
import com.rbmhtechnology.vind.api.query.filter.Filter;
import com.rbmhtechnology.vind.model.FieldDescriptor;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

public class TermsLiteral  extends SimpleLiteral{
    private final List values = new ArrayList<>();

    public TermsLiteral add(String val) {
        values.add(val);
        return this;
    }

    public List getValues() {
        return values;
    }

    @Override
    public String toString() {
        return this.values.stream()
                .filter(val -> !Strings.isNullOrEmpty(val)).collect(Collectors.joining(" "));
    }

    @Override
    public Filter toVindFilter(FieldDescriptor descriptor) {
        final Filter termFilter = (Filter)this.getValues().stream()
                .map(val -> Filter.eq(descriptor, val.replaceAll("\\\"", "")))
                .collect(Filter.OrCollector); //TODO: default OR, should be able to change

        return termFilter;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy