liangsi03 / ik-analyzer

Automatically exported from code.google.com/p/ik-analyzer
0 stars 0 forks source link

IKQParserPlugin, 当搜索句子时 #5

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. solrconfig.xml
2. <queryParser name="ik" class="org.apache.solr.search.IKQParserPlugin"/>
3. IKQParserPlugin code:

public class IKQParserPlugin extends QParserPlugin {
  public static String NAME = "ik";

  public void init(NamedList args) {
  }

  public QParser createParser(String qstr, SolrParams localParams, 
SolrParams params, SolrQueryRequest req) {
    return new IKQParser(qstr, localParams, params, req);
  }
}

class IKQParser extends QParser {
    String defaultField;

    public IKQParser(String qstr, SolrParams localParams, SolrParams 
params, SolrQueryRequest req) {
        super(qstr, localParams, params, req);
    }

    public Query parse() throws ParseException {
        String qstr = getString();

        defaultField = getParam(CommonParams.DF);
        if (defaultField==null) {
            defaultField = getReq().getSchema
().getDefaultSearchFieldName();
        }

        Query query = null;
        try {
            query = IKQueryParser.parse(defaultField, qstr);
        }
        catch (IOException e) {
            // TODO: handle exception
        }
        return query;
    }

    public String[] getDefaultHighlightFields() {
        return defaultField == null ? null : new String[]
{defaultField};
    }

}

Original issue reported on code.google.com by duc...@gmail.com on 28 Jan 2010 at 10:11

GoogleCodeExporter commented 8 years ago
我们会在后续版本中,加入该类的代码,感谢您的贡献

Original comment by linliang...@gmail.com on 8 Jul 2010 at 7:21

GoogleCodeExporter commented 8 years ago

Original comment by linliang...@gmail.com on 23 Oct 2012 at 9:38