
package uk.ac.ebi.atlas.solr.query.builders;

import org.apache.solr.client.solrj.SolrQuery;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import uk.ac.ebi.atlas.search.SemanticQuery;

/**
 * This is a builder, keep always in mind that builders are potentially stateful.
 * If you need to build different query strings within the same client process
 * you must use a new instance of builder for each query.
 */
public class BioentityIdentifierQueryBuilder extends SolrQueryBuilder<BioentityIdentifierQueryBuilder>{
    private static final Logger LOGGER = LoggerFactory.getLogger(BioentityIdentifierQueryBuilder.class);

    private static final String BIOENTITY_IDENTIFIER_FIELD = "bioentity_identifier";
    private static final String PROPERTY_SEARCH_FIELD = "property_value_search";
    private static final int MAX_GENE_IDS_TO_FETCH = 1000000;

    private boolean applyOrOnQueryStringContent;
    private String queryString;

    public BioentityIdentifierQueryBuilder forQueryString(String queryString, boolean applyOrOnQueryStringContent){
        this.queryString = queryString.replace(":", "\\:").replace("[", "\\[").replace("]", "\\]");
        this.applyOrOnQueryStringContent = applyOrOnQueryStringContent;
        return this;
    }

    public BioentityIdentifierQueryBuilder forGeneQuery(SemanticQuery geneQuery, boolean applyOrOnQueryStringContent){
        this.queryString = geneQuery.asSolr1DNF();
        this.applyOrOnQueryStringContent = applyOrOnQueryStringContent;
        return this;
    }

    public SolrQuery build() {
        String propertyName = PROPERTY_SEARCH_FIELD;
        StringBuilder queryConditionBuilder = new StringBuilder(propertyName).append(":");

        if (applyOrOnQueryStringContent){
            // use default "lucene" parser and set default operator to OR and default field to propertyName
            queryConditionBuilder.insert(0, "{!lucene q.op=OR df=" + propertyName + "}(").append(queryString).append(")");
        } else {
            queryConditionBuilder.append("\"").append(queryString).append("\"");
        }

        queryStringBuilder.insert(0, queryConditionBuilder);

        return buildQueryObject(queryStringBuilder.toString());
    }

    private SolrQuery buildQueryObject(String queryString) {
        SolrQuery solrQuery = new SolrQuery(queryString);
        solrQuery.setFields(BIOENTITY_IDENTIFIER_FIELD);
        solrQuery.setParam("group", true);
        solrQuery.setParam("group.field", BIOENTITY_IDENTIFIER_FIELD);
        solrQuery.setParam("group.main", true);
        solrQuery.setRows(MAX_GENE_IDS_TO_FETCH);

        LOGGER.trace("<buildQueryObject> solr query: {}", solrQuery.toString());

        return solrQuery;
    }

    @Override
    protected BioentityIdentifierQueryBuilder getThis() {
        return this;
    }
}

@@ -1,9 +1,8 @@
-%0A
 package 
@@ -146,53 +146,8 @@
 ory;
-%0Aimport uk.ac.ebi.atlas.search.SemanticQuery;
 %0A%0A/*
@@ -1212,278 +1212,8 @@
  %7D%0A%0A
-    public BioentityIdentifierQueryBuilder forGeneQuery(SemanticQuery geneQuery, boolean applyOrOnQueryStringContent)%7B%0A        this.queryString = geneQuery.asSolr1DNF();%0A        this.applyOrOnQueryStringContent = applyOrOnQueryStringContent;%0A        return this;%0A    %7D%0A%0A
     

Remove unused method