Java Code Examples for org.apache.solr.schema.SchemaField#getType()
The following examples show how to use
org.apache.solr.schema.SchemaField#getType() .
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: CommandHandler.java From lucene-solr with Apache License 2.0 | 6 votes |
private DocSet computeGroupedDocSet(Query query, ProcessedFilter filter, List<Collector> collectors) throws IOException { @SuppressWarnings({"rawtypes"}) Command firstCommand = commands.get(0); String field = firstCommand.getKey(); SchemaField sf = searcher.getSchema().getField(field); FieldType fieldType = sf.getType(); @SuppressWarnings({"rawtypes"}) final AllGroupHeadsCollector allGroupHeadsCollector; if (fieldType.getNumberType() != null) { ValueSource vs = fieldType.getValueSource(sf, null); allGroupHeadsCollector = AllGroupHeadsCollector.newCollector(new ValueSourceGroupSelector(vs, new HashMap<>()), firstCommand.getWithinGroupSort()); } else { allGroupHeadsCollector = AllGroupHeadsCollector.newCollector(new TermGroupSelector(firstCommand.getKey()), firstCommand.getWithinGroupSort()); } if (collectors.isEmpty()) { searchWithTimeLimiter(query, filter, allGroupHeadsCollector); } else { collectors.add(allGroupHeadsCollector); searchWithTimeLimiter(query, filter, MultiCollector.wrap(collectors.toArray(new Collector[collectors.size()]))); } return new BitDocSet(allGroupHeadsCollector.retrieveGroupHeads(searcher.maxDoc())); }
Example 2
Source File: GeoDistValueSourceParser.java From lucene-solr with Apache License 2.0 | 6 votes |
private MultiValueSource parseSfield(FunctionQParser fp) throws SyntaxError { String sfield = fp.getParam(SpatialParams.FIELD); if (sfield == null) return null; SchemaField sf = fp.getReq().getSchema().getField(sfield); FieldType type = sf.getType(); if (type instanceof AbstractSpatialFieldType) { @SuppressWarnings({"rawtypes"}) AbstractSpatialFieldType asft = (AbstractSpatialFieldType) type; return new SpatialStrategyMultiValueSource(asft.getStrategy(sfield), asft.getDistanceUnits()); } ValueSource vs = type.getValueSource(sf, fp); if (vs instanceof MultiValueSource) { return (MultiValueSource)vs; } throw new SyntaxError("Spatial field must implement MultiValueSource or extend AbstractSpatialFieldType:" + sf); }
Example 3
Source File: GroupConverter.java From lucene-solr with Apache License 2.0 | 6 votes |
@SuppressWarnings({"unchecked", "rawtypes"}) static TopGroups<BytesRef> fromMutable(SchemaField field, TopGroups<MutableValue> values) { if (values == null) { return null; } FieldType fieldType = field.getType(); GroupDocs<BytesRef> groupDocs[] = new GroupDocs[values.groups.length]; for (int i = 0; i < values.groups.length; i++) { GroupDocs<MutableValue> original = values.groups[i]; final BytesRef groupValue; if (original.groupValue.exists) { BytesRefBuilder binary = new BytesRefBuilder(); fieldType.readableToIndexed(Utils.OBJECT_TO_STRING.apply(original.groupValue.toObject()), binary); groupValue = binary.get(); } else { groupValue = null; } groupDocs[i] = new GroupDocs<>(original.score, original.maxScore, original.totalHits, original.scoreDocs, groupValue, original.groupSortValues); } return new TopGroups<>(values.groupSort, values.withinGroupSort, values.totalHitCount, values.totalGroupedHitCount, groupDocs, values.maxScore); }
Example 4
Source File: SimpleFacets.java From lucene-solr with Apache License 2.0 | 6 votes |
/** * Computes the term->count counts for the specified term values relative to the * * @param field the name of the field to compute term counts against * @param parsed contains the docset to compute term counts relative to * @param terms a list of term values (in the specified field) to compute the counts for */ protected NamedList<Integer> getListedTermCounts(String field, final ParsedParams parsed, List<String> terms) throws IOException { final String sort = parsed.params.getFieldParam(field, FacetParams.FACET_SORT, "empty"); final SchemaField sf = searcher.getSchema().getField(field); final FieldType ft = sf.getType(); final DocSet baseDocset = parsed.docs; final NamedList<Integer> res = new NamedList<>(); Stream<String> inputStream = terms.stream(); if (sort.equals(FacetParams.FACET_SORT_INDEX)) { // it might always make sense inputStream = inputStream.sorted(); } Stream<SimpleImmutableEntry<String,Integer>> termCountEntries = inputStream .map((term) -> new SimpleImmutableEntry<>(term, numDocs(term, sf, ft, baseDocset))); if (sort.equals(FacetParams.FACET_SORT_COUNT)) { termCountEntries = termCountEntries.sorted(Collections.reverseOrder(Map.Entry.comparingByValue())); } termCountEntries.forEach(e -> res.add(e.getKey(), e.getValue())); return res; }
Example 5
Source File: QueryAutoFilteringComponent.java From query-autofiltering-component with Apache License 2.0 | 6 votes |
private ArrayList<String> getStringFields( SolrIndexSearcher searcher ) { IndexSchema schema = searcher.getSchema(); ArrayList<String> strFields = new ArrayList<String>( ); Collection<String> fieldNames = searcher.getFieldNames(); Iterator<String> fnIt = fieldNames.iterator(); while ( fnIt.hasNext() ) { String fieldName = fnIt.next( ); if (excludeFields == null || !excludeFields.contains( fieldName )) { try { SchemaField field = schema.getField(fieldName); if (field.stored() && field.getType() instanceof StrField ) { strFields.add( fieldName ); } } catch (Throwable e ) { } } } return strFields; }
Example 6
Source File: AlfrescoLukeRequestHandler.java From SearchServices with GNU Lesser General Public License v3.0 | 5 votes |
private static void populateFieldInfo(IndexSchema schema, Map<String, List<String>> typeusemap, Map<String, Object> fields, SchemaField uniqueField, SchemaField f) { FieldType ft = f.getType(); SimpleOrderedMap<Object> field = new SimpleOrderedMap<>(); field.add("type", ft.getTypeName()); field.add("flags", getFieldFlags(f)); if (f.isRequired()) { field.add("required", f.isRequired()); } if (f.getDefaultValue() != null) { field.add("default", f.getDefaultValue()); } if (f == uniqueField) { field.add("uniqueKey", true); } if (ft.getIndexAnalyzer().getPositionIncrementGap(f.getName()) != 0) { field.add("positionIncrementGap", ft.getIndexAnalyzer() .getPositionIncrementGap(f.getName())); } field.add("copyDests", toListOfStringDests(schema.getCopyFieldsList(f.getName()))); field.add("copySources", schema.getCopySources(f.getName())); fields.put(f.getName(), field); List<String> v = typeusemap.get(ft.getTypeName()); if (v == null) { v = new ArrayList<>(); } v.add(f.getName()); typeusemap.put(ft.getTypeName(), v); }
Example 7
Source File: CursorMark.java From lucene-solr with Apache License 2.0 | 5 votes |
/** * Generates a Base64 encoded serialized representation of the sort values * encapsulated by this object, for use in cursor requests. * * @see #parseSerializedTotem */ public String getSerializedTotem() { if (null == this.values) { return CURSOR_MARK_START; } final List<SchemaField> schemaFields = sortSpec.getSchemaFields(); final ArrayList<Object> marshalledValues = new ArrayList<>(values.size()+1); for (int i = 0; i < schemaFields.size(); i++) { SchemaField fld = schemaFields.get(i); Object safeValue = values.get(i); if (null != fld) { FieldType type = fld.getType(); safeValue = type.marshalSortValue(safeValue); } marshalledValues.add(safeValue); } // TODO: we could also encode info about the SortSpec for error checking: // the type/name/dir from the SortFields (or a hashCode to act as a checksum) // could help provide more validation beyond just the number of clauses. try (JavaBinCodec jbc = new JavaBinCodec(); ByteArrayOutputStream out = new ByteArrayOutputStream(256)) { jbc.marshal(marshalledValues, out); byte[] rawData = out.toByteArray(); return Base64.byteArrayToBase64(rawData, 0, rawData.length); } catch (Exception ex) { throw new SolrException(ErrorCode.SERVER_ERROR, "Unable to format search after totem", ex); } }
Example 8
Source File: FieldQParserPlugin.java From lucene-solr with Apache License 2.0 | 5 votes |
@Override public QParser createParser(String qstr, SolrParams localParams, SolrParams params, SolrQueryRequest req) { return new QParser(qstr, localParams, params, req) { @Override public Query parse() { String field = localParams.get(QueryParsing.F); String queryText = localParams.get(QueryParsing.V); SchemaField sf = req.getSchema().getField(field); FieldType ft = sf.getType(); return ft.getFieldQuery(this, sf, queryText); } }; }
Example 9
Source File: ValueSourceParser.java From lucene-solr with Apache License 2.0 | 5 votes |
@Override public ValueSource parse(FunctionQParser fp) throws SyntaxError { String fieldName = fp.parseArg(); SchemaField f = fp.getReq().getSchema().getField(fieldName); if (! (f.getType() instanceof CurrencyFieldType)) { throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Currency function input must be the name of a CurrencyFieldType: " + fieldName); } CurrencyFieldType ft = (CurrencyFieldType) f.getType(); String code = fp.hasMoreArguments() ? fp.parseArg() : null; return ft.getConvertedValueSource(code, ft.getValueSource(f, fp)); }
Example 10
Source File: TestDocBasedVersionConstraints.java From lucene-solr with Apache License 2.0 | 5 votes |
public void testCanCreateTombstonesRequiredFieldWithDefault() { DocBasedVersionConstraintsProcessorFactory factory = new DocBasedVersionConstraintsProcessorFactory(); NamedList<Object> config = new NamedList<>(); config.add("versionField", "_version_"); factory.init(config); IndexSchema schema = h.getCore().getLatestSchema(); SchemaField sf = schema.getField("sku1"); SchemaField sf2 = new SchemaField("sku1_with_default", sf.getType(), sf.getProperties(), "foo"); try { schema.getRequiredFields().add(sf2); assertThat(factory.canCreateTombstoneDocument(schema), is(true)); } finally { schema.getRequiredFields().remove(sf2); } }
Example 11
Source File: DocBasedVersionConstraintsProcessor.java From lucene-solr with Apache License 2.0 | 5 votes |
/** * Inspects a raw field value (which may come from a doc in the index, or a * doc in the UpdateLog that still has String values, or a String sent by * the user as a param) and if it is a String, asks the versionField FieldType * to convert it to an Object suitable for comparison. */ private static Object convertFieldValueUsingType(final Object rawValue, SchemaField field) { if (rawValue instanceof CharSequence) { // in theory, the FieldType might still be CharSequence based, // but in that case trust it to do an identity conversion... FieldType fieldType = field.getType(); BytesRefBuilder term = new BytesRefBuilder(); fieldType.readableToIndexed((CharSequence)rawValue, term); return fieldType.toObject(field, term.get()); } // else... return rawValue; }
Example 12
Source File: LukeRequestHandler.java From lucene-solr with Apache License 2.0 | 5 votes |
private static void populateFieldInfo(IndexSchema schema, Map<String, List<String>> typeusemap, Map<String, Object> fields, SchemaField uniqueField, SchemaField f) { FieldType ft = f.getType(); SimpleOrderedMap<Object> field = new SimpleOrderedMap<>(); field.add( "type", ft.getTypeName() ); field.add( "flags", getFieldFlags(f) ); if( f.isRequired() ) { field.add( "required", f.isRequired() ); } if( f.getDefaultValue() != null ) { field.add( "default", f.getDefaultValue() ); } if (f == uniqueField){ field.add("uniqueKey", true); } if (ft.getIndexAnalyzer().getPositionIncrementGap(f.getName()) != 0) { field.add("positionIncrementGap", ft.getIndexAnalyzer().getPositionIncrementGap(f.getName())); } field.add("copyDests", toListOfStringDests(schema.getCopyFieldsList(f.getName()))); field.add("copySources", schema.getCopySources(f.getName())); fields.put( f.getName(), field ); List<String> v = typeusemap.get( ft.getTypeName() ); if( v == null ) { v = new ArrayList<>(); } v.add( f.getName() ); typeusemap.put( ft.getTypeName(), v ); }
Example 13
Source File: ElevatedMarkerFactory.java From lucene-solr with Apache License 2.0 | 4 votes |
@Override public DocTransformer create(String field, SolrParams params, SolrQueryRequest req) { SchemaField uniqueKeyField = req.getSchema().getUniqueKeyField(); String idfield = uniqueKeyField.getName(); return new MarkTransformer(field,idfield, uniqueKeyField.getType()); }
Example 14
Source File: SolrDocumentFetcher.java From lucene-solr with Apache License 2.0 | 4 votes |
private Object decodeNumberFromDV(SchemaField schemaField, long value, boolean sortableNumeric) { // note: This special-case is unfortunate; if we have to add any more than perhaps the fieldType should // have this method so that specific field types can customize it. if (schemaField.getType() instanceof LatLonPointSpatialField) { return LatLonPointSpatialField.decodeDocValueToString(value); } if (schemaField.getType().getNumberType() == null) { log.warn("Couldn't decode docValues for field: [{}], schemaField: [{}], numberType is unknown", schemaField.getName(), schemaField); return null; } switch (schemaField.getType().getNumberType()) { case INTEGER: final int raw = (int)value; if (schemaField.getType() instanceof AbstractEnumField) { return ((AbstractEnumField)schemaField.getType()).getEnumMapping().intValueToStringValue(raw); } else { return raw; } case LONG: return value; case FLOAT: if (sortableNumeric) { return NumericUtils.sortableIntToFloat((int)value); } else { return Float.intBitsToFloat((int)value); } case DOUBLE: if (sortableNumeric) { return NumericUtils.sortableLongToDouble(value); } else { return Double.longBitsToDouble(value); } case DATE: return new Date(value); default: // catched all possible values, this line will never be reached throw new AssertionError(); } }
Example 15
Source File: Grouping.java From lucene-solr with Apache License 2.0 | 4 votes |
@Override @SuppressWarnings({"unchecked"}) protected void finish() throws IOException { if (secondPass != null) { result = secondPass.getTopGroups(0); populateScoresIfNecessary(); } if (main) { mainResult = createSimpleResponse(); return; } @SuppressWarnings({"rawtypes"}) NamedList groupResult = commonResponse(); if (format == Format.simple) { groupResult.add("doclist", createSimpleResponse()); return; } @SuppressWarnings({"rawtypes"}) List groupList = new ArrayList(); groupResult.add("groups", groupList); // grouped={ key={ groups=[ if (result == null) { return; } // handle case of rows=0 if (numGroups == 0) return; for (GroupDocs<BytesRef> group : result.groups) { @SuppressWarnings({"rawtypes"}) NamedList nl = new SimpleOrderedMap(); groupList.add(nl); // grouped={ key={ groups=[ { // To keep the response format compatable with trunk. // In trunk MutableValue can convert an indexed value to its native type. E.g. string to int // The only option I currently see is the use the FieldType for this if (group.groupValue != null) { SchemaField schemaField = searcher.getSchema().getField(groupBy); FieldType fieldType = schemaField.getType(); // use createFields so that fields having doc values are also supported // TODO: currently, this path is called only for string field, so // should we just use fieldType.toObject(schemaField, group.groupValue) here? List<IndexableField> fields = schemaField.createFields(group.groupValue.utf8ToString()); if (CollectionUtils.isNotEmpty(fields)) { nl.add("groupValue", fieldType.toObject(fields.get(0))); } else { throw new SolrException(ErrorCode.INVALID_STATE, "Couldn't create schema field for grouping, group value: " + group.groupValue.utf8ToString() + ", field: " + schemaField); } } else { nl.add("groupValue", null); } addDocList(nl, group); } }
Example 16
Source File: SolrInformationServer.java From SearchServices with GNU Lesser General Public License v3.0 | 4 votes |
@Override public List<NodeMetaData> getCascadeNodes(List<Long> txnIds) throws IOException, JSONException { List<FieldInstance> list = dataModel.getIndexedFieldNamesForProperty(ContentModel.PROP_CASCADE_TX).getFields(); FieldInstance fieldInstance = list.get(0); RefCounted<SolrIndexSearcher> refCounted = null; IntArrayList docList; Set<Long> parentNodesId = new HashSet<>(); try { refCounted = core.getSearcher(); SolrIndexSearcher searcher = refCounted.get(); String field = fieldInstance.getField(); SchemaField schemaField = searcher.getSchema().getField(field); FieldType fieldType = schemaField.getType(); BooleanQuery.Builder builder = new BooleanQuery.Builder(); BooleanQuery booleanQuery; for(Long l : txnIds) { BytesRefBuilder bytesRefBuilder = new BytesRefBuilder(); fieldType.readableToIndexed(l.toString(), bytesRefBuilder); TermQuery termQuery = new TermQuery(new Term(field, bytesRefBuilder.toBytesRef())); BooleanClause booleanClause = new BooleanClause(termQuery, BooleanClause.Occur.SHOULD); builder.add(booleanClause); } booleanQuery = builder.build(); DocListCollector collector = new DocListCollector(); searcher.search(booleanQuery, collector); docList = collector.getDocs(); int size = docList.size(); for(int i=0; i<size; i++) { int docId = docList.get(i); Document document = searcher.doc(docId, REQUEST_ONLY_ID_FIELD); IndexableField indexableField = document.getField(FIELD_SOLR4_ID); String id = indexableField.stringValue(); TenantDbId ids = AlfrescoSolrDataModel.decodeNodeDocumentId(id); parentNodesId.add(ids.dbId); } } finally { ofNullable(refCounted).ifPresent(RefCounted::decref); } List<NodeMetaData> allNodeMetaDatas = new ArrayList<>(); for (Long parentNodeId : parentNodesId) { NodeMetaDataParameters nmdp = new NodeMetaDataParameters(); nmdp.setFromNodeId(parentNodeId); nmdp.setToNodeId(parentNodeId); nmdp.setIncludeAclId(true); nmdp.setIncludeChildAssociations(false); nmdp.setIncludeChildIds(true); nmdp.setIncludeOwner(false); nmdp.setIncludeParentAssociations(false); nmdp.setIncludePaths(true); nmdp.setIncludeProperties(false); nmdp.setIncludeTxnId(true); nmdp.setMaxResults(1); // Gets only one Optional<Collection<NodeMetaData>> nodeMetaDatas = getNodesMetaDataFromRepository(nmdp); allNodeMetaDatas.addAll(nodeMetaDatas.orElse(Collections.emptyList())); } return allNodeMetaDatas; }
Example 17
Source File: SolrQueryParserBase.java From lucene-solr with Apache License 2.0 | 4 votes |
protected Query getFieldQuery(String field, String queryText, boolean quoted, boolean raw) throws SyntaxError { checkNullField(field); SchemaField sf; if (field.equals(lastFieldName)) { // only look up the SchemaField on a field change... this helps with memory allocation of dynamic fields // and large queries like foo_i:(1 2 3 4 5 6 7 8 9 10) when we are passed "foo_i" each time. sf = lastField; } else { // intercept magic field name of "_" to use as a hook for our // own functions. if (allowSubQueryParsing && field.charAt(0) == '_' && parser != null) { MagicFieldName magic = MagicFieldName.get(field); if (null != magic) { subQParser = parser.subQuery(queryText, magic.subParser); return subQParser.getQuery(); } } lastFieldName = field; sf = lastField = schema.getFieldOrNull(field); } if (sf != null) { FieldType ft = sf.getType(); // delegate to type for everything except tokenized fields if (ft.isTokenized() && sf.indexed()) { boolean fieldAutoGenPhraseQueries = ft instanceof TextField && ((TextField)ft).getAutoGeneratePhraseQueries(); boolean fieldEnableGraphQueries = ft instanceof TextField && ((TextField)ft).getEnableGraphQueries(); SynonymQueryStyle synonymQueryStyle = AS_SAME_TERM; if (ft instanceof TextField) { synonymQueryStyle = ((TextField)(ft)).getSynonymQueryStyle(); } return newFieldQuery(getAnalyzer(), field, queryText, quoted, fieldAutoGenPhraseQueries, fieldEnableGraphQueries, synonymQueryStyle); } else { if (raw) { return new RawQuery(sf, queryText); } else { return ft.getFieldQuery(parser, sf, queryText); } } } // default to a normal field query return newFieldQuery(getAnalyzer(), field, queryText, quoted, false, true, AS_SAME_TERM); }
Example 18
Source File: GroupConverter.java From lucene-solr with Apache License 2.0 | 4 votes |
static Collection<SearchGroup<MutableValue>> toMutable(SchemaField field, Collection<SearchGroup<BytesRef>> values) { FieldType fieldType = field.getType(); List<SearchGroup<MutableValue>> result = new ArrayList<>(values.size()); for (SearchGroup<BytesRef> original : values) { SearchGroup<MutableValue> converted = new SearchGroup<>(); converted.sortValues = original.sortValues; // ? NumberType type = fieldType.getNumberType(); final MutableValue v; switch (type) { case INTEGER: MutableValueInt mutableInt = new MutableValueInt(); if (original.groupValue == null) { mutableInt.value = 0; mutableInt.exists = false; } else { mutableInt.value = (Integer) fieldType.toObject(field, original.groupValue); } v = mutableInt; break; case FLOAT: MutableValueFloat mutableFloat = new MutableValueFloat(); if (original.groupValue == null) { mutableFloat.value = 0; mutableFloat.exists = false; } else { mutableFloat.value = (Float) fieldType.toObject(field, original.groupValue); } v = mutableFloat; break; case DOUBLE: MutableValueDouble mutableDouble = new MutableValueDouble(); if (original.groupValue == null) { mutableDouble.value = 0; mutableDouble.exists = false; } else { mutableDouble.value = (Double) fieldType.toObject(field, original.groupValue); } v = mutableDouble; break; case LONG: MutableValueLong mutableLong = new MutableValueLong(); if (original.groupValue == null) { mutableLong.value = 0; mutableLong.exists = false; } else { mutableLong.value = (Long) fieldType.toObject(field, original.groupValue); } v = mutableLong; break; case DATE: MutableValueDate mutableDate = new MutableValueDate(); if (original.groupValue == null) { mutableDate.value = 0; mutableDate.exists = false; } else { mutableDate.value = ((Date)fieldType.toObject(field, original.groupValue)).getTime(); } v = mutableDate; break; default: throw new AssertionError(); } converted.groupValue = v; result.add(converted); } return result; }
Example 19
Source File: AlfrescoLukeRequestHandler.java From SearchServices with GNU Lesser General Public License v3.0 | 4 votes |
private static SimpleOrderedMap<Object> getIndexedFieldsInfo( SolrQueryRequest req) throws Exception { SolrIndexSearcher searcher = req.getSearcher(); SolrParams params = req.getParams(); Set<String> fields = null; String fl = params.get(CommonParams.FL); if (fl != null) { fields = new TreeSet<>(Arrays.asList(fl.split("[,\\s]+"))); } LeafReader reader = searcher.getSlowAtomicReader(); IndexSchema schema = searcher.getSchema(); // Don't be tempted to put this in the loop below, the whole point here // is to alphabetize the fields! Set<String> fieldNames = new TreeSet<>(); for (FieldInfo fieldInfo : reader.getFieldInfos()) { fieldNames.add(fieldInfo.name); } // Walk the term enum and keep a priority queue for each map in our set SimpleOrderedMap<Object> vInfo = new SimpleOrderedMap<>(); SimpleOrderedMap<Object> aInfo = new SimpleOrderedMap<>(); for (String fieldName : fieldNames) { if (fields != null && !fields.contains(fieldName) && !fields.contains("*")) { continue; // we're not interested in this field Still an issue // here } SimpleOrderedMap<Object> fieldMap = new SimpleOrderedMap<>(); SchemaField sfield = schema.getFieldOrNull(fieldName); FieldType ftype = (sfield == null) ? null : sfield.getType(); fieldMap.add("type", (ftype == null) ? null : ftype.getTypeName()); fieldMap.add("schema", getFieldFlags(sfield)); if (sfield != null && schema.isDynamicField(sfield.getName()) && schema.getDynamicPattern(sfield.getName()) != null) { fieldMap.add("dynamicBase", schema.getDynamicPattern(sfield.getName())); } Terms terms = reader.fields().terms(fieldName); if (terms == null) { // Not indexed, so we need to report what we // can (it made it through the fl param if // specified) vInfo.add(AlfrescoSolrDataModel.getInstance() .getAlfrescoPropertyFromSchemaField(fieldName), fieldMap); aInfo.add(fieldName, fieldMap); continue; } if (sfield != null && sfield.indexed()) { if (params.getBool(INCLUDE_INDEX_FIELD_FLAGS, true)) { Document doc = getFirstLiveDoc(terms, reader); if (doc != null) { // Found a document with this field try { IndexableField fld = doc.getField(fieldName); if (fld != null) { fieldMap.add("index", getFieldFlags(fld)); } else { // it is a non-stored field... fieldMap.add("index", "(unstored field)"); } } catch (Exception ex) { log.warn("error reading field: " + fieldName); } } } fieldMap.add("docs", terms.getDocCount()); } if (fields != null && (fields.contains(fieldName) || fields.contains("*"))) { getDetailedFieldInfo(req, fieldName, fieldMap); } // Add the field vInfo.add(fieldName, fieldMap); aInfo.add(AlfrescoSolrDataModel.getInstance() .getAlfrescoPropertyFromSchemaField(fieldName), fieldMap); } SimpleOrderedMap<Object> finfo = new SimpleOrderedMap<>(); finfo.addAll(vInfo); // finfo.add("mimetype()", finfo.get("cm:content.mimetype")); // finfo.add("contentSize()", finfo.get("cm:content.size")); finfo.addAll(aInfo); return finfo; }
Example 20
Source File: AlfrescoLukeRequestHandler.java From SearchServices with GNU Lesser General Public License v3.0 | 4 votes |
/** * @return a string representing a SchemaField's flags. */ private static String getFieldFlags(SchemaField f) { FieldType t = (f == null) ? null : f.getType(); // see: // http://www.nabble.com/schema-field-properties-tf3437753.html#a9585549 boolean lazy = false; // "lazy" is purely a property of reading fields boolean binary = false; // Currently not possible StringBuilder flags = new StringBuilder(); flags.append((f != null && f.indexed()) ? FieldFlag.INDEXED .getAbbreviation() : '-'); flags.append((t != null && t.isTokenized()) ? FieldFlag.TOKENIZED .getAbbreviation() : '-'); flags.append((f != null && f.stored()) ? FieldFlag.STORED .getAbbreviation() : '-'); flags.append((f != null && f.hasDocValues()) ? FieldFlag.DOC_VALUES .getAbbreviation() : "-"); flags.append((f != null && f.multiValued()) ? FieldFlag.MULTI_VALUED .getAbbreviation() : '-'); flags.append((f != null && f.storeTermVector()) ? FieldFlag.TERM_VECTOR_STORED .getAbbreviation() : '-'); flags.append((f != null && f.storeTermOffsets()) ? FieldFlag.TERM_VECTOR_OFFSET .getAbbreviation() : '-'); flags.append((f != null && f.storeTermPositions()) ? FieldFlag.TERM_VECTOR_POSITION .getAbbreviation() : '-'); flags.append((f != null && f.storeTermPayloads()) ? FieldFlag.TERM_VECTOR_PAYLOADS .getAbbreviation() : '-'); flags.append((f != null && f.omitNorms()) ? FieldFlag.OMIT_NORMS .getAbbreviation() : '-'); flags.append((f != null && f.omitTermFreqAndPositions()) ? FieldFlag.OMIT_TF .getAbbreviation() : '-'); flags.append((f != null && f.omitPositions()) ? FieldFlag.OMIT_POSITIONS .getAbbreviation() : '-'); flags.append((f != null && f.storeOffsetsWithPositions()) ? FieldFlag.STORE_OFFSETS_WITH_POSITIONS .getAbbreviation() : '-'); flags.append((lazy) ? FieldFlag.LAZY.getAbbreviation() : '-'); flags.append((binary) ? FieldFlag.BINARY.getAbbreviation() : '-'); flags.append((f != null && f.sortMissingFirst()) ? FieldFlag.SORT_MISSING_FIRST .getAbbreviation() : '-'); flags.append((f != null && f.sortMissingLast()) ? FieldFlag.SORT_MISSING_LAST .getAbbreviation() : '-'); return flags.toString(); }