Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement mod function in Solr 3.3

I am using solr 3.3 now, and there is need to using mod function in query,but mod function is not exist until 4.0. so, I want using other functionsto replace mod in 3.3 like

q=subject:mp3&fq={!frange l=1 u=1}sub(id,product(floor(div(id,2)),2)). 

But I found that this function can not working, cause that sub(id,product(floor(div(id,2)),2)) will equal to id even id is a odd number. Is there anyone can given a working replacement for mod function in 3.3? Thanks

like image 396
Wang Jun Avatar asked Jul 16 '26 13:07

Wang Jun


1 Answers

If you have already written some Java, it should be easy to implement, just write a ModFunction class (see the div implementation for example). Then write a ValueSourceParser for it, it should look like:

public class ModFunctionParser extends ValueSourceParser {
  @Override
  public ValueSource parse(FunctionQParser fp) throws ParseException {
    ValueSource a = fp.parseValueSource();
    ValueSource b = fp.parseValueSource();
    return new ModFunction(a, b);
  }
}

And finally, register this parser in your solrconfig.xml.

like image 194
jpountz Avatar answered Jul 20 '26 04:07

jpountz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!