@Override protected HashMap<String,Analyzer> analyzerCache() { HashMap<String,Analyzer> cache = new HashMap<String,Analyzer>(); for (SchemaField f : getFields().values()) { Analyzer analyzer = f.getType().getQueryAnalyzer(); cache.put(f.getName(), analyzer); } return cache; }
protected HashMap<String,Analyzer> analyzerCache() { HashMap<String,Analyzer> cache = new HashMap<String,Analyzer>(); for (SchemaField f : getFields().values()) { Analyzer analyzer = f.getType().getAnalyzer(); cache.put(f.getName(), analyzer); } return cache; }
/** * Check if all fields are of type {@link SirenField}. */ private static void checkFieldTypes(final IndexSchema indexSchema, final Map<String, Float> queryFields) { for (final String fieldName : queryFields.keySet()) { final FieldType fieldType = indexSchema.getFieldType(fieldName); if (!(fieldType instanceof SirenField)) { throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "FieldType: " + fieldName + " (" + fieldType.getTypeName() + ") do not support Siren's tree query"); } } }
/** * @param language * @param indexField * @param analyzer * @param fst * @param allowCreation */ protected CorpusInfo(String language, String indexField, String storeField, FieldType fieldType, File fst, boolean allowCreation){ this.language = language; this.indexedField = indexField; this.storedField = storeField; this.fst = fst; this.allowCreation = allowCreation; this.analyzer = fieldType.getAnalyzer(); this.taggingAnalyzer = fieldType.getQueryAnalyzer(); this.fstDate = fst.isFile() ? new Date(fst.lastModified()) : null; } /**
final String indexedField = req.getParams().get("field"); if (indexedField == null) throw new RuntimeException("required param 'field'"); throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, getClass().getSimpleName()+" does not support multiple ContentStreams"); throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, getClass().getSimpleName()+" requires text to be POSTed to it"); initOffsetCorrector(htmlOffsetAdjust, xmlOffsetAdjust, inputString, nonTaggableTags); final SolrIndexSearcher searcher = req.getSearcher(); final FixedBitSet matchDocIdsBS = new FixedBitSet(searcher.maxDoc()); final List tags = new ArrayList(2000); Analyzer analyzer = req.getSchema().getField(indexedField).getType().getQueryAnalyzer(); try (TokenStream tokenStream = analyzer.tokenStream("", inputReader)) { Terms terms = searcher.getSlowAtomicReader().terms(indexedField); if (terms == null) throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, idSchemaField.getType().getValueSource(idSchemaField, null));
SolrParams params = req.getParams(); if (!params.getBool(COMPONENT_NAME, true)) { return; SolrIndexSearcher searcher = req.getSearcher(); throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "'start' parameter cannot be negative"); 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 ); rsp.getToLog().add("hits", rb.getResults().docList.matches());
@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 ); 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 ); info.add( "key", getFieldFlagsKey() ); info.add( "NOTE", "Document Frequency (df) is not updated when a document is marked for deletion. df values include deleted documents." ); rsp.add( "info", info ); rsp.setHttpCaching(false);
LOG.info("Initializing spell checkers"); boolean hasDefault = false; for (int i = 0; i < initParams.size(); i++) { if (initParams.getName(i).equals("spellchecker")) { NamedList spellchecker = (NamedList) initParams.getVal(i); String className = (String) spellchecker.get("classname"); if (className == null) IndexSchema schema = core.getSchema(); String fieldTypeName = (String) initParams.get("queryAnalyzerFieldType"); FieldType fieldType = schema.getFieldTypes().get(fieldTypeName); Analyzer analyzer = fieldType == null ? new WhitespaceAnalyzer() : fieldType.getQueryAnalyzer();
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); NamedList fieldTerms = new NamedList(); terms.add(field, fieldTerms); Term lowerTestTerm = termEnum.term(); 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");
SchemaField uniqueKeyField = schema.getUniqueKeyField(); NamedList<Object> result = new SimpleOrderedMap<Object>(); result.add(document.getFieldValue(uniqueKeyField.getName()).toString(), theTokens); for (String name : document.getFieldNames()) { SchemaField field = schema.getField(name); if (!field.indexed()) { continue; theTokens.add(name, fieldTokens); FieldType fieldType = schema.getFieldType(name); List<Token> tokens = analyzeValue(request.getQuery(), fieldType.getQueryAnalyzer()); for (Token token : tokens) { termsToMatch.add(token.term()); AnalysisContext analysisContext = new AnalysisContext(fieldType, fieldType.getQueryAnalyzer(), Collections.EMPTY_SET); NamedList<List<NamedList>> tokens = analyzeValue(request.getQuery(), analysisContext); fieldTokens.add("query", tokens); } catch (Exception e) { Analyzer analyzer = fieldType.getAnalyzer(); AnalysisContext analysisContext = new AnalysisContext(fieldType, analyzer, termsToMatch); Collection<Object> fieldValues = document.getFieldValues(name);
solrDocumentList.setNumFound(visibleHitCount); queryResponse.getResponse().setVal( queryResponse.getResponse().indexOf(QUERY_RESPONSE_NAME, 0), solrDocumentList); queryResponse.getResponseHeader().setVal( queryResponse.getResponseHeader().indexOf(QUERY_TIME_NAME, 0), new Integer(new Long(System.currentTimeMillis() - startTime).intValue())); rb.doHighlights = true; DocListAndSet res = new DocListAndSet(); SchemaField idField = OpenCms.getSearchManager().getSolrServerConfiguration().getSolrSchema().getUniqueKeyField(); for (SolrDocument doc : solrDocumentList) { String idString = (String)doc.getFirstValue(CmsSearchField.FIELD_ID); int id = solrQueryRequest.getSearcher().getFirstMatch( new Term(idField.getName(), idField.getType().toInternal(idString))); luceneIds[docs++] = id;
boolean fsv = req.getParams().getBool(ResponseBuilder.FIELD_SORT_VALUES,false); if(fsv){ Sort sort = rb.getSortSpec().getSort(); SortField[] sortFields = sort==null ? new SortField[]{SortField.FIELD_SCORE} : sort.getSort(); NamedList sortVals = new NamedList(); // order is important for the sort fields Field field = new Field("dummy", "", Field.Store.YES, Field.Index.NO); // a dummy Field SolrIndexReader reader = searcher.getReader(); SolrIndexReader[] readers = reader.getLeafReaders(); SolrIndexReader subReader = reader; FieldType ft = fieldname==null ? null : req.getSchema().getFieldTypeNoEx(fieldname); val = ft.toObject(field); sortVals.add(fieldname, vals);
SchemaField sp = req.getSchema().getFieldOrNull(field); if (sp == null) { throw new SolrException(ErrorCode.SERVER_ERROR,"Undefined field: "+field); Analyzer analyzer = sp.getType().getQueryAnalyzer(); TokenStream ts = analyzer.tokenStream(field, new StringReader(qstr));
/** Add the xpathFields to the indexConfig using information about the field drawn from the schema. */ private void addXPathFields() { for (Entry<String,String> f : xpathFieldConfig) { SchemaField field = schema.getField(f.getKey()); FieldType fieldType = field.getType(); if (fieldType == null) { throw new SolrException(ErrorCode.SERVER_ERROR, "Field " + f.getKey() + " declared in lux config, but not defined in schema"); } XPathField xpathField = new XPathField(f.getKey(), f.getValue(), fieldType.getAnalyzer(), field.stored() ? Store.YES : Store.NO, field); indexConfig.addField(xpathField); } }
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()); String f = initArgs.get( CONFIG_FILE ); if( f == null ) { throw new SolrException( SolrException.ErrorCode.SERVER_ERROR, "QueryElevationComponent must specify argument: '"+CONFIG_FILE +"' -- path to elevate.xml" ); try { searchHolder = core.getNewestSearcher(false); IndexReader reader = searchHolder.get().getReader(); getElevationMap( reader, core ); } finally {
throws Exception { IndexReader reader = searcher.getReader(); IndexSchema schema = searcher.getSchema(); SchemaField sfield = schema.getFieldOrNull( fieldName ); FieldType ftype = (sfield==null)?null:sfield.getType(); f.add( "type", (ftype==null)?null:ftype.getTypeName() ); f.add( "schema", getFieldFlags( sfield ) ); if (sfield != null && schema.isDynamicField(sfield.getName()) && schema.getDynamicPattern(sfield.getName()) != null) { f.add("dynamicBase", schema.getDynamicPattern(sfield.getName())); if( ttinfo != null && sfield != null && sfield.indexed() ) { Query q = new ConstantScoreRangeQuery(fieldName,null,null,false,false); TopDocs top = searcher.search( q, 1 ); if( top.totalHits > 0 ) {
public String init(NamedList config, SolrCore core) { super.init(config, core); indexDir = (String) config.get(INDEX_DIR); String accuracy = (String) config.get(ACCURACY); sourceLocation = (String) config.get(LOCATION); field = (String) config.get(FIELD); String strDistanceName = (String)config.get(STRING_DISTANCE); if (field != null && core.getSchema().getFieldTypeNoEx(field) != null) { analyzer = core.getSchema().getFieldType(field).getQueryAnalyzer(); fieldTypeName = (String) config.get(FIELD_TYPE); if (core.getSchema().getFieldTypes().containsKey(fieldTypeName)) { FieldType fieldType = core.getSchema().getFieldTypes().get(fieldTypeName); analyzer = fieldType.getQueryAnalyzer();
SchemaField uniq = schema.getUniqueKeyField(); NamedList<NamedList<NamedList<Object>>> theTokens = new SimpleOrderedMap<NamedList<NamedList<Object>>>(); result.add(doc.getFieldValue(uniq.getName()).toString(), theTokens); for (String name : doc.getFieldNames()) { FieldType ft = schema.getFieldType(name); Analyzer analyzer = ft.getAnalyzer(); Collection<Object> vals = doc.getFieldValues(name); for (Object val : vals) { TokenStream tstream = analyzer.tokenStream(name, reader); NamedList<NamedList<Object>> tokens = getTokens(tstream); theTokens.add(name, tokens);
String val; try { val = toInternal(externalVal); } catch (RuntimeException e) { throw new SolrException( SolrException.ErrorCode.SERVER_ERROR, "Error while creating field '" + field + "' from value '" + externalVal + "'", e, false); if (!field.indexed() && !field.stored()) { if (log.isTraceEnabled()) log.trace("Ignoring unindexed/unstored field: " + field); Field f = new Field(field.getName(), val, getFieldStore(field, val), getFieldIndex(field, val), getFieldTermVec(field, val)); f.setOmitNorms(field.omitNorms()); f.setOmitTermFreqAndPositions(field.omitTf());
private NamedList getListedTermCounts(String field, String termList) throws IOException { FieldType ft = searcher.getSchema().getFieldType(field); List<String> terms = StrUtils.splitSmart(termList, ",", true); NamedList res = new NamedList(); Term t = new Term(field); for (String term : terms) { String internal = ft.toInternal(term); int count = searcher.numDocs(new TermQuery(t.createTerm(internal)), base); res.add(term, count); } return res; }