src/retrieval based query topic analysis/src/edu/virginia/cs/index/Searcher.java
private SearchResult runSearch(Query luceneQuery, SearchQuery searchQuery) {
        try {
            TopDocs docs = indexSearcher.search(luceneQuery, searchQuery.fromDoc() + searchQuery.numResults());
            ScoreDoc[] hits = docs.scoreDocs;
            String field = searchQuery.fields().get(0);

            SearchResult searchResult = new SearchResult(searchQuery, docs.totalHits);
            for (ScoreDoc hit : hits) {
                Document doc = indexSearcher.doc(hit.doc);
                ResultDoc rdoc = new ResultDoc(hit.doc);

                String highlighted;
                try {
                    Highlighter highlighter = new Highlighter(formatter, new QueryScorer(luceneQuery));
                    String contents = doc.getField(field).stringValue();
                    rdoc.content(contents);
                    rdoc.url(doc.getField("url").stringValue());
                    rdoc.topic(doc.getField("topic").stringValue());
                    String[] snippets = highlighter.getBestFragments(analyzer, field, contents, NUM_FRAGMENTS);
                    highlighted = createOneSnippet(snippets);
                } catch (InvalidTokenOffsetsException ex) {
                    Logger.getLogger(Searcher.class.getName()).log(Level.SEVERE, null, ex);
                    highlighted = "(no snippets yet)";
                }

                searchResult.addResult(rdoc);
                searchResult.setSnippet(rdoc, highlighted);
            }

            searchResult.trimResults(searchQuery.fromDoc());
            return searchResult;

        } catch (IOException ex) {
            Logger.getLogger(Searcher.class.getName()).log(Level.SEVERE, null, ex);
        }
        return new SearchResult(searchQuery);
    }
/**
     * Performs the actual Lucene search.
     *
     * @param luceneQuery
     * @param numResults
     * @return the SearchResult
     */
Performs the actual Lucene search.
@param luceneQuery
@param numResults
@return the SearchResult
Performs the actual Lucene search . @param luceneQuery @param numResults @return the SearchResult
private SearchResult runSearch(Query luceneQuery, SearchQuery searchQuery) {
        try {
            TopDocs docs = indexSearcher.search(luceneQuery, searchQuery.fromDoc() + searchQuery.numResults());
            ScoreDoc[] hits = docs.scoreDocs;
            String field = searchQuery.fields().get(0);
            SearchResult searchResult = new SearchResult(searchQuery, docs.totalHits);
            for (ScoreDoc hit : hits) {
                Document doc = indexSearcher.doc(hit.doc);
                ResultDoc rdoc = new ResultDoc(hit.doc);
                String highlighted;
                try {
                    Highlighter highlighter = new Highlighter(formatter, new QueryScorer(luceneQuery));
                    String contents = doc.getField(field).stringValue();
                    rdoc.content(contents);
                    rdoc.url(doc.getField("url").stringValue());
                    rdoc.topic(doc.getField("topic").stringValue());
                    String[] snippets = highlighter.getBestFragments(analyzer, field, contents, NUM_FRAGMENTS);
                    highlighted = createOneSnippet(snippets);
                } catch (InvalidTokenOffsetsException ex) {
                    Logger.getLogger(Searcher.class.getName()).log(Level.SEVERE, null, ex);
                    highlighted = "(no snippets yet)";
                }
                searchResult.addResult(rdoc);
                searchResult.setSnippet(rdoc, highlighted);
            }
            searchResult.trimResults(searchQuery.fromDoc());
            return searchResult;
        } catch (IOException ex) {
            Logger.getLogger(Searcher.class.getName()).log(Level.SEVERE, null, ex);
        }
        return new SearchResult(searchQuery);
    }
private SearchResult runSearch ( Query luceneQuery , SearchQuery searchQuery ) { try { TopDocs docs = indexSearcher . search ( luceneQuery , searchQuery . fromDoc ( ) + searchQuery . numResults ( ) ) ; ScoreDoc [ ] hits = docs . scoreDocs ; String field = searchQuery . fields ( ) . get ( 0 ) ; SearchResult searchResult = new SearchResult ( searchQuery , docs . totalHits ) ; for ( ScoreDoc hit : hits ) { Document doc = indexSearcher . doc ( hit . doc ) ; ResultDoc rdoc = new ResultDoc ( hit . doc ) ; String highlighted ; try { Highlighter highlighter = new Highlighter ( formatter , new QueryScorer ( luceneQuery ) ) ; String contents = doc . getField ( field ) . stringValue ( ) ; rdoc . content ( contents ) ; rdoc . url ( doc . getField ( "url" ) . stringValue ( ) ) ; rdoc . topic ( doc . getField ( "topic" ) . stringValue ( ) ) ; String [ ] snippets = highlighter . getBestFragments ( analyzer , field , contents , NUM_FRAGMENTS ) ; highlighted = createOneSnippet ( snippets ) ; } catch ( InvalidTokenOffsetsException ex ) { Logger . getLogger ( Searcher . class . getName ( ) ) . log ( Level . SEVERE , null , ex ) ; highlighted = "(no snippets yet)" ; } searchResult . addResult ( rdoc ) ; searchResult . setSnippet ( rdoc , highlighted ) ; } searchResult . trimResults ( searchQuery . fromDoc ( ) ) ; return searchResult ; } catch ( IOException ex ) { Logger . getLogger ( Searcher . class . getName ( ) ) . log ( Level . SEVERE , null , ex ) ; } return new SearchResult ( searchQuery ) ; }
Performs the actual Lucene search.
Performs the actual Lucene search .