if (!(((SolrIndexReader) rb.req.getSearcher().getIndexReader()).getWrappedReader() instanceof lucandra.IndexReader)) return false; if (rb.req.getParams().getBool(ShardParams.IS_SHARD, false)) String indexName = (String) rb.req.getContext().get("solandra-index"); IndexReader reader = (IndexReader) ((SolrIndexReader) rb.req.getSearcher().getIndexReader()).getWrappedReader(); IndexReader reader = (IndexReader) ((SolrIndexReader) rb.req.getSearcher().getIndexReader()) .getWrappedReader();
/** * Retrieve the {@link Document} instance corresponding to the document id. */ public Document doc(int i) throws IOException { return doc(i, (Set<String>)null); }
SolrHighlighter highligher = rb.req.getCore().getHighlighter(); if (highligher.isHighlightingEnabled(rb.req.getParams())) SchemaField keyField = rb.req.getSearcher().getSchema().getUniqueKeyField(); if (null != keyField) if (!returnFields.contains(keyField)) fieldFilter.add(ByteBufferUtil.bytes(keyField.getName())); rb.req.getSearcher().getReader().document(docIds.get(0), selector);
SolrIndexSearcher searcher = req.getSearcher(); throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "'start' parameter cannot be negative"); long timeAllowed = (long)params.getInt( CommonParams.TIME_ALLOWED, -1 ); String ids = params.get(ShardParams.IDS); if (ids != null) { SchemaField idField = req.getSchema().getUniqueKeyField(); List<String> idArr = StrUtils.splitSmart(ids, ",", true); int[] luceneIds = new int[idArr.size()]; int docs = 0; for (int i=0; i<idArr.size(); i++) { int id = req.getSearcher().getFirstMatch( new Term(idField.getName(), idField.getType().toInternal(idArr.get(i)))); if (id >= 0) luceneIds[docs++] = id; List<Query> filters = rb.getFilters(); if (filters != null) queries.addAll(filters); res.docSet = searcher.getDocSet(queries); cmd.setTimeAllowed(timeAllowed); SolrIndexSearcher.QueryResult result = new SolrIndexSearcher.QueryResult(); searcher.search(result,cmd); rb.setResult( result );
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Illegal query type. The incoming query must be a Lucene SpanNearQuery and it was a " + origQuery.getClass().getName()); SolrIndexSearcher searcher = rb.req.getSearcher(); IndexReader reader = searcher.getIndexReader(); Spans spans = sQuery.getSpans(reader); addPassage(tvm.passage, rankedPassages, termWeights, bigramWeights, adjWeight, secondAdjWeight, bigramWeight); } catch (CloneNotSupportedException e) { throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Internal error cloning Passage", e); int rows = params.getInt(QA_ROWS, 5); SchemaField uniqField = rb.req.getSchema().getUniqueKeyField(); if (rankedPassages.size() > 0) { int size = Math.min(rows, rankedPassages.size()); idValue = searcher.doc(passage.lDocId, fields).get(idName); } else { idName = "luceneDocId"; passNL.add("field", passage.field); String fldValue = searcher.doc(passage.lDocId, fields).get(passage.field); if (fldValue != null) {
@Override public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception IndexSchema schema = req.getSchema(); SolrIndexSearcher searcher = req.getSearcher(); IndexReader reader = searcher.getReader(); SolrParams params = req.getParams(); int numTerms = params.getInt( NUMTERMS, DEFAULT_COUNT ); Integer docId = params.getInt( DOC_ID ); if( docId == null && params.get( ID ) != null ) { SchemaField uniqueKey = schema.getUniqueKeyField(); String v = uniqueKey.getType().toInternal( params.get(ID) ); Term t = new Term( uniqueKey.getName(), v ); docId = searcher.getFirstMatch( t ); if( docId < 0 ) { throw new SolrException( SolrException.ErrorCode.NOT_FOUND, "Can't find document: "+params.get( ID ) ); throw new SolrException( SolrException.ErrorCode.NOT_FOUND, "Can't find document: "+docId );
this.reader = searcher.getIndexReader(); this.uniqueKeyField = uniqueKeyField; this.needDocSet = params.getBool(FacetParams.FACET,false); SolrParams required = params.required(); String[] fields = splitList.split( required.get(UnsupervisedFeedbackParams.SIMILARITY_FIELDS) ); if( fields.length < 1 ) { throw new SolrException( SolrException.ErrorCode.BAD_REQUEST, "MoreLikeThis requires at least one similarity field: "+ UnsupervisedFeedbackParams.SIMILARITY_FIELDS ); moreLikeThis.setPayloadFields(payloadFields); moreLikeThis.setAnalyzer(searcher.getSchema().getIndexAnalyzer());
public void process(ResponseBuilder rb) throws IOException { SolrParams params = rb.req.getParams(); if (params.getBool(TermsParams.TERMS, false)) { String lowerStr = params.get(TermsParams.TERMS_LOWER, null); String[] fields = params.getParams(TermsParams.TERMS_FIELD); if (fields != null && fields.length > 0) { NamedList terms = new NamedList(); for (int j = 0; j < fields.length; j++) { String field = StringHelper.intern(fields[j]); FieldType ft = raw ? null : rb.req.getSchema().getFieldTypeNoEx(field); if (ft==null) ft = new StrField(); String lower = lowerStr==null ? prefix : (raw ? lowerStr : ft.toInternal(lowerStr)); if (lower == null) lower=""; String upper = upperStr==null ? null : (raw ? upperStr : ft.toInternal(upperStr)); TermEnum termEnum = rb.req.getSearcher().getReader().terms(lowerTerm); //this will be positioned ready to go int i = 0; BoundedTreeSet<CountPair<String, Integer>> queue = (sort ? new BoundedTreeSet<CountPair<String, Integer>>(limit) : null); if (docFreq >= freqmin && docFreq <= freqmax) { String label = raw ? indexedText : ft.indexedToReadable(indexedText); if (sort) { queue.add(new CountPair<String, Integer>(label, docFreq)); throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "No terms.fl parameter specified");
SolrParams params = req.getParams(); if (!isHighlightingEnabled(params)) return null; SolrIndexSearcher searcher = req.getSearcher(); IndexSchema schema = searcher.getSchema(); NamedList fragments = new SimpleOrderedMap(); String[] fieldNames = getHighlightFields(query, req, defaultFields); for (int i = 0; i < docs.size(); i++) { int docId = iterator.nextDoc(); Document doc = searcher.doc(docId, fset); NamedList docSummaries = new SimpleOrderedMap(); for (String fieldName : fieldNames) { TokenStream tvStream = TokenSources.getTokenStream(searcher.getReader(), docId, fieldName); if (tvStream != null) { tots = new TermOffsetsTokenStream(tvStream); if (Boolean.valueOf(req.getParams().get(HighlightParams.USE_PHRASE_HIGHLIGHTER, "true"))) { throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, e); String printId = schema.printableUniqueKey(doc); fragments.add(printId == null ? null : printId, docSummaries);
Query query, final SolrQueryRequest sreq) throws IOException { SolrHighlighter highligher = null; SolrParams solrParams = sreq.getParams(); SolrCore core = sreq.getCore(); String urlField = solrParams.get(CarrotParams.URL_FIELD_NAME, "url"); String titleField = solrParams.get(CarrotParams.TITLE_FIELD_NAME, "title"); String snippetField = solrParams.get(CarrotParams.SNIPPET_FIELD_NAME, titleField); if (StringUtils.isBlank(snippetField)) { throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, CarrotParams.SNIPPET_FIELD_NAME + " must not be blank."); String[] snippetFieldAry = null; if (produceSummary == true) { highligher = core.getHighlighter(); Map args = new HashMap(); snippetFieldAry = new String[]{snippetField}; SolrIndexSearcher searcher = sreq.getSearcher(); List<Document> result = new ArrayList<Document>(docList.size()); FieldSelector fieldSelector = new SetBasedFieldSelector(fieldsToLoad, org.apache.lucene.document.Document doc = searcher.doc(id, fieldSelector); String snippet = getValue(doc, snippetField);
@Override public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception SolrIndexSearcher searcher = req.getSearcher(); SchemaField uniqueKeyField = searcher.getSchema().getUniqueKeyField(); ModifiableSolrParams params = new ModifiableSolrParams(req.getParams()); configureSolrParameters(req, params, uniqueKeyField.getName()); mltFqFilters = getFilters(req, UnsupervisedFeedbackParams.FQ); } catch (SyntaxError e) { throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, e); throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Dice unsupervised feedback handler requires either a query (?q=) to find similar documents.");
public void inform(SolrCore core) String a = initArgs.get( FIELD_TYPE ); if( a != null ) { FieldType ft = core.getSchema().getFieldTypes().get( a ); if( ft == null ) { throw new SolrException( SolrException.ErrorCode.SERVER_ERROR, "Unknown FieldType: '"+a+"' used in QueryElevationComponent" ); analyzer = ft.getQueryAnalyzer(); SchemaField sf = core.getSchema().getUniqueKeyField(); if( sf == null ) { throw new SolrException( SolrException.ErrorCode.SERVER_ERROR, "QueryElevationComponent requires the schema to have a uniqueKeyField" ); idField = StringHelper.intern(sf.getName()); File fC = new File( core.getResourceLoader().getConfigDir(), f ); File fD = new File( core.getDataDir(), f ); if( fC.exists() == fD.exists() ) { try { searchHolder = core.getNewestSearcher(false); IndexReader reader = searchHolder.get().getReader(); getElevationMap( reader, core ); } finally {
SolrQueryRequest req = rb.req; if (rb.doHighlights) { SolrHighlighter highlighter = req.getCore().getHighlighter(); SolrParams params = req.getParams(); defaultHighlightFields = rb.getQparser().getDefaultHighlightFields(); } else { defaultHighlightFields = params.getParams(CommonParams.DF); rb.setHighlightQuery( highlightQuery ); } catch (Exception e) { throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, e); boolean rewrite = !(Boolean.valueOf(req.getParams().get(HighlightParams.USE_PHRASE_HIGHLIGHTER, "true")) && Boolean.valueOf(req.getParams().get(HighlightParams.HIGHLIGHT_MULTI_TERM, "true"))); highlightQuery = rewrite ? highlightQuery.rewrite(req.getSearcher().getReader()) : highlightQuery;
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)); }
@Override @SuppressWarnings("unchecked") public void process(ResponseBuilder rb) throws IOException { SolrParams params = rb.req.getParams(); if (!params.getBool(COMPONENT_NAME, false) || spellCheckers.isEmpty()) { return; String q = params.get(SPELLCHECK_Q); SolrSpellChecker spellChecker = getSpellChecker(params); Collection<Token> tokens = null; q = rb.getQueryString(); if (q == null) { q = params.get(CommonParams.Q); false); NamedList response = new SimpleOrderedMap(); IndexReader reader = rb.req.getSearcher().getReader(); boolean collate = params.getBool(SPELLCHECK_COLLATE, false); SpellingResult spellingResult = spellChecker.getSuggestions(tokens, throw new SolrException(SolrException.ErrorCode.NOT_FOUND, "Specified dictionary does not exist.");
final String[] corpusFilterQueries = req.getParams().getParams("fq"); final SolrIndexSearcher searcher = req.getSearcher(); final Bits docBits; if (corpusFilterQueries != null && corpusFilterQueries.length > 0) { filterQueries.add(qParser.parse()); } catch (SyntaxError e) { throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, e); final DocSet docSet = searcher.getDocSet(filterQueries);//hopefully in the cache docBits = searcher.getSlowAtomicReader().getLiveDocs();
public void process(ResponseBuilder rb) throws IOException { SolrParams params = rb.req.getParams(); if (!params.getBool(COMPONENT_NAME, false)) { return; rb.rsp.add(TERM_VECTORS, termVectors); boolean termFreq = params.getBool(TermVectorParams.TF, false); boolean positions = params.getBool(TermVectorParams.POSITIONS, false); boolean offsets = params.getBool(TermVectorParams.OFFSETS, false); boolean docFreq = params.getBool(TermVectorParams.DF, false); iter = list.iterator(); SolrIndexSearcher searcher = rb.req.getSearcher(); IndexReader reader = searcher.getReader(); IndexSchema schema = rb.req.getSchema(); String uniqFieldName = schema.getUniqueKeyField().getName();
SolrQueryRequest req, SolrQueryResponse res) throws IOException { SolrIndexSearcher searcher = req.getSearcher(); if(!searcher.enableLazyFieldLoading) { SolrHighlighter highligher = req.getCore().getHighlighter(); if(highligher.isHighlightingEnabled(req.getParams())) { for(String field: highligher.getHighlightFields(query, req, null)) fieldFilter.add(field); SchemaField keyField = req.getSearcher().getSchema().getUniqueKeyField(); if(null != keyField) fieldFilter.add(keyField.getName()); searcher.doc(iter.nextDoc(), fieldFilter);
private void doSearch1(SolrDocumentList results, SolrIndexSearcher searcher, String q, Filter filter, int ndocs, SolrQueryRequest req, Map<String,SchemaField> fields, Set<Integer> alreadyFound) throws IOException { // build custom query and extra fields Query query = null; //buildCustomQuery1(q); Map<String,Object> extraFields = new HashMap<String,Object>(); extraFields.put("search_type", "search1"); boolean includeScore = req.getParams().get(CommonParams.FL).contains("score"); int maxDocsPerSearcherType = 0; float maprelScoreCutoff = 2.0f; append(results, searcher.search( query, filter, maxDocsPerSearcherType).scoreDocs, alreadyFound, fields, extraFields, maprelScoreCutoff , searcher.getIndexReader(), includeScore); }
@Override public void process(ResponseBuilder rb) throws IOException { if(isEnabled(rb)){ long startTime = System.currentTimeMillis(); SolrParams params = rb.req.getParams(); int topN = getTopN(params); boolean binary = getBinary(params); boolean logTfs = getLogTfs(params); boolean includeExisting = getIncludeExisting(params); final SolrIndexSearcher searcher = rb.req.getSearcher(); IndexReader ir = searcher.getIndexReader(); Analyzer analyzer = searcher.getSchema().getIndexAnalyzer(); DocListAndSet docs = rb.getResults(); DocIterator iterator = docs.docList.iterator(); String uniqueKeyField = searcher.getSchema().getUniqueKeyField().getName(); NamedList<NamedList<Double>> topPredictions = new NamedList<NamedList<Double>>(); while(iterator.hasNext()) { int docNum = iterator.nextDoc(); Map<String, Map<String,Integer>> tf = getFieldTermFrequencyCounts(fields, ir, analyzer, docNum); NamedList<Double> predictions = predict(tf, topN, binary, logTfs, includeExisting); String uniqueFieldValue = getUniqueKeyFieldValue(ir, analyzer, uniqueKeyField, docNum); topPredictions.add(String.format("%s:%s", uniqueKeyField, uniqueFieldValue), predictions); } long duration = System.currentTimeMillis() - startTime; NamedList<Object> results = new NamedList<Object>(); results.add("Time", duration); results.add("values", topPredictions); rb.rsp.add(getPrefix(), results); } }