Java Code Examples for org.apache.lucene.queries.mlt.MoreLikeThis#setMinDocFreq()
The following examples show how to use
org.apache.lucene.queries.mlt.MoreLikeThis#setMinDocFreq() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SearchImpl.java From lucene-solr with Apache License 2.0 | 6 votes |
@Override public Query mltQuery(int docid, MLTConfig mltConfig, Analyzer analyzer) { MoreLikeThis mlt = new MoreLikeThis(reader); mlt.setAnalyzer(analyzer); mlt.setFieldNames(mltConfig.getFieldNames()); mlt.setMinDocFreq(mltConfig.getMinDocFreq()); mlt.setMaxDocFreq(mltConfig.getMaxDocFreq()); mlt.setMinTermFreq(mltConfig.getMinTermFreq()); try { return mlt.like(docid); } catch (IOException e) { throw new LukeException("Failed to create MLT query for doc: " + docid); } }
Example 2
Source File: ContextAnalyzerIndex.java From modernmt with Apache License 2.0 | 4 votes |
public ContextVector getContextVector(UUID user, LanguageDirection direction, Corpus queryDocument, int limit, Rescorer rescorer) throws IOException { String contentFieldName = DocumentBuilder.makeContentFieldName(direction); IndexSearcher searcher = this.getIndexSearcher(); IndexReader reader = searcher.getIndexReader(); // Get matching documents int rawLimit = limit < MIN_RESULT_BATCH ? MIN_RESULT_BATCH : limit; MoreLikeThis mlt = new MoreLikeThis(reader); mlt.setFieldNames(new String[]{contentFieldName}); mlt.setMinDocFreq(0); mlt.setMinTermFreq(1); mlt.setMinWordLen(2); mlt.setBoost(true); mlt.setAnalyzer(analyzer); TopScoreDocCollector collector = TopScoreDocCollector.create(rawLimit, true); Reader queryDocumentReader = queryDocument.getRawContentReader(); try { Query mltQuery = mlt.like(contentFieldName, queryDocumentReader); BooleanQuery ownerQuery = new BooleanQuery(); if (user == null) { ownerQuery.add(DocumentBuilder.makePublicOwnerMatchingQuery(), BooleanClause.Occur.MUST); } else { ownerQuery.add(DocumentBuilder.makePublicOwnerMatchingQuery(), BooleanClause.Occur.SHOULD); ownerQuery.add(DocumentBuilder.makeOwnerMatchingQuery(user), BooleanClause.Occur.SHOULD); ownerQuery.setMinimumNumberShouldMatch(1); } FilteredQuery query = new FilteredQuery(mltQuery, new QueryWrapperFilter(ownerQuery)); searcher.search(query, collector); } finally { IOUtils.closeQuietly(queryDocumentReader); } ScoreDoc[] topDocs = collector.topDocs().scoreDocs; // Rescore result if (rescorer != null) { Document referenceDocument = DocumentBuilder.newInstance(direction, queryDocument); rescorer.rescore(reader, this.analyzer, topDocs, referenceDocument, contentFieldName); } // Build result ContextVector.Builder resultBuilder = new ContextVector.Builder(topDocs.length); resultBuilder.setLimit(limit); for (ScoreDoc topDocRef : topDocs) { Document topDoc = searcher.doc(topDocRef.doc); long memory = DocumentBuilder.getMemory(topDoc); resultBuilder.add(memory, topDocRef.score); } return resultBuilder.build(); }