src/main/java/ch/uzh/ifi/seal/ase/cscc/index/AbstractInvertedIndex.java
public Set<IndexDocument> search(IndexDocument doc) {
        Set<IndexDocument> answers = new HashSet<>();
        try {
            BooleanQuery.Builder boolQueryBuilder = new BooleanQuery.Builder();
            boolQueryBuilder.setMinimumNumberShouldMatch(1);
            Query queryForType = new TermQuery(new Term(TYPE_FIELD, doc.getType()));
            boolQueryBuilder.add(queryForType, BooleanClause.Occur.MUST);
            for (String termStr : doc.getOverallContext()) {
                Term term = new Term(OVERALL_CONTEXT_FIELD, termStr);
                Query queryForOverallContext = new TermQuery(term);
                boolQueryBuilder.add(queryForOverallContext, BooleanClause.Occur.SHOULD);
            }
            Query boolQuery = boolQueryBuilder.build();
            List<Integer> docs = new ArrayList<>();
            Collector collector = new Collector() {
                @Override
                public LeafCollector getLeafCollector(LeafReaderContext context) throws IOException {
                    return new LeafCollector() {
                        @Override
                        public void setScorer(Scorer scorer) throws IOException {

                        }

                        @Override
                        public void collect(int doc) throws IOException {
                            docs.add(doc);
                        }
                    };
                }

                @Override
                public boolean needsScores() {
                    return false;
                }
            };
            searcher.search(boolQuery, collector);
            for (Integer luceneDocID : docs) {
                Document luceneDoc = searcher.doc(luceneDocID);
                String docID = luceneDoc.get(DOC_ID_FIELD);
//                System.out.println(docID);
                IndexDocument matchingDoc = deserializeIndexDocument(docID);
                answers.add(matchingDoc);
            }
        } catch (IndexNotFoundException e) {
            // if there is no inverted index structure for the type we're looking for we can't make a
            // completion recommendation
//            System.out.println("INDEX NOT AVAILABLE FOR TYPE " + doc.getType() + ". NO SUGGESTION POSSIBLE!");
        } catch (IOException e) {
            e.printStackTrace();
            System.exit(1); // exit on IOException
        }
        return answers;
    }
/**
     * Searches the Lucene index for documents which match doc's type and which contain similar terms in the overall
     * context as doc.
     * The query equals a boolean OR query of all terms in the overall context of doc.
     *
     * @param doc document for which to find similar documents
     * @return documents which are similar to doc, i.e. documents whose overall context has at least one term in
     * common with doc's overall context
     */
Searches the Lucene index for documents which match doc's type and which contain similar terms in the overall
context as doc.
The query equals a boolean OR query of all terms in the overall context of doc.

@param doc document for which to find similar documents
@return documents which are similar to doc, i.e. documents whose overall context has at least one term in
common with doc's overall context
Searches the Lucene index for documents which match doc ' s type and which contain similar terms in the overall context as doc . The query equals a boolean OR query of all terms in the overall context of doc . @param doc document for which to find similar documents @return documents which are similar to doc i . e . documents whose overall context has at least one term in common with doc ' s overall context
public Set<IndexDocument> search(IndexDocument doc) {
        Set<IndexDocument> answers = new HashSet<>();
        try {
            BooleanQuery.Builder boolQueryBuilder = new BooleanQuery.Builder();
            boolQueryBuilder.setMinimumNumberShouldMatch(1);
            Query queryForType = new TermQuery(new Term(TYPE_FIELD, doc.getType()));
            boolQueryBuilder.add(queryForType, BooleanClause.Occur.MUST);
            for (String termStr : doc.getOverallContext()) {
                Term term = new Term(OVERALL_CONTEXT_FIELD, termStr);
                Query queryForOverallContext = new TermQuery(term);
                boolQueryBuilder.add(queryForOverallContext, BooleanClause.Occur.SHOULD);
            }
            Query boolQuery = boolQueryBuilder.build();
            List<Integer> docs = new ArrayList<>();
            Collector collector = new Collector() {
                @Override
                public LeafCollector getLeafCollector(LeafReaderContext context) throws IOException {
                    return new LeafCollector() {
                        @Override
                        public void setScorer(Scorer scorer) throws IOException {
                        }
                        @Override
                        public void collect(int doc) throws IOException {
                            docs.add(doc);
                        }
                    };
                }
                @Override
                public boolean needsScores() {
                    return false;
                }
            };
            searcher.search(boolQuery, collector);
            for (Integer luceneDocID : docs) {
                Document luceneDoc = searcher.doc(luceneDocID);
                String docID = luceneDoc.get(DOC_ID_FIELD);
                IndexDocument matchingDoc = deserializeIndexDocument(docID);
                answers.add(matchingDoc);
            }
        } catch (IndexNotFoundException e) {
        } catch (IOException e) {
            e.printStackTrace();
            System.exit(1); 
        }
        return answers;
    }
public Set < IndexDocument > search ( IndexDocument doc ) { Set < IndexDocument > answers = new HashSet < > ( ) ; try { BooleanQuery . Builder boolQueryBuilder = new BooleanQuery . Builder ( ) ; boolQueryBuilder . setMinimumNumberShouldMatch ( 1 ) ; Query queryForType = new TermQuery ( new Term ( TYPE_FIELD , doc . getType ( ) ) ) ; boolQueryBuilder . add ( queryForType , BooleanClause . Occur . MUST ) ; for ( String termStr : doc . getOverallContext ( ) ) { Term term = new Term ( OVERALL_CONTEXT_FIELD , termStr ) ; Query queryForOverallContext = new TermQuery ( term ) ; boolQueryBuilder . add ( queryForOverallContext , BooleanClause . Occur . SHOULD ) ; } Query boolQuery = boolQueryBuilder . build ( ) ; List < Integer > docs = new ArrayList < > ( ) ; Collector collector = new Collector ( ) { @ Override public LeafCollector getLeafCollector ( LeafReaderContext context ) throws IOException { return new LeafCollector ( ) { @ Override public void setScorer ( Scorer scorer ) throws IOException { } @ Override public void collect ( int doc ) throws IOException { docs . add ( doc ) ; } } ; } @ Override public boolean needsScores ( ) { return false ; } } ; searcher . search ( boolQuery , collector ) ; for ( Integer luceneDocID : docs ) { Document luceneDoc = searcher . doc ( luceneDocID ) ; String docID = luceneDoc . get ( DOC_ID_FIELD ) ; IndexDocument matchingDoc = deserializeIndexDocument ( docID ) ; answers . add ( matchingDoc ) ; } } catch ( IndexNotFoundException e ) { } catch ( IOException e ) { e . printStackTrace ( ) ; System . exit ( 1 ) ; } return answers ; }
Searches the Lucene index for documents which match doc's type and which contain similar terms in the overall
 context as doc.
Searches the Lucene index for documents which match doc ' s type and which contain similar terms in the overall context as doc .
//                System.out.println(docID); // if there is no inverted index structure for the type we're looking for we can't make a // completion recommendation //            System.out.println("INDEX NOT AVAILABLE FOR TYPE " + doc.getType() + ". NO SUGGESTION POSSIBLE!"); // exit on IOException