When using SolrJ can I point it at a request handler? - java

I have created a request handler in Solr that uses dismax and limits my query to certain fields and adds boosts for relevancy on the "title" field.
This all works fine when I go directly to Solr using an http request in a browser. However my question is whether I can use the request handler if I am accessing Solr using SolrJ?
It would be better if I could control boosts and filters and so on in the request handler rather than having to make code changes but I can't see how to specify a request handler in the API.
Any ideas?

In the class SolrQuery, there is a method setRequestHandler that allows you to do that. You pass the name of the request handler as defined in solrconfig.xml (probably 'dismax').

Related

Specify Solr request handler in query

I have created a new request handler in Solr name mySearch, in the older versions of Solr I can use the default select request and specify the custom request handler using the "qt" parameter. But in Solr 6.0 that doesn't seem to work.
Is there a way I can invoke the new request handler using a query param instead of solr/mySearch?
In Solr 6, this is controlled by the parameter handleSelect which needs to be set to true and the solrconfig.xml should not have select handler (it does in all examples).
Once you fulfill both conditions, you should be able to get your old behavior to work.

Set request attribute in varnish script

Is it possible from varnish vcl script to set an attribute on the request and get it in the backend by java Servlet getAttribute() method? http://docs.oracle.com/javaee/6/api/javax/servlet/ServletRequest.html#getAttribute(java.lang.String)
Request attributes are a mechanism internal to the Servlet framework, so it is not possible to set them from the outside. It would however be possible to set a Request parameter (in either query String or request body, depending on the request type), that would then be available through HttpServletRequest.getParameter(name)

Passing object from Spring HandlerInterceptor to Servlet Filter

There is a webapp, where every request consumes various external resources. The webapp tracks those consumed resources with request scooped bean. Then HandlerInterceptor's afterCompletion method calls TaskExecutor to store this information in DB. All is fine and dandy, but there goes the requirement to add bandwith consumption as another resource. Counting outgoing response size is a typical task for servlet filter (along with response wrapper and custom stream implementation). So this is done and is also working.
The problem is that I'd like to aggregate two things together. Obviously, I can't pass "bytes sent" to Spring HandlerInterceptor, because filter's doFilter() hasn't completed yet and the amount of bytes sent isn't known when the interceptor runs. So filter must be the place to aggregate all the resource usage and start async task to store it in DB. The problem is: how can I pass data from HandlerInterceptor to Filter. I've tried simple request.setAttribute() but surprisingly it didn't worked.
As a side note: I'm aware of request scooped bean lifecycle and at the handler I'm creating a simple POJO populated with data from scooped bean.
The problem turned out to be quite trival. The app was doing a lot of forward/dispatches as a part of somehwat normal request handling. It turned out that the my filter was called (so far, so good) then another filter down the chain was doing forward/dispatch which then did actual request processing. Default filter setup catches only plain requests and you need additional configuration (web.xml) to also filter forwards/dispatches. I just did that and that solved the problem.

Remove invalid request parameter from URL with servlet filter

I have a web application written in Java which uses Struts 1.0. Sometimes when a URL is fired, I can see that it one of the request parameters does not have any name and value like the following ...
http://www.aaa.com/test.do?a=1&b=2&=&d=4&e=5
As can be seen, there is a '&=' which is essentially a parameter with no name and value. I'd like to remove this part from the URL before sending the request to the server. How can I achieve this? Should I use a filter or is there an easier way?

Modify the filter chain - Or select servlet to respond to request using filter

I am trying to use a filter to map requests. I am trying to do this for two reasons, firstly to dynamically generate URI's and have them mapped to the appropriate servlet and secondly to catch URI's which are not registered and handle them appropriately.
So I'm using a catch-all filter to process the URI and determine the response. I would like some way of modifying the filter chain, or some way to set the servlet which responds to the request from within the filter. I have been unsuccessful using filterConfig.getServletContext().getRequestDispatcher().forward() to send to jsp, ideally though I would like to map to a servlet but can't figure out how.
The reason I am not doing this from within a servlet is that I have some URIs which are fixed within web.xml and if I use a catch-all servlet those URIs do not get mapped. Is this possible, is it clean or it going to get really messy?
I don't think this is the right way to do it.
If you look at what web MVC frameworks do, they have a front controller servlet that maps URLs to controllers, which themselves can accept HTTP requests and return HTTP responses. I think that's a design worth emulating, not your filter idea.

Categories

Resources