public CategoryHits[] categorize(Reader reader) throws IOException { Query query = moreLikeThis.like(reader); HashMap<String, CategoryHits> categoryHash = new HashMap<String, CategoryHits>(25); for (ScoreDoc sd: indexSearcher.search(query, maxResults).scoreDocs) { String cat = getDocClass(sd.doc); if (cat == null) continue; CategoryHits ch = categoryHash.get(cat); if (ch == null) { ch = new CategoryHits(); ch.setLabel(cat); categoryHash.put(cat, ch); } ch.incrementScore(sd.score); } SortedSet<CategoryHits> sortedCats = new TreeSet<CategoryHits>(CategoryHits.byScoreComparator()); sortedCats.addAll(categoryHash.values()); return sortedCats.toArray(new CategoryHits[0]); }
public DocListAndSet getMoreLikeThis( Reader reader, int start, int rows, List<Query> filters, List<InterestingTerm> terms, int flags ) throws IOException { mltquery = mlt.like(reader); setBoosts(mltquery); if( terms != null ) { fillInterestingTermsFromMLTQuery( mltquery, terms ); } DocListAndSet results = new DocListAndSet(); if (this.needDocSet) { results = searcher.getDocListAndSet(mltquery, filters, null, start, rows, flags); } else { results.docList = searcher.getDocList(mltquery, filters, null, start, rows, flags); } return results; }
public SearchEngineQuery toQuery() { if (!propertiesSet) { moreLikeThis.setFieldNames(new String[]{searchEngine.getSearchEngineFactory().getAllProperty()}); } try { Query query; if (reader != null) { query = moreLikeThis.like(reader); } else { BooleanQuery boolQuery = new BooleanQuery(); boolQuery.add(moreLikeThis.like(resource.getDocNum()), BooleanClause.Occur.MUST); boolQuery.add(ResourceHelper.buildResourceLoadQuery(resource.getResourceKey()), BooleanClause.Occur.MUST_NOT); query = boolQuery; } return new LuceneSearchEngineQuery(searchEngineFactory, query); } catch (IOException e) { throw new SearchEngineException("Failed to find queries like [" + idResource + "]", e); } }
public DocListAndSet getMoreLikeThis( int id, int start, int rows, List<Query> filters, List<InterestingTerm> terms, int flags ) throws IOException { Document doc = reader.document(id); mltquery = mlt.like(id); setBoosts(mltquery); if( terms != null ) { fillInterestingTermsFromMLTQuery( mltquery, terms ); } // exclude current document from results BooleanQuery mltQuery = new BooleanQuery(); mltQuery.add(mltquery, BooleanClause.Occur.MUST); mltQuery.add( new TermQuery(new Term(uniqueKeyField.getName(), uniqueKeyField.getType().storedToIndexed(doc.getFieldable(uniqueKeyField.getName())))), BooleanClause.Occur.MUST_NOT); DocListAndSet results = new DocListAndSet(); if (this.needDocSet) { results = searcher.getDocListAndSet(mltQuery, filters, null, start, rows, flags); } else { results.docList = searcher.getDocList(mltQuery, filters, null, start, rows, flags); } return results; }