<commit_before>package com.tinkerpop.gremlin.elastic.process.graph.traversal.sideEffect;

import com.tinkerpop.gremlin.elastic.structure.ElasticEdge;
import com.tinkerpop.gremlin.process.graph.util.HasContainer;
import com.tinkerpop.gremlin.structure.Compare;
import com.tinkerpop.gremlin.structure.Contains;
import com.tinkerpop.gremlin.structure.Direction;
import org.elasticsearch.common.geo.builders.ShapeBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.json.JsonXContent;
import org.elasticsearch.index.query.*;
import sun.reflect.generics.reflectiveObjects.NotImplementedException;

import java.util.List;

/**
 * Created by Eliran on 11/3/2015.
 */
public class FilterBuilderProvider {

    public static FilterBuilder getFilter(ElasticSearchStep searchStep){
        return getFilter(searchStep,null);
    }
    public static FilterBuilder getFilter(ElasticSearchStep searchStep,Direction direction){
        Object[] ids = searchStep.getIds();
        List<HasContainer> hasContainers = searchStep.getPredicates();
        if (hasContainers.size() == 0 && ids.length == 0) return null;
        BoolFilterBuilder boolFilterBuilder = FilterBuilders.boolFilter();
        for (HasContainer has : hasContainers) {
            if (has.predicate instanceof Compare) {
                String predicateString = has.predicate.toString();
                switch (predicateString) {
                    case ("eq"):
                        if (has.key.equals("~label")) searchStep.setLabel(has.value.toString());
                        else boolFilterBuilder.must(FilterBuilders.termFilter(has.key, has.value));
                        break;
                    case ("neq"):
                        boolFilterBuilder.mustNot(FilterBuilders.termFilter(has.key, has.value));
                        break;
                    case ("gt"):
                        boolFilterBuilder.must(FilterBuilders.rangeFilter(has.key).gt(has.value));
                        break;
                    case ("gte"):
                        boolFilterBuilder.must(FilterBuilders.rangeFilter(has.key).gte(has.value));
                        break;
                    case ("lt"):
                        boolFilterBuilder.must(FilterBuilders.rangeFilter(has.key).lt(has.value));
                        break;
                    case ("lte"):
                        boolFilterBuilder.must(FilterBuilders.rangeFilter(has.key).lte(has.value));
                        break;
                    default:
                        throw new IllegalArgumentException("predicate not supported in has step: " + has.predicate.toString());
                }
            } else if (has.predicate instanceof Contains) {
                if (has.predicate == Contains.without)
                    boolFilterBuilder.mustNot(FilterBuilders.existsFilter(has.key));
                else if (has.predicate == Contains.within)
                    boolFilterBuilder.must(FilterBuilders.existsFilter(has.key));
            } else if (has.predicate instanceof Geo)
                boolFilterBuilder.must(new GeoShapeFilterBuilder(has.key, GetShapeBuilder(has.value), ((Geo) has.predicate).getRelation()));
            else throw new NotImplementedException();
        }<commit_msg>add support on equal id<commit_after>package com.tinkerpop.gremlin.elastic.process.graph.traversal.sideEffect;

import com.tinkerpop.gremlin.elastic.structure.ElasticEdge;
import com.tinkerpop.gremlin.process.graph.util.HasContainer;
import com.tinkerpop.gremlin.structure.Compare;
import com.tinkerpop.gremlin.structure.Contains;
import com.tinkerpop.gremlin.structure.Direction;
import org.elasticsearch.common.geo.builders.ShapeBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.json.JsonXContent;
import org.elasticsearch.index.query.*;
import sun.reflect.generics.reflectiveObjects.NotImplementedException;

import java.util.List;

/**
 * Created by Eliran on 11/3/2015.
 */
public class FilterBuilderProvider {

    public static FilterBuilder getFilter(ElasticSearchStep searchStep){
        return getFilter(searchStep,null);
    }
    public static FilterBuilder getFilter(ElasticSearchStep searchStep,Direction direction){
        Object[] ids = searchStep.getIds();
        List<HasContainer> hasContainers = searchStep.getPredicates();
        if (hasContainers.size() == 0 && ids.length == 0) return null;
        BoolFilterBuilder boolFilterBuilder = FilterBuilders.boolFilter();
        for (HasContainer has : hasContainers) {
            if (has.predicate instanceof Compare) {
                String predicateString = has.predicate.toString();
                switch (predicateString) {
                    case ("eq"):
                        if (has.key.equals("~label")) searchStep.setLabel(has.value.toString());
                        else if(has.key.equals("~id")) {
                            searchStep.addId(has.value);
                            ids = searchStep.getIds();
                        }
                        else boolFilterBuilder.must(FilterBuilders.termFilter(has.key, has.value));
                        break;
                    case ("neq"):
                        boolFilterBuilder.mustNot(FilterBuilders.termFilter(has.key, has.value));
                        break;
                    case ("gt"):
                        boolFilterBuilder.must(FilterBuilders.rangeFilter(has.key).gt(has.value));
                        break;
                    case ("gte"):
                        boolFilterBuilder.must(FilterBuilders.rangeFilter(has.key).gte(has.value));
                        break;
                    case ("lt"):
                        boolFilterBuilder.must(FilterBuilders.rangeFilter(has.key).lt(has.value));
                        break;
                    case ("lte"):
                        boolFilterBuilder.must(FilterBuilders.rangeFilter(has.key).lte(has.value));
                        break;
                    default:
                        throw new IllegalArgumentException("predicate not supported in has step: " + has.predicate.toString());
                }
            } else if (has.predicate instanceof Contains) {
                if (has.predicate == Contains.without)
                    boolFilterBuilder.mustNot(FilterBuilders.existsFilter(has.key));
                else if (has.predicate == Contains.within)
                    boolFilterBuilder.must(FilterBuilders.existsFilter(has.key));
            } else if (has.predicate instanceof Geo)
                boolFilterBuilder.must(new GeoShapeFilterBuilder(has.key, GetShapeBuilder(has.value), ((Geo) has.predicate).getRelation()));
            else throw new NotImplementedException();
        }
{'fraction_non_alphanumeric': 0.10171730515191546, 'fraction_numerical': 0.002642007926023778, 'mean_word_length': 2.1546296296296297, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '382454', 'n_tokens_mistral': 1773, 'n_tokens_neox': 1677, 'n_words': 293}