Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5975315
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:04:03+00:00 2026-05-22T21:04:03+00:00

Short question: I’m looking for a way (java) to intercept a query to Solr

  • 0

Short question:
I’m looking for a way (java) to intercept a query to Solr and inject a few extra filtering parameters provided by my business logic. What structures should I use?

Context:
First of all, a little confession: I’m such a rookie regarding Solr. For me, setting up a server, defining a schema, coding a functional indexmanager and afterwards actually seeing the server returning the right results – exactly as intended! – was already much of an achievement for itself. Yay me!

However I’m currently working in an enterprise project that requires a little more than that. Roughly speaking, the solr instance is to be queried by several thousands of users through the very same requestHandler, being that the documents returned are automatically filtered according to a user’s permission level. For example, if both the user A and the super-user B tried the very same search parameters (even the very same url), the user B would get all of user A’s files and then some more. In order to accomplish this the documents are already indexed with the necessary permission level information.

Well, with this in mind and making use of Solr’s extensive documentation for newb developers I tried to come up with a simple custom requestHandler that overrides the handleRequest function in order to inject the necessary extra parameters in the SolrQueryRequest. All is fine and dandy – except that I never see any difference at all in the QueryResponse, the server rudely ignoring my little manipulation. After a couple of days searching the web without so much of a hint weather if this the best approach, finally decided to come up and bother the fine folks here at StackOverflow.

So, in short, my questions are:

  • Is this a correct approach? Are there other alternatives? I can already grasp some of Solr’s concepts, but admittedly there is much lacking and its entirely possible that am missing something.

  • If so, after modifying the query parameters is there anything I should do to force the QueryResponse to be updated? As far as I can tell these are merely encapsulating http requests, and I fail to sniff anything querying the server after the modifications are made.

Thanks in advance and so very sorry for the long post!

UPDATE

After a lot of reading APIs and specially much trial and error I’ve managed to get a functional solution. However I still fail to understand much of Solr’s internals, therefore would still appreciate some enlightening. Feel free to bash at will, am still very aware of my rookiness.

The relevant part of the solution is this function which is called from by overriden handleRequestBody:

private void SearchDocumentsTypeII(SolrDocumentList results,
        SolrIndexSearcher searcher, String q, 
        UserPermissions up, int ndocs, SolrQueryRequest req,
        Map<String, SchemaField> fields, Set<Integer> alreadyFound)
        throws IOException, ParseException {


         BooleanQuery bq = new BooleanQuery();
         String permLvl = "PermissionLevel:" + up.getPermissionLevel();
         QParser parser = QParser.getParser(permLvl, null, req);
         bq.add(parser.getQuery(), Occur.MUST);

         Filter filter = CachingWrapperFilter(new QueryWrapperFilter(bq));   

         QueryParser qp = new QueryParser(q, new StandardAnalyzer());
         Query query =  qp.parse(q);                        

         append (results, searcher.search(
          query, filter, 50).scoreDocs,
          alreadyFound, fields, new HashMap<String,Object>(), 0,
          searcher.getReader(), true);

}

Basically the search query is not modified in any way, and instead a filter is applied containing the PermissionLevel of the user. Even so, why doesn’t the following alternative work? The search query works perfectly when applied in the standard requestHandler, while in this case it simply doesn’t hit any document.

private void SearchDocumentsTypeII(SolrDocumentList results,
        SolrIndexSearcher searcher, String q, 
        UserPermissions up, int ndocs, SolrQueryRequest req,
        Map<String, SchemaField> fields, Set<Integer> alreadyFound)
        throws IOException, ParseException {

         String qFiltered = q + " AND " + "PermissionLevel:" + up.getPermissionLevel();                              

         QueryParser qp = new QueryParser(qFiltered, new StandardAnalyzer());
         Query query =  qp.parse(qFiltered);                        

         append (results, searcher.search(
          query, null, 50).scoreDocs,
          alreadyFound, fields, new HashMap<String,Object>(), 0,
          searcher.getReader(), true);

}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T21:04:04+00:00Added an answer on May 22, 2026 at 9:04 pm

    Oh well. As previously stated, the answer that worked for me. Feel free to comment or bash!

       private void SearchDocumentsTypeII(SolrDocumentList results,
                SolrIndexSearcher searcher, String q, 
                UserPermissions up, int ndocs, SolrQueryRequest req,
                Map<String, SchemaField> fields, Set<Integer> alreadyFound)
                throws IOException, ParseException {
    
    
                 BooleanQuery bq = new BooleanQuery();
                 String permLvl = "PermissionLevel:" + up.getPermissionLevel();
                 QParser parser = QParser.getParser(permLvl, null, req);
                 bq.add(parser.getQuery(), Occur.MUST);
    
                 Filter filter = CachingWrapperFilter(new QueryWrapperFilter(bq));   
    
                 QueryParser qp = new QueryParser(q, new StandardAnalyzer());
                 Query query =  qp.parse(q);                        
    
                 append (results, searcher.search(
                  query, filter, 50).scoreDocs,
                  alreadyFound, fields, new HashMap<String,Object>(), 0,
                  searcher.getReader(), true);
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Very short question: Is there a more elegant way to do this: Object tmp;
A short question: My eclipse project is set to use the sun-java-6-jdk-supplied JDK library,
Short question: Is there a shorter way to do this array<array<atomic<int>,n>,m> matrix; I was
Just a very short question about DropBox - is there any way to find
Is there a way to do UI changes in a non-UI thread? Short question.
Short Question : Since DNS is anycast, is there any way for a DNS
Short Question: Is there a way to tell CoreData to use COLLATE while creating
Short question: Is there a simple way in LINQ to objects to get a
Short Question Using my examples below, is there a Pythonic way to share my_object
Short question: Do any of MS's built in Data Objects support INotifyPropertyChanged? Long explination:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.