Hi everyone, I'm modifying a existing custom request handler for an open source project, and am looking for some help with a compile error around an anonymous SimpleCollector. The build failure message from ant and the source of the specific method are below. I am compiling on a Mac with Java 1.8 and Solr 6.4.2. There are two things I do not understand.
First: [javac] /Users/tod/src/vufind-browse-handler/browse-handler/java/org/vufind/solr/handler/BrowseRequestHandler.java:445: error: <anonymous org.vufind.solr.handler.BibDB$1> is not abstract and does not override abstract method setNextReader(AtomicReaderContext) in Collector [javac] db.search(q, new SimpleCollector() { Based on the javadoc, neither SimpleCollector nor Collector define a setNextReader(AtomicReaderContext) method. Grepping through the Lucene 6.4.2 source reveals neither a setNextReader method (though maybe a couple archaic comments), nor an AtomicReaderContext class or interface. Second: [javac] method IndexSearcher.search(Query,Collector) is not applicable [javac] (argument mismatch; <anonymous SimpleCollector> cannot be converted to Collector) How is it that SimpleCollector cannot be converted to Collector? Perhaps this is just a consequence of the first error. Any help getting past this compile problem would be most welcome! -Tod Build failure message: build-handler: [mkdir] Created dir: /Users/tod/src/vufind-browse-handler/build/browse-handler [javac] Compiling 1 source file to /Users/tod/src/vufind-browse-handler/build/browse-handler [javac] /Users/tod/src/vufind-browse-handler/browse-handler/java/org/vufind/solr/handler/BrowseRequestHandler.java:445: error: <anonymous org.vufind.solr.handler.BibDB$1> is not abstract and does not override abstract method setNextReader(AtomicReaderContext) in Collector [javac] db.search(q, new SimpleCollector() { [javac] ^ [javac] /Users/tod/src/vufind-browse-handler/browse-handler/java/org/vufind/solr/handler/BrowseRequestHandler.java:445: error: no suitable method found for search(TermQuery,<anonymous SimpleCollector>) [javac] db.search(q, new SimpleCollector() { [javac] ^ [javac] method IndexSearcher.search(Query,int) is not applicable [javac] (argument mismatch; <anonymous SimpleCollector> cannot be converted to int) [javac] method IndexSearcher.search(Query,Filter,int) is not applicable [javac] (actual and formal argument lists differ in length) [javac] method IndexSearcher.search(Query,Filter,Collector) is not applicable [javac] (actual and formal argument lists differ in length) [javac] method IndexSearcher.search(Query,Collector) is not applicable [javac] (argument mismatch; <anonymous SimpleCollector> cannot be converted to Collector) [javac] method IndexSearcher.search(Query,Filter,int,Sort) is not applicable [javac] (actual and formal argument lists differ in length) [javac] method IndexSearcher.search(Query,Filter,int,Sort,boolean,boolean) is not applicable [javac] (actual and formal argument lists differ in length) [javac] method IndexSearcher.search(Query,int,Sort) is not applicable [javac] (actual and formal argument lists differ in length) [javac] method IndexSearcher.search(Weight,ScoreDoc,int) is not applicable [javac] (actual and formal argument lists differ in length) [javac] method IndexSearcher.search(List<AtomicReaderContext>,Weight,ScoreDoc,int) is not applicable [javac] (actual and formal argument lists differ in length) [javac] method IndexSearcher.search(Weight,int,Sort,boolean,boolean) is not applicable [javac] (actual and formal argument lists differ in length) [javac] method IndexSearcher.search(Weight,FieldDoc,int,Sort,boolean,boolean,boolean) is not applicable [javac] (actual and formal argument lists differ in length) [javac] method IndexSearcher.search(List<AtomicReaderContext>,Weight,FieldDoc,int,Sort,boolean,boolean,boolean) is not applicable [javac] (actual and formal argument lists differ in length) [javac] method IndexSearcher.search(List<AtomicReaderContext>,Weight,Collector) is not applicable [javac] (actual and formal argument lists differ in length) [javac] 2 errors Problem method: /** * * Function to retrieve the doc ids when there is a building limit * This retrieves the doc ids for an individual heading * * Need to add a filter query to limit the results from Solr * * Includes functionality to retrieve additional info * like titles for call numbers, possibly ISBNs * * @param heading string of the heading to use for finding matching * @param fields docs colon-separated string of Solr fields * to return for use in the browse display * @param maxBibListSize maximum numbers of records to check for fields * @return return a map of Solr ids and extra bib info */ public Map<String, List<Collection<String>>> matchingIDs(String heading, String fields, int maxBibListSize) throws Exception { TermQuery q = new TermQuery(new Term(field, heading)); //Log.info<http://Log.info>("matchingIDs: '" + heading + "': '" + field); // bibinfo values are List<Collection> because some extra fields // may be multi-valued. // Note: it may be time for bibinfo to become a class... final Map<String, List<Collection<String>>> bibinfo = new HashMap<> (); final String[] bibFieldList = fields.split(":"); for (String bibField : bibFieldList) { bibinfo.put(bibField, new ArrayList<Collection<String>> ()); } db.search(q, new SimpleCollector() { // <== Compiler error here private LeafReaderContext context; public void setScorer(Scorer scorer) { } public boolean acceptsDocsOutOfOrder() { return true; } public boolean needsScores() { return false; } public void doSetNextReader(LeafReaderContext context) { this.context = context; } public void collect(int docnum) { int docid = docnum + context.docBase; try { Document doc = db.getIndexReader().document(docid); for (String bibField : bibFieldList) { String[] vals = doc.getValues(bibField); if (vals.length > 0) { Collection<String> valSet = new LinkedHashSet<> (); for (String val : vals) { valSet.add(val); } bibinfo.get(bibField).add(valSet); } } } catch (org.apache.lucene.index.CorruptIndexException e) { Log.info<http://Log.info>("CORRUPT INDEX EXCEPTION. EEK! - " + e); } catch (Exception e) { Log.info<http://Log.info>("Exception thrown: " + e); } } }); return bibinfo; }