package org.jabref.model.search.rules;

import java.util.Iterator;
import java.util.List;
import java.util.Locale;

import org.jabref.model.entry.BibEntry;

import org.apache.commons.lang3.StringUtils;

/**
 * Search rule for contain-based search.
 */
public class ContainBasedSearchRule implements SearchRule {

    private final boolean caseSensitive;

    public ContainBasedSearchRule(boolean caseSensitive) {
        this.caseSensitive = caseSensitive;
    }

    public boolean isCaseSensitive() {
        return caseSensitive;
    }

    @Override
    public boolean validateSearchStrings(String query) {
        return true;
    }

    @Override
    public boolean applyRule(String query, BibEntry bibEntry) {

        String searchString = query;
        if (!caseSensitive) {
            searchString = searchString.toLowerCase(Locale.ROOT);
        }
        searchString = StringUtils.stripAccents(searchString);

        List<String> unmatchedWords = new SentenceAnalyzer(searchString).getWords();

        for (String fieldKey : bibEntry.getFieldNames()) {
            String formattedFieldContent = StringUtils.stripAccents(bibEntry.getLatexFreeField(fieldKey).get());
            if (!caseSensitive) {
                formattedFieldContent = formattedFieldContent.toLowerCase(Locale.ROOT);
            }

            Iterator<String> unmatchedWordsIterator = unmatchedWords.iterator();
            while (unmatchedWordsIterator.hasNext()) {
                String word = unmatchedWordsIterator.next();
                if(formattedFieldContent.contains(word)) {
                    unmatchedWordsIterator.remove();
                }
            }

            if(unmatchedWords.isEmpty()) {
                return true;
            }
        }

        return false; // Didn't match all words.
    }

}

@@ -154,54 +154,8 @@
 y;%0A%0A
-import org.apache.commons.lang3.StringUtils;%0A%0A
 /**%0A
@@ -812,71 +812,8 @@
    %7D
-%0A        searchString = StringUtils.stripAccents(searchString);
 %0A%0A  
@@ -1002,33 +1002,8 @@
 t = 
-StringUtils.stripAccents(
 bibE
@@ -1040,17 +1040,16 @@
 y).get()
-)
 ;%0A      

Revert "allow search for words without diacritics in contain-based mode". I did not know that the push is considered in my push request