private void copy(MoreLikeThis moreLikeThis) { moreLikeThis.setAnalyzer(this.moreLikeThis.getAnalyzer()); moreLikeThis.setBoost(this.moreLikeThis.isBoost()); moreLikeThis.setFieldNames(this.moreLikeThis.getFieldNames()); moreLikeThis.setMaxNumTokensParsed(this.moreLikeThis.getMaxNumTokensParsed()); moreLikeThis.setMaxQueryTerms(this.moreLikeThis.getMaxQueryTerms()); moreLikeThis.setMaxWordLen(this.moreLikeThis.getMaxWordLen()); moreLikeThis.setMinDocFreq(this.moreLikeThis.getMinDocFreq()); moreLikeThis.setMinTermFreq(this.moreLikeThis.getMinTermFreq()); moreLikeThis.setMinWordLen(this.moreLikeThis.getMinWordLen()); moreLikeThis.setStopWords(this.moreLikeThis.getStopWords()); } }
public SearchEngineQueryBuilder.SearchEngineMoreLikeThisQueryBuilder addProperty(String property) { propertiesSet = true; if (moreLikeThis.getFieldNames() == null) { moreLikeThis.setFieldNames(new String[]{property}); } else { String[] newNames = new String[moreLikeThis.getFieldNames().length + 1]; System.arraycopy(moreLikeThis.getFieldNames(), 0, newNames, 0, moreLikeThis.getFieldNames().length); newNames[newNames.length -1] = property; moreLikeThis.setFieldNames(newNames); } return this; }
public MoreLikeThisHelper( SolrParams params, SolrIndexSearcher searcher ) { this.searcher = searcher; this.reader = searcher.getReader(); this.uniqueKeyField = searcher.getSchema().getUniqueKeyField(); this.needDocSet = params.getBool(FacetParams.FACET,false); SolrParams required = params.required(); String[] fields = splitList.split( required.get(MoreLikeThisParams.SIMILARITY_FIELDS) ); if( fields.length < 1 ) { throw new SolrException( SolrException.ErrorCode.BAD_REQUEST, "MoreLikeThis requires at least one similarity field: "+MoreLikeThisParams.SIMILARITY_FIELDS ); } this.mlt = new MoreLikeThis( reader ); // TODO -- after LUCENE-896, we can use , searcher.getSimilarity() ); mlt.setFieldNames(fields); mlt.setAnalyzer( searcher.getSchema().getAnalyzer() ); // configurable params mlt.setMinTermFreq( params.getInt(MoreLikeThisParams.MIN_TERM_FREQ, MoreLikeThis.DEFAULT_MIN_TERM_FREQ)); mlt.setMinDocFreq( params.getInt(MoreLikeThisParams.MIN_DOC_FREQ, MoreLikeThis.DEFAULT_MIN_DOC_FREQ)); mlt.setMinWordLen( params.getInt(MoreLikeThisParams.MIN_WORD_LEN, MoreLikeThis.DEFAULT_MIN_WORD_LENGTH)); mlt.setMaxWordLen( params.getInt(MoreLikeThisParams.MAX_WORD_LEN, MoreLikeThis.DEFAULT_MAX_WORD_LENGTH)); mlt.setMaxQueryTerms( params.getInt(MoreLikeThisParams.MAX_QUERY_TERMS, MoreLikeThis.DEFAULT_MAX_QUERY_TERMS)); mlt.setMaxNumTokensParsed(params.getInt(MoreLikeThisParams.MAX_NUM_TOKENS_PARSED, MoreLikeThis.DEFAULT_MAX_NUM_TOKENS_PARSED)); mlt.setBoost( params.getBool(MoreLikeThisParams.BOOST, false ) ); boostFields = SolrPluginUtils.parseFieldBoosts(params.getParams(MoreLikeThisParams.QF)); }
private void init(LuceneSearchEngine searchEngine, LuceneSearchEngineFactory searchEngineFactory) { this.searchEngine = searchEngine; this.searchEngineFactory = searchEngineFactory; LuceneSearchEngineInternalSearch internalSearch = (LuceneSearchEngineInternalSearch) searchEngine.internalSearch(subIndexes, aliases); this.moreLikeThis = new MoreLikeThis(internalSearch.getReader()); this.moreLikeThis.setFieldNames(null); this.moreLikeThis.setAnalyzer(searchEngine.getSearchEngineFactory().getAnalyzerManager().getSearchAnalyzer()); }
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 void setNgramSize(int size) { if (size <= 1) return; Analyzer a = moreLikeThis.getAnalyzer(); ShingleAnalyzerWrapper sw; if (a instanceof ShingleAnalyzerWrapper) { sw = (ShingleAnalyzerWrapper) a; } else { sw = new ShingleAnalyzerWrapper(a); moreLikeThis.setAnalyzer(sw); } sw.setMaxShingleSize(size); sw.setMinShingleSize(size); }
public MoreLikeThisCategorizer(IndexReader indexReader, String categoryFieldName) throws IOException { this.indexReader = indexReader; this.indexSearcher = new IndexSearcher(indexReader); this.moreLikeThis = new MoreLikeThis(indexReader); this.categoryFieldName = categoryFieldName; loadCategoriesFromIndex(); }
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 SearchEngineQueryBuilder.SearchEngineMoreLikeThisQueryBuilder setProperties(String[] properties) { propertiesSet = true; moreLikeThis.setFieldNames(properties); return this; }
public void setAnalyzer(Analyzer analyzer) { moreLikeThis.setAnalyzer(analyzer); }
public SearchEngineQueryBuilder.SearchEngineMoreLikeThisQueryBuilder setMaxNumTokensParsed(int maxNumTokensParsed) { moreLikeThis.setMaxNumTokensParsed(maxNumTokensParsed); return this; }
public SearchEngineQueryBuilder.SearchEngineMoreLikeThisQueryBuilder setMaxWordLen(int maxWordLen) { moreLikeThis.setMaxWordLen(maxWordLen); return this; }
public SearchEngineQueryBuilder.SearchEngineMoreLikeThisQueryBuilder setBoost(boolean boost) { moreLikeThis.setBoost(boost); return this; }
public SearchEngineQueryBuilder.SearchEngineMoreLikeThisQueryBuilder setMaxQueryTerms(int maxQueryTerms) { moreLikeThis.setMaxQueryTerms(maxQueryTerms); return this; }
? null : new ArrayList<InterestingTerm>( mlt.mlt.getMaxQueryTerms() );
public SearchEngineQueryBuilder.SearchEngineMoreLikeThisQueryBuilder setAliases(String[] aliases) { this.aliases = aliases; LuceneSearchEngineInternalSearch internalSearch = (LuceneSearchEngineInternalSearch) searchEngine.internalSearch(subIndexes, aliases); MoreLikeThis moreLikeThis = new MoreLikeThis(internalSearch.getReader()); copy(moreLikeThis); this.moreLikeThis = moreLikeThis; return this; }
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 void setFieldNames(String[] fieldNames) { moreLikeThis.setFieldNames(fieldNames); }
public SearchEngineQueryBuilder.SearchEngineMoreLikeThisQueryBuilder setAnalyzer(String analyzer) { moreLikeThis.setAnalyzer(searchEngine.getSearchEngineFactory().getAnalyzerManager().getAnalyzerMustExist(analyzer)); return this; }
public SearchEngineQueryBuilder.SearchEngineMoreLikeThisQueryBuilder setSubIndexes(String[] subIndexes) { this.subIndexes = subIndexes; LuceneSearchEngineInternalSearch internalSearch = (LuceneSearchEngineInternalSearch) searchEngine.internalSearch(subIndexes, aliases); MoreLikeThis moreLikeThis = new MoreLikeThis(internalSearch.getReader()); copy(moreLikeThis); this.moreLikeThis = moreLikeThis; return this; }