Short question: I am looking for a way (java) to intercept the Solr request and introduce some additional filtering options provided by my business logic. What structures should I use?
Context: First of all, a little confession: I'm so new to Solra. For me, setting up a server, defining a schema, encoding a functional index index, and then actually monitoring the server returning the correct results - exactly the same as expected! - was already a great achievement for himself. Give me!
However, I am currently working in a corporate project that requires a little more. Roughly speaking, a solr instance must be requested by several thousand users through the same Handler request that returned documents are automatically filtered according to the user's permission level. For example, if user A and superuser B try the same search parameters (even the same url), user B will receive all the files of user A, and then several more. For this, documents are already indexed with the necessary permission level information.
Well, keeping in mind and using Solrβs extensive documentation for newb developers, I tried to create a simple custom Handler query that overrides the handleRequest function to insert the necessary additional parameters into the SolrQueryRequest. Everything is fine and dandy - except that I never see any difference in QueryResponse, the server grossly ignores my little manipulations. After a couple of days, searching the Internet without a hint of the weather, if this is the best approach, I finally decided to go and disturb beautiful people here in StackOverflow.
So, in short, my questions are:
Is this the right approach? Are there other alternatives? I can already understand some of Solr's concepts, but admittedly this is not enough, and it is possible that something is missing.
If so, after changing the query parameters, do I have to do something to force a QueryResponse update? As far as I can tell, this is just an encapsulation of HTTP requests, and I cannot cheat anyone by asking the server after making the changes.
Thanks in advance and really sorry for the long message!
UPDATE
After reading the API many times and especially trial and error, I got a functional solution. However, I still do not understand many of the internal functions of Solr, so I will still be grateful for the enlightenment. Feel free to bash as you see fit, I'm still very knowledgeable about my newbie.
The relevant part of the solution is this function, called with overrideen 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 has not been changed in any way, and instead a filter is applied that contains the user's PermissionLevel. However, why is there no next alternative job? The search query works fine when applied in the standard requestHandler, while in this case it simply does not fall into 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);
}