Search code examples
solrsolrj

solrj returns the same result for different queries


Here is my code:-

    SolrClient client = new HttpSolrClient.Builder("http://arlmsendeavour01:8983/solr/ImageMatch").build();

    SolrQuery query = new SolrQuery();
    query.setRequestHandler("/select");
    //System.currentTimeMillis();
    String q = "{!cache=false}*:*&debugQuery=true&sort=lirefunc(eh,\"opKg0dKEtZOSsaSBkfPChsTEopGykqHExYTEw5GylbKx8KKXkqHRww==\")+asc";
    query.setQuery("q");

    QueryResponse response = null;
    try {
        response = client.query(query);
    } catch (SolrServerException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    SolrDocumentList results = response.getResults();
    for (int i = 0; i < results.size(); ++i) {
        System.out.println(results.get(i)/*.getFieldValue("id")*/);
    }

I am using a function query lirefunc where the first parameter defines whether it is a color or edge or texture and the second parameter is the extracted feature from the image. Every time i run the code that is even for different images and different features I get the same output as if it is extracted from the solr xml. The out put remains the same for all the types of queries. Where am I going wrong?


Solution

  • query.setQuery("q"); - this sets the query to the string "q". I'm certain that's not what you meant to do.

    The setQuery method isn't used to set a query string either - it's used to set whatever is present in the q parameter (the query) to Solr.

    There are separate methods for each part of the request to Solr in SolrJ.

    To set the sort= parameter, use addSort:

    query.addSort(SortClause.desc("lirefunc(eh,\"opKg0dKEtZOSsaSBkfPChsTEopGykqHExYTEw5GylbKx8KKXkqHRww==\")"));