public Map<String,Object> toObject(IndexSchema schema) { Map<String,Object> result = new HashMap<>(); for (Fld fld : fields) { SchemaField sf = schema.getField(fld.ftype.fname); if (!sf.multiValued()) { result.put(fld.ftype.fname, fld.vals.get(0)); } else { result.put(fld.ftype.fname, fld.vals); } } return result; }
private SchemaField getSchemaField(String fieldName){ if(cachedFields.containsKey(fieldName)){ return cachedFields.get(fieldName); } SchemaField field = searcher.getSchema().getField(fieldName); cachedFields.put(fieldName, field); return field; }
public static Map<String,Object> toObject(Doc doc, IndexSchema schema, Collection<String> fieldNames) { Map<String,Object> result = new HashMap<>(); for (Fld fld : doc.fields) { if (fieldNames != null && !fieldNames.contains(fld.ftype.fname)) continue; SchemaField sf = schema.getField(fld.ftype.fname); if (!sf.multiValued()) { result.put(fld.ftype.fname, fld.vals.get(0)); } else { result.put(fld.ftype.fname, fld.vals); } } return result; }
public static FieldType getFieldType(String fieldName, IndexSchema indexSchema){ SchemaField field = indexSchema.getField(fieldName); return field.getType(); }
public ValueSource getValueSource(SchemaField field, QParser parser) { // default key field to unique key SchemaField keyField = keyFieldName==null ? schema.getUniqueKeyField() : schema.getField(keyFieldName); return new FileFloatSource(field, keyField, defVal, parser); }
public FieldValueCountCollapseCollector(SolrIndexSearcher searcher, String collapseField) { super(searcher); IndexSchema schema = searcher.getSchema(); collapseFieldType = schema.getField(collapseField).getType(); }
protected Query getRangeQuery(String field, String part1, String part2, boolean inclusive) throws ParseException { checkNullField(field); SchemaField sf = schema.getField(field); return sf.getType().getRangeQuery(parser, sf, "*".equals(part1) ? null : part1, "*".equals(part2) ? null : part2, inclusive, inclusive); }
/** * Get all copy fields, both the static and the dynamic ones. * @param destField * @return Array of fields copied into this field */ public SchemaField[] getCopySources(String destField) { SchemaField f = getField(destField); if (!isCopyFieldTarget(f)) { return new SchemaField[0]; } List<SchemaField> sf = new ArrayList<SchemaField>(); for (Map.Entry<String, List<CopyField>> cfs : copyFieldsMap.entrySet()) { for (CopyField copyField : cfs.getValue()) { if (copyField.getDestination().getName().equals(destField)) { sf.add(copyField.getSource()); } } } return sf.toArray(new SchemaField[sf.size()]); } /**
/** 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); } }
protected void checkFieldsInSchema(SolrIndexSearcher searcher, Collection<String> fields) throws SolrException { IndexSchema schema = searcher.getSchema(); for (String field : fields) { SchemaField sField = schema.getField(field); if (sField == null) { throw new SolrException(ErrorCode.BAD_REQUEST, "\"" + field + "\" is not in schema " + schema.getSchemaName()); } } }
public ValueSource getValueSource(FunctionQParser fp, String arg) { if (arg==null) return null; SchemaField f = fp.req.getSchema().getField(arg); if (f.getType().getClass() == DateField.class || f.getType().getClass() == LegacyDateField.class) { throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Can't use ms() function on non-numeric legacy date field " + arg); } return f.getType().getValueSource(f, fp); }
/** * Converts a lucene document to a solr document. * * @param schema the index schema * @param luceneDoc the lucene document * @return solr document */ public SolrDocument toSolrDoc(IndexSchema schema, Document luceneDoc) { SolrDocument solrDoc = new SolrDocument(); luceneDoc.forEach(it -> solrDoc.addField(it.name(), schema.getField(it.name()).getType().toObject(it))); for (String field : solrDoc.getFieldNames()) { Object value = solrDoc.getFieldValue(field); if (value instanceof ByteBuffer) { solrDoc.setField(field, ((ByteBuffer) value).array()); } } return solrDoc; }
@Test public void testConciseSirenFieldType() throws Exception { final IndexSchema schema = h.getCore().getLatestSchema(); SchemaField json = schema.getField("concise"); assertNotNull(json); FieldType tmp = json.getType(); assertTrue(tmp instanceof ConciseJsonField); json = schema.getField("concise-attribute-wildcard"); assertNotNull(json); tmp = json.getType(); assertTrue(tmp instanceof ConciseJsonField); }
@Test public void testSirenFieldType() throws Exception { final IndexSchema schema = h.getCore().getLatestSchema(); final SchemaField ntriple = schema.getField(JSON_FIELD); assertNotNull(ntriple); final FieldType tmp = ntriple.getType(); assertTrue(tmp instanceof ExtendedJsonField); }
@Test public void testSirenFieldType() throws Exception { final IndexSchema schema = h.getCore().getSchema(); final SchemaField ntriple = schema.getField(JSON_FIELD); assertNotNull(ntriple); final FieldType tmp = ntriple.getType(); assertTrue(tmp instanceof SirenField); }
@Test public void testSirenFieldTypeProperties() throws Exception { final IndexSchema schema = h.getCore().getSchema(); final FieldType type = schema.getField("json").getType(); assertTrue(type instanceof SirenField); assertFalse(type.isMultiValued()); assertTrue(type.isTokenized()); assertEquals(type.getPostingsFormat(), Siren10AForPostingsFormat.NAME); }
@Test public void testSirenFieldTypeProperties() throws Exception { final IndexSchema schema = h.getCore().getLatestSchema(); final FieldType type = schema.getField("json").getType(); assertTrue(type instanceof ExtendedJsonField); assertFalse(type.isMultiValued()); assertTrue(type.isTokenized()); assertEquals(type.getPostingsFormat(), Siren10AForPostingsFormat.NAME); }
@Test public void testSirenFieldAnalyzer() throws Exception { final IndexSchema schema = h.getCore().getLatestSchema(); final SchemaField ntriple = schema.getField(JSON_FIELD); final FieldType tmp = ntriple.getType(); assertTrue(tmp.getAnalyzer() instanceof TokenizerChain); final TokenizerChain ts = (TokenizerChain) tmp.getAnalyzer(); assertNotNull(ts.getTokenizerFactory()); assertTrue(ts.getTokenizerFactory() instanceof ExtendedJsonTokenizerFactory); // 3 filters for index analyzer assertNotNull(ts.getTokenFilterFactories()); assertEquals(3, ts.getTokenFilterFactories().length); assertTrue(ts.getTokenFilterFactories()[0] instanceof DatatypeAnalyzerFilterFactory); assertTrue(ts.getTokenFilterFactories()[1] instanceof PositionAttributeFilterFactory); assertTrue(ts.getTokenFilterFactories()[2] instanceof SirenPayloadFilterFactory); }
@Test public void testConciseSirenFieldAnalyzer() throws Exception { final IndexSchema schema = h.getCore().getLatestSchema(); final SchemaField json = schema.getField("concise"); final FieldType tmp = json.getType(); assertTrue(tmp.getAnalyzer() instanceof TokenizerChain); final TokenizerChain ts = (TokenizerChain) tmp.getAnalyzer(); assertNotNull(ts.getTokenizerFactory()); assertTrue(ts.getTokenizerFactory() instanceof ConciseJsonTokenizerFactory); // 4 filters for index analyzer assertNotNull(ts.getTokenFilterFactories()); assertEquals(4, ts.getTokenFilterFactories().length); assertTrue(ts.getTokenFilterFactories()[0] instanceof DatatypeAnalyzerFilterFactory); assertTrue(ts.getTokenFilterFactories()[1] instanceof PathEncodingFilterFactory); assertTrue(ts.getTokenFilterFactories()[2] instanceof PositionAttributeFilterFactory); assertTrue(ts.getTokenFilterFactories()[3] instanceof SirenPayloadFilterFactory); }
@Test public void testSirenFieldAnalyzer() throws Exception { final IndexSchema schema = h.getCore().getSchema(); final SchemaField ntriple = schema.getField(JSON_FIELD); final FieldType tmp = ntriple.getType(); assertTrue(tmp.getAnalyzer() instanceof TokenizerChain); final TokenizerChain ts = (TokenizerChain) tmp.getAnalyzer(); assertNotNull(ts.getTokenizerFactory()); assertTrue(ts.getTokenizerFactory() instanceof JsonTokenizerFactory); // 3 filters for index analyzer assertNotNull(ts.getTokenFilterFactories()); assertEquals(3, ts.getTokenFilterFactories().length); assertTrue(ts.getTokenFilterFactories()[0] instanceof DatatypeAnalyzerFilterFactory); assertTrue(ts.getTokenFilterFactories()[1] instanceof PositionAttributeFilterFactory); assertTrue(ts.getTokenFilterFactories()[2] instanceof SirenPayloadFilterFactory); // no query analyzer assertNull(tmp.getQueryAnalyzer()); }