private BooleanSpanQuery toBooleanSpanQuery() throws QueryNodeException { int slop = this.hasSlop() ? this.getSlop() : BooleanQueryNodeBuilder.DEFAULT_SLOP; boolean inOrder = this.hasInOrder() ? this.getInOrder() : BooleanQueryNodeBuilder.DEFAULT_INORDER; final BooleanSpanQuery query = new BooleanSpanQuery(slop, inOrder); // convert clauses for (final QueryClause clause : clauses) { final SpanQuery q = new NodeSpanQuery((com.sindicetech.siren.search.node.NodeQuery) clause.getQuery().toQuery(false)); query.add(q, clause.getNodeBooleanOccur()); } return query; }
@Override public Query toQuery(final boolean proxy) throws QueryNodeException { Query query; // boolean span query if (this.hasSlop() || this.hasInOrder()) { query = this.toBooleanSpanQuery(); // should we wrap the query into a lucene proxy if (proxy) { query = new LuceneProxyNodeQuery((com.sindicetech.siren.search.node.NodeQuery) query); } } // lucene boolean query else { query = this.toBooleanQuery(); } // add boost if (this.hasBoost()) { query.setBoost(this.getBoost()); } return query; }
@Override public ObjectNode toJson() { final ObjectNode obj = mapper.createObjectNode(); ObjectNode bool = obj.putObject(BooleanPropertyParser.BOOLEAN_PROPERTY); // add boost if (this.hasBoost()) { bool.put(BoostPropertyParser.BOOST_PROPERTY, this.getBoost()); } // add slop if (this.hasSlop()) { bool.put(SlopPropertyParser.SLOP_PROPERTY, this.getSlop()); } // add inOrder if (this.hasInOrder()) { bool.put(InOrderPropertyParser.IN_ORDER_PROPERTY, this.getInOrder()); } // add clauses ArrayNode array = bool.putArray(ClausePropertyParser.CLAUSE_PROPERTY); for (final QueryClause clause : clauses) { final ObjectNode e = array.addObject(); e.put(OccurPropertyParser.OCCUR_PROPERTY, clause.getOccur().toString()); e.putAll(clause.getQuery().toJson()); } return obj; }