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

run.halo.app.extension.index.query.StringContains Maven / Gradle / Ivy

The newest version!
package run.halo.app.extension.index.query;

import com.google.common.collect.Sets;
import java.util.Map;
import java.util.NavigableSet;
import org.apache.commons.lang3.StringUtils;

public class StringContains extends SimpleQuery {
    public StringContains(String fieldName, String value) {
        super(fieldName, value);
    }

    @Override
    public NavigableSet matches(QueryIndexView indexView) {
        var resultSet = Sets.newTreeSet();
        var indexEntry = indexView.getIndexEntry(fieldName);

        indexEntry.acquireReadLock();
        try {
            for (Map.Entry entry : indexEntry.entries()) {
                var fieldValue = entry.getKey();
                if (StringUtils.containsIgnoreCase(fieldValue, value)) {
                    resultSet.add(entry.getValue());
                }
            }
            return resultSet;
        } finally {
            indexEntry.releaseReadLock();
        }
    }

    @Override
    public String toString() {
        return "contains(" + fieldName + ", '" + value + "')";
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy