Skip to content

Commit

Permalink
增加从solrconfig.xml里面传过来的解析参数的方法
Browse files Browse the repository at this point in the history
  • Loading branch information
qindongliang committed May 18, 2016
1 parent cf7a168 commit fe242e9
Showing 1 changed file with 10 additions and 41 deletions.
51 changes: 10 additions & 41 deletions src/main/java/com/easy/custom/functionquery/MyValueParser.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
package com.easy.custom.functionquery;

import org.apache.lucene.queries.function.ValueSource;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.search.FunctionQParser;
import org.apache.solr.search.SyntaxError;
import org.apache.solr.search.ValueSourceParser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;

/**
* Created by qindongliang on 2016/5/11.
*/
Expand All @@ -20,50 +17,22 @@ public class MyValueParser extends ValueSourceParser {
final static Logger log= LoggerFactory.getLogger(MyValueParser.class);

//接受传过来的参数
List<String> params;
private int maxYears;
private int money_maxTimes;
private int money_base;

// handle configuration parameters
// passed through solrconfig.xml
public void init(NamedList args) {

//得到一个映射之后,转成NamedList便于操作
params=((NamedList)args.get("words")).getAll("word");
if(params.isEmpty()){
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,"至少有一个参数");
}

// handle configuration parameters
// passed through solrconfig.xml
for(String pm:params){
log.info("函数查询参数:{}",pm);
}
this.params=params;
log.info("函数查询的前台参数: size:{} info:{}",params.size(),params.toString());

maxYears=(Integer) ((NamedList)args.get("strategy")).get("maxYears");
money_maxTimes=(Integer) ((NamedList)args.get("strategy")).get("money_maxTimes");
money_base=(Integer) ((NamedList)args.get("strategy")).get("money_base");
log.info("初始化加权因子参数: maxYears:{} money_maxTimes:{} money_base:{} ",maxYears,money_maxTimes,money_base);
}

@Override
public ValueSource parse(FunctionQParser fq) throws SyntaxError {


//log.info("参数啥东西:{} ",fq.getString());
//得到的结果如下
//参数啥东西:myfunc(easy_year,easy_money)



// log.info("参数啥东西:{}",functionQParser.getParams().getParameterNamesIterator().toString());

// String year=functionQParser.parseArg();
// String money=functionQParser.parseArg();
// log.info("进来就看有几个valuesource:{} ",functionQParser.parseValueSourceList().size());
// log.info("进来就看有几个valuesource:{} ",functionQParser.parseValueSourceList().size());






// log.info("函数的前台几个字段:{} , value list长度:{}",year+","+money,vs.size());

return new FunctionValueSource(params,fq.parseValueSourceList());
return new FunctionValueSource(maxYears,money_maxTimes,money_base,fq.parseValueSourceList());
}
}

0 comments on commit fe242e9

Please sign in to comment.