solrspring-dataspring-data-solr

Spring Data for Apache Solr Extended DisMax Parameters


I am trying to add the params below (qf,bq) in a Solr query generated by Spring Data Solr.

Solr parameters are :

qf => Spring Data Solr Method?
bq => Spring Data Solr Method?

I was able to find the methods below

fq => addFilterQuery
fl => addProjectionOnField
defType => setDefType
qt => setRequestHandler

I saw an open issue qf https://jira.spring.io/browse/DATASOLR-153

How can i add the qf and bq params to Solr query built with Spring Data Solr.

Thanks


Solution

  • You can use the SolrCallback on template level to access the SolrClient and execute the query from there or register your own QueryParser for a custom query type.

    Maybe something like:

    @Bean
    public SolrTemplate solrTemplate(SolrClient client) {
    
        SolrTemplate template = new SolrTemplate(client);
        template.registerQueryParser(EdismaxQuery.class, new EdisMaxQueryParser());
        return template;
    }
    
    class EdismaxQuery extends SimpleQuery {
        // ... add stuff you need. Maybe `autoRelax`
    }
    
    class EdisMaxQueryParser extends QueryParserBase<EdismaxQuery> {
    
        DefaultQueryParser defaultQueryParser = new DefaultQueryParser();
    
        @Override
        public SolrQuery doConstructSolrQuery(EdismaxQuery source) {
    
            // just use the default parser to construct the query string in first place.
            SolrQuery target = defaultQueryParser.constructSolrQuery(source);
    
            // add missing parameters
            target.add("defType", "edismax");
            target.add("qf", source....);
    
            return target;
        }
    }