SolrJ Query, Join Query

I'm currently working on solr, in which to create a connection 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 products that have these 2 categories.

I get accurate results using this, I can find how to write the same thing in Java using SolrJ api

Wat i did

 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); 

it does not give soln, solr gives an error

now according to 1st ans page

 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 it still doesn’t work, adds β€œ&” which I don’t want, since the output is wrong this wat goes to solr for processing here the results come only based on β€œcat1” and not AND both

 q=category_name:cat1&_query_={!dismax%26qf%3Dcategory_name%26v%3Dcat2} 

3rd, tried the wat page suggested in the last answer, fails this wat goes to solr for processing here they work as an OR operator, not AND

 q=category_name:cat1+_query_:"{!dismax+qf%3Dcategory_name+v%3Dcat2}" 

PS: I need to find a solution on how to write myQuery, pls help stuck in it

Finally he decided inested + = "AND query: \" {! dismax qf = category_name v = "; is the solution to my problem

Now the request is being processed! Thanks

+4
source share
1 answer

After reading Nested Queries in Solr It looks like your problem is with passing already encoded values, since SolrJ is going to encode them for you, and you probably get double encoding with your approach in question.

Here is a modified version without encoding that should work:

 SolrQuery query = new SolrQuery(); String nested = ""; nested += "category_name:"; nested += categoryNames.get(0); nested += " AND _query_:\"{!dismax qf=category_name v="; nested += categoryNames.get(1); nested += "}\""; query.setQuery(nested); QueryResponse response = solr.query(query); 

You will probably need to look at the boat or boat logs to find out which URL is being sent to Solr if it doesn't work properly and adjust accordingly to get the desired results.

Update: Changed to make the query parameter an AND match.

+4
source

All Articles