user1998719
user1998719

Reputation: 87

Solr Custom Request Handler: creating queries with group clauses?

I'm writing my own request handler. After I get the user input from "q"

String q = params.get(CommonParams.Q);

I want to build a complex query using group clauses:

example:

foo&group.truncate=true&group.ngroups=true&group.field=id&group.sort=date desc&version=2.2&start=0&rows=10&indent=on

I'm seeing examples on line where they are doing following:

Query query1 = new TermQuery(new Term(q));

So in this case the q, would be the query string I create?

and after we create the query how do we actually perform the search?

Upvotes: 2

Views: 2189

Answers (2)

Mantra
Mantra

Reputation: 346

I have not gone deep with these links but check to see if it provides any clue to your Q.

Upvotes: 1

Prem
Prem

Reputation: 329

I Don't have experience in writing RequestHandler and I Don't know how difficult it is.

If your requirement is to add more filters to the existing the query, I think it is easy to write a SearchComponent.

You can write a CustomComponent extending SearchComponent. In that Custom component, you can override the prepare method as below:

public void prepare(ResponseBuilder responseBuilder) throws IOException {
 BooleanFilter booleanFilter = new BooleanFilter();
 TermsFilter termFilter = new TermsFilter(new Term("name", value));
 booleanFilter.add(new FilterClause(termFilter, Occur.MUST));
 /*
   Create a filtered Query with the with the filter created and the actual query
  */
 FilteredQuery query = new FilteredQuery(responseBuilder.getQuery(),booleanFilter);
 // Set the new query into the response builder.
 responseBuilder.setQuery(query);
}

Once you have search component ready, you can create the searchComponent in solrConfig.xml as below:

 <searchComponent name="customComponent" class="com.CustomComponent">
<lst name="parameterName">
    <str name="key">value</str>
</lst>
  </searchComponent>

Then You can add this as a last component in the existing Request Handler

<arr name="last-components">
  <str>customComponent</str>
   <str>spellcheck</str>
 </arr>

Upvotes: 0

Related Questions