I am currently working on solr, in which to create a join, i need to write
http://localhost:8983/solr/select?q=category_name:cat1%20_query_:"{!dismax%20qf=category_name%20v=cat2}"
where cat1 and cat2 are the categories, in which i want my product to be, i.e all those product which have these 2 categories.
I am getting accurate results using this, by I can find how to write the same in Java using SolrJ api
wat i was doing
String myQuery = "";
myQuery += "category_name:";
myQuery += categoryNames.get(0);
myQuery += "%20_query_:\"{!dismax%20qf=category_name%20v=";
myQuery += categoryNames.get(1);
myQuery += "}\"";
query.setQuery(myQuery);
this doesnt give the soln, solr gives error
now as per page 1st ans
SolrQuery query = new SolrQuery();
query.setQuery("category_name:" + categoryNames.get(0));
String join = "";
join += "{!dismax&qf=category_name&v=";
join += categoryNames.get(1);
join += "}";
query.setParam("_query_", join);
QueryResponse response = solr.query(query);
better but still doesnt works, appends “&” which i dont want since then the output is wrong
this is wat goes to solr for processing
here results come only on basis of “cat1”, rather than AND of both
q=category_name:cat1&_query_={!dismax%26qf%3Dcategory_name%26v%3Dcat2}
3rd, tried wat page suggested in latest answer, fails miserably
this is wat goes to solr for processing
here is works like an OR operator rather than AND
q=category_name:cat1+_query_:"{!dismax+qf%3Dcategory_name+v%3Dcat2}"
PS: I needed to find solution as to how to write myQuery, Pls help, stuck at it
Its finally solved,
nested += ” AND query:\”{!dismax qf=category_name v=”;
is the solution to my problem
now the query gets processed!!
Thanks
After reading Nested Queries in Solr Looks like your issue has to do with passing the already encoded values, since SolrJ is going to encode them for you, and you are probably getting double encoding with your approach in the question.
Here is a modified version without the encoding that should work:
You will probably need to look at your jetty or tomcat logs to see what url is actually being sent to Solr if this does not work as expected and tweak accordingly to get the desired results.
Update: Modified to make the query option be an AND comparison.