<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en"><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/><link rel="stylesheet" href="../jacoco-resources/report.css" type="text/css"/><link rel="shortcut icon" href="../jacoco-resources/report.gif" type="image/gif"/><title>MtasJoinQParser.java</title><link rel="stylesheet" href="../jacoco-resources/prettify.css" type="text/css"/><script type="text/javascript" src="../jacoco-resources/prettify.js"></script></head><body onload="window['PR_TAB_WIDTH']=4;prettyPrint()"><div class="breadcrumb" id="breadcrumb"><span class="info"><a href="../jacoco-sessions.html" class="el_session">Sessions</a></span><a href="../index.html" class="el_report">MTAS</a> > <a href="index.source.html" class="el_package">mtas.solr.search</a> > <span class="el_source">MtasJoinQParser.java</span></div><h1>MtasJoinQParser.java</h1><pre class="source lang-java linenums">package mtas.solr.search; import java.io.IOException; import org.apache.lucene.index.Term; import org.apache.lucene.search.BooleanQuery; import org.apache.lucene.search.Query; import org.apache.lucene.util.automaton.Automaton; import org.apache.lucene.search.AutomatonQuery; import org.apache.lucene.search.BooleanClause.Occur; import org.apache.solr.common.params.SolrParams; import org.apache.solr.core.PluginBag.PluginHolder; import org.apache.solr.handler.component.SearchComponent; import org.apache.solr.request.SolrQueryRequest; import org.apache.solr.search.QParser; import org.apache.solr.search.SyntaxError; import mtas.solr.handler.component.MtasSolrSearchComponent; /** * The Class MtasJoinQParser. */ public class MtasJoinQParser extends QParser { /** The Constant MTAS_JOIN_QPARSER_COLLECTION. */ public static final String MTAS_JOIN_QPARSER_COLLECTION = "collection"; /** The Constant MTAS_JOIN_QPARSER_FIELD. */ public static final String MTAS_JOIN_QPARSER_FIELD = "field"; /** The id. */ <span class="fc" id="L32"> private String id = null;</span> /** The fields. */ <span class="fc" id="L35"> private String[] fields = null;</span> /** * Instantiates a new mtas join Q parser. * * @param qstr the qstr * @param localParams the local params * @param params the params * @param req the req */ public MtasJoinQParser(String qstr, SolrParams localParams, SolrParams params, SolrQueryRequest req) { <span class="fc" id="L47"> super(qstr, localParams, params, req);</span> <span class="pc bpc" id="L49" title="1 of 2 branches missed."> if ((localParams.getParams(MTAS_JOIN_QPARSER_COLLECTION) != null)</span> <span class="pc bpc" id="L50" title="1 of 2 branches missed."> && (localParams.getParams(MTAS_JOIN_QPARSER_COLLECTION).length == 1)) {</span> <span class="fc" id="L51"> id = localParams.getParams(MTAS_JOIN_QPARSER_COLLECTION)[0];</span> } <span class="pc bpc" id="L53" title="1 of 2 branches missed."> if ((localParams.getParams(MTAS_JOIN_QPARSER_FIELD) != null)</span> <span class="pc bpc" id="L54" title="1 of 2 branches missed."> && (localParams.getParams(MTAS_JOIN_QPARSER_FIELD).length > 0)) {</span> <span class="fc" id="L55"> fields = new String[localParams</span> <span class="fc" id="L56"> .getParams(MTAS_JOIN_QPARSER_FIELD).length];</span> <span class="fc" id="L57"> System.arraycopy(localParams.getParams(MTAS_JOIN_QPARSER_FIELD), 0,</span> <span class="fc" id="L58"> fields, 0, localParams.getParams(MTAS_JOIN_QPARSER_FIELD).length);</span> } <span class="fc" id="L60"> }</span> /* * (non-Javadoc) * * @see org.apache.solr.search.QParser#parse() */ @Override public Query parse() throws SyntaxError { <span class="pc bpc" id="L69" title="1 of 2 branches missed."> if (id == null) {</span> <span class="nc" id="L70"> throw new SyntaxError("no " + MTAS_JOIN_QPARSER_COLLECTION);</span> <span class="pc bpc" id="L71" title="1 of 2 branches missed."> } else if (fields == null) {</span> <span class="nc" id="L72"> throw new SyntaxError("no " + MTAS_JOIN_QPARSER_FIELD);</span> } else { <span class="fc" id="L75"> BooleanQuery.Builder booleanQueryBuilder = new BooleanQuery.Builder();</span> <span class="fc" id="L77"> MtasSolrCollectionCache mtasSolrJoinCache = null;</span> <span class="fc bfc" id="L78" title="All 2 branches covered."> for (PluginHolder<SearchComponent> item : req.getCore()</span> <span class="fc" id="L79"> .getSearchComponents().getRegistry().values()) {</span> <span class="fc bfc" id="L80" title="All 2 branches covered."> if (item.get() instanceof MtasSolrSearchComponent) {</span> <span class="fc" id="L81"> mtasSolrJoinCache = ((MtasSolrSearchComponent) item.get())</span> <span class="fc" id="L82"> .getCollectionCache();</span> } <span class="fc" id="L84"> }</span> <span class="pc bpc" id="L85" title="1 of 2 branches missed."> if (mtasSolrJoinCache != null) {</span> Automaton automaton; try { <span class="fc" id="L88"> automaton = mtasSolrJoinCache.getAutomatonById(id);</span> <span class="pc bpc" id="L89" title="1 of 2 branches missed."> if (automaton != null) {</span> <span class="fc bfc" id="L90" title="All 2 branches covered."> for (String field : fields) {</span> <span class="fc" id="L91"> booleanQueryBuilder.add(</span> new AutomatonQuery(new Term(field), automaton), Occur.SHOULD); } } else { <span class="nc" id="L95"> throw new IOException("no data for collection '" + id + "'");</span> } <span class="nc" id="L97"> } catch (IOException e) {</span> <span class="nc" id="L98"> throw new SyntaxError(</span> <span class="nc" id="L99"> "could not construct automaton: " + e.getMessage(), e);</span> <span class="fc" id="L100"> }</span> <span class="fc" id="L101"> return booleanQueryBuilder.build();</span> } else { <span class="nc" id="L103"> throw new SyntaxError("no MtasSolrSearchComponent found");</span> } } } } </pre><div class="footer"><span class="right">Created with <a href="http://www.jacoco.org/jacoco">JaCoCo</a> 0.7.9.201702052155</span></div></body></html>