2

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?

user1998719
  • 87
  • 1
  • 1
  • 11

2 Answers2

1

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

Community
  • 1
  • 1
Mantra
  • 316
  • 3
  • 16
  • Thanks for your answer but still does not answer my question. I'm looking for examples on how to build a complex query from user entered input, ex: user enters "foo" and I have to add group-clauses. – user1998719 Mar 29 '13 at 14:13
  • @user1998719 My pleasure! But please be more clear with your question and try to include some additional information for supporting your Q. like, * Which Solr version you are using? * How you are using it? like using SolrJ or any other. * The title of the question must reflect the exact clue of your Q. * Any supported links that you have referred. * screen shots of your attempts. e.t.c. With this it is likely draw more attention of the viewer. – Mantra Mar 30 '13 at 08:56
0

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>
Prem
  • 329
  • 1
  • 11
  • Thanks for your reply but I think your solution is more related to how to build a custom filter. – user1998719 Mar 29 '13 at 14:15
  • If I understand correctly, your use case is to modify the query to more complex query, Not the way request handler work right? If that is the case, a custom component itself will solve your problem. You don't need to write custom request handler. – Prem Mar 29 '13 at 16:16
  • AGAIN I need to know how to build queries with group by clauses in a custom request handler. Please don't answer any questions if you don't have the answer. – user1998719 Apr 01 '13 at 15:25