List of usage examples for org.apache.lucene.queries.function.docvalues IntDocValues IntDocValues
public IntDocValues(ValueSource vs)
From source file:alba.solr.docvalues.FunctionExecutor.java
License:Apache License
@Override public FunctionValues getValues(Map context, LeafReaderContext readerContext) throws IOException { final Map<String, FunctionValues> valsMap = this.valsMap(sources, context, readerContext); final CallableFunction fn = this.function; FunctionExecutor host = this; if ((this.function.getReturnType() == Boolean.class) || (this.function.getReturnType() == boolean.class)) { logger.error("calling boolean function!"); return new BoolDocValues(this.sources.get(0)) { @Override//from w ww. j av a 2s.co m public boolean boolVal(int doc) { // TODO Auto-generated method stub Object[] objParams = host.populateObjParams(valsMap, doc); return host.getBooleanResult(fn, objParams); } }; } else if (this.function.getReturnType() == Double.class) { return new DoubleDocValues(this.sources.get(0)) { @Override public double doubleVal(int doc) { // TODO Auto-generated method stub return 12.0d; } }; } else if (this.function.getReturnType() == String.class) { return new StrDocValues(this.vs) { @Override public String strVal(int doc) { Object[] objParams = host.populateObjParams(valsMap, doc); return host.getStringResult(fn, objParams); } }; } else if (this.function.getReturnType() == Float.class) { return new FloatDocValues(this.sources.get(0)) { @Override public float floatVal(int doc) { // TODO Auto-generated method stub Object[] objParams = host.populateObjParams(valsMap, doc); return host.getFloatResult(fn, objParams, doc); } }; } else if ((this.function.getReturnType() == Integer.class)) { // with this snippet of code we could avoid to instantiate a new object of type IntDocValues // simply by using the existing instance of WrappedIntDocValues. // but.. this cause a crash :( // wrappedIntDocValues.setFunction(fn); // wrappedIntDocValues.setExpectedParams(this.expectedParams); // return wrappedIntDocValues; // so for now, just go on with the good old new instance of IntDocValues return new IntDocValues(this.sources.get(0)) { @Override public int intVal(int doc) { // TODO Auto-generated method stub Object[] objParams = host.populateObjParams(valsMap, doc); return host.getIntegerResult(fn, objParams, doc); } }; } //apparently we dind't find an appropriate DocValues for this function. //it could be a function which should generate two or more additional fields in the resulting docs //but HOW can we do that??? //for now, just return a null, so no field will be added. host.ping2caller(); logger.error("I don't know how to deal with class " + this.function.getReturnType() + ", check FunctionExecutor.java"); /* * instanziare e restituire x forza un DocValues altrimenti non valorizza i parametri!! * poi in doctransformer togliere questo campo (capire come!) */ IntDocValues dd = new IntDocValues(this.vs) { @Override public int intVal(int doc) { // TODO Auto-generated method stub Object[] objParams = host.populateObjParams(valsMap, doc); try { host.function.getMethod().invoke(fn.getInstance(), objParams); } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { // TODO Auto-generated catch block logger.error("argggg", e); } return 0; //we're not going to use this value } }; return dd; // new StrFunctionValue(null); }
From source file:com.mysoft.b2b.solr.B258DynamicSourceParser.java
License:Open Source License
@SuppressWarnings("rawtypes") @Override/* ww w.j a v a 2s . co m*/ public FunctionValues getValues(Map context, AtomicReaderContext readerContext) throws IOException { final FunctionValues fieldVals = fieldSource.getValues(context, readerContext); final FunctionValues[] valsArr = new FunctionValues[valueSource.length]; System.err.println("valueSource.length-------------" + valueSource.length); for (int i = 0; i < valueSource.length; i++) { valsArr[i] = valueSource[i].getValues(context, readerContext); System.err.println(valsArr[i]); } return new IntDocValues(this) { @Override public int intVal(int doc) { String source = fieldVals.strVal(doc); System.err.println("source------------------" + source); System.err.println("valsArr.length-----" + valsArr.length); System.err.println("doc----" + doc); for (FunctionValues fv : valsArr) { int ss = fv.intVal(doc); System.err.println("args-----" + ss); if (doc > 7) { return 2; } } return 1; } @Override public String toString(int doc) { return name() + '(' + fieldVals.strVal(doc) + ')'; } }; }
From source file:com.rzewucki.solr.functions.LengthFunction.java
License:Apache License
/** * Gets the values for this reader and the context. This method * returns FunctionValues object containing integer for output. * @param context SOLR context object//from ww w .j a v a 2s . c o m * @param readerContext index reader object * @return FunctionValues object * @exception IOException * @see FunctionValues */ @Override public FunctionValues getValues(Map context, AtomicReaderContext readerContext) throws IOException { final FunctionValues firstValues = (valueSource != null) ? (valueSource.getValues(context, readerContext)) : (null); return new IntDocValues(this) { @Override public int intVal(int documentId) {//this method is called for each document in results set String stringValue; if ((firstValues == null) || ((stringValue = firstValues.strVal(documentId)) == null)) { return 0; } else { return stringValue.length(); } } }; }
From source file:org.apache.solr.schema.TrieIntField.java
License:Apache License
@Override protected ValueSource getSingleValueSource(SortedSetSelector.Type choice, SchemaField f) { return new SortedSetFieldSource(f.getName(), choice) { @Override/*from ww w .ja va2s. com*/ public FunctionValues getValues(Map context, LeafReaderContext readerContext) throws IOException { SortedSetFieldSource thisAsSortedSetFieldSource = this; // needed for nested anon class ref SortedSetDocValues sortedSet = DocValues.getSortedSet(readerContext.reader(), field); SortedDocValues view = SortedSetSelector.wrap(sortedSet, selector); return new IntDocValues(thisAsSortedSetFieldSource) { private int lastDocID; private boolean setDoc(int docID) throws IOException { if (docID < lastDocID) { throw new IllegalArgumentException( "docs out of order: lastDocID=" + lastDocID + " docID=" + docID); } if (docID > view.docID()) { lastDocID = docID; return docID == view.advance(docID); } else { return docID == view.docID(); } } @Override public int intVal(int doc) throws IOException { if (setDoc(doc)) { BytesRef bytes = view.binaryValue(); assert bytes.length > 0; return LegacyNumericUtils.prefixCodedToInt(bytes); } else { return 0; } } @Override public boolean exists(int doc) throws IOException { return setDoc(doc); } @Override public ValueFiller getValueFiller() { return new ValueFiller() { private final MutableValueInt mval = new MutableValueInt(); @Override public MutableValue getValue() { return mval; } @Override public void fillValue(int doc) throws IOException { if (setDoc(doc)) { mval.exists = true; mval.value = LegacyNumericUtils.prefixCodedToInt(view.binaryValue()); } else { mval.exists = false; mval.value = 0; } } }; } }; } }; }
From source file:org.opencommercesearch.lucene.queries.function.valuesource.FixedBoostValueSource.java
License:Apache License
@Override public FunctionValues getValues(Map context, AtomicReaderContext readerContext) throws IOException { final FunctionValues vals = fieldValueSource.getValues(context, readerContext); return new IntDocValues(this) { @Override/*from ww w.j ava 2 s . c o m*/ public int intVal(int doc) { int position = positions.size(); String value = vals.strVal(doc); Integer index = positions.get(value); if (index != null) { position = index; } return position; } }; }