use of org.apache.lucene.index.FieldInfo in project lucene-solr by apache.
the class FieldValueQuery method createWeight.
@Override
public Weight createWeight(IndexSearcher searcher, boolean needsScores, float boost) throws IOException {
return new ConstantScoreWeight(this, boost) {
@Override
public Scorer scorer(LeafReaderContext context) throws IOException {
FieldInfos fieldInfos = context.reader().getFieldInfos();
FieldInfo fieldInfo = fieldInfos.fieldInfo(field);
if (fieldInfo == null) {
return null;
}
DocValuesType dvType = fieldInfo.getDocValuesType();
LeafReader reader = context.reader();
DocIdSetIterator iterator;
switch(dvType) {
case NONE:
return null;
case NUMERIC:
iterator = reader.getNumericDocValues(field);
break;
case BINARY:
iterator = reader.getBinaryDocValues(field);
break;
case SORTED:
iterator = reader.getSortedDocValues(field);
break;
case SORTED_NUMERIC:
iterator = reader.getSortedNumericDocValues(field);
break;
case SORTED_SET:
iterator = reader.getSortedSetDocValues(field);
break;
default:
throw new AssertionError();
}
return new ConstantScoreScorer(this, score(), iterator);
}
};
}
use of org.apache.lucene.index.FieldInfo in project lucene-solr by apache.
the class BytesRefFieldSource method getValues.
@Override
public FunctionValues getValues(Map context, LeafReaderContext readerContext) throws IOException {
final FieldInfo fieldInfo = readerContext.reader().getFieldInfos().fieldInfo(field);
// TODO: do it cleaner?
if (fieldInfo != null && fieldInfo.getDocValuesType() == DocValuesType.BINARY) {
final BinaryDocValues binaryValues = DocValues.getBinary(readerContext.reader(), field);
return new FunctionValues() {
int lastDocID = -1;
private BytesRef getValueForDoc(int doc) throws IOException {
if (doc < lastDocID) {
throw new IllegalArgumentException("docs were sent out-of-order: lastDocID=" + lastDocID + " vs docID=" + doc);
}
lastDocID = doc;
int curDocID = binaryValues.docID();
if (doc > curDocID) {
curDocID = binaryValues.advance(doc);
}
if (doc == curDocID) {
return binaryValues.binaryValue();
} else {
return null;
}
}
@Override
public boolean exists(int doc) throws IOException {
return getValueForDoc(doc) != null;
}
@Override
public boolean bytesVal(int doc, BytesRefBuilder target) throws IOException {
BytesRef value = getValueForDoc(doc);
if (value == null || value.length == 0) {
return false;
} else {
target.copyBytes(value);
return true;
}
}
public String strVal(int doc) throws IOException {
final BytesRefBuilder bytes = new BytesRefBuilder();
return bytesVal(doc, bytes) ? bytes.get().utf8ToString() : null;
}
@Override
public Object objectVal(int doc) throws IOException {
return strVal(doc);
}
@Override
public String toString(int doc) throws IOException {
return description() + '=' + strVal(doc);
}
@Override
public ValueFiller getValueFiller() {
return new ValueFiller() {
private final MutableValueStr mval = new MutableValueStr();
@Override
public MutableValue getValue() {
return mval;
}
@Override
public void fillValue(int doc) throws IOException {
BytesRef value = getValueForDoc(doc);
mval.exists = value != null;
mval.value.clear();
if (value != null) {
mval.value.copyBytes(value);
}
}
};
}
};
} else {
return new DocTermsIndexDocValues(this, readerContext, field) {
@Override
protected String toTerm(String readableValue) {
return readableValue;
}
@Override
public Object objectVal(int doc) throws IOException {
return strVal(doc);
}
@Override
public String toString(int doc) throws IOException {
return description() + '=' + strVal(doc);
}
};
}
}
use of org.apache.lucene.index.FieldInfo in project stanbol by apache.
the class FstConfig method buildConfig.
/**
* Inspects the SolrCore to get defined languages for the configured
* {@link #indexField} and {@link #storeField}. Initialises the
* {@link #getCorpusCreationInfos()}
* @param schema the schema of the SolrCore
* @param indexReader the index reader of the SolrCore
*/
public void buildConfig(IndexSchema schema, AtomicReader indexReader) {
//we need this twice
FieldInfos fieldInfos = indexReader.getFieldInfos();
String fieldWildcard = encodeLanguage(indexField, "*");
for (FieldInfo fieldInfo : fieldInfos) {
//try to match the field names against the wildcard
if (FilenameUtils.wildcardMatch(fieldInfo.name, fieldWildcard)) {
//for matches parse the language from the field name
String language = parseLanguage(fieldInfo.name, indexField);
if (language != null) {
//generate the FST file name
StringBuilder fstFileName = new StringBuilder(fstName);
if (!language.isEmpty()) {
fstFileName.append('.').append(language);
}
fstFileName.append(".fst");
File fstFile = new File(fstDirectory, fstFileName.toString());
//get the FieldType of the field from the Solr schema
FieldType fieldType = schema.getFieldTypeNoEx(fieldInfo.name);
if (fieldType != null) {
//if the fieldType is present
//we need also to check if the stored field with
//the labels is present
//get the stored Field and check if it is present!
String storeFieldName;
if (storeField == null) {
//storeField == indexField
storeFieldName = fieldInfo.name;
} else {
// check that the storeField is present in the index
storeFieldName = encodeLanguage(storeField, language);
FieldInfo storedFieldInfos = fieldInfos.fieldInfo(storeFieldName);
if (storedFieldInfos == null) {
log.warn(" ... ignore language {} because Stored Field {} " + "for IndexField {} does not exist! ", new Object[] { language, storeFieldName, fieldInfo.name });
storeFieldName = null;
}
}
if (storeFieldName != null) {
// == valid configuration
CorpusCreationInfo fstInfo = new CorpusCreationInfo(language, fieldInfo.name, storeFieldName, fieldType, fstFile);
log.info(" ... init {} ", fstInfo);
addCorpus(fstInfo);
}
} else {
log.warn(" ... ignore language {} becuase unknown fieldtype " + "for SolrFied {}", language, fieldInfo.name);
}
}
//else the field matched the wildcard, but has not passed the
//encoding test.
}
//Solr field does not match the field definition in the config
}
// end iterate over all fields in the SolrIndex
}
Aggregations