Package org.sindice.siren.search.node

Examples of org.sindice.siren.search.node.NodeQuery


  @Override
  public NodeQuery build(final QueryNode queryNode) throws QueryNodeException {
    final NodeQueryNode node = (NodeQueryNode) queryNode;
    final String field = node.getField().toString();
    final String expr = node.getValue().toString();
    final NodeQuery query = (NodeQuery) keywordParser.parse(expr, field);
    // check if the node has a level constraint
    if (node.getTag(LevelPropertyParser.LEVEL_PROPERTY) != null) {
      query.setLevelConstraint((Integer) node.getTag(LevelPropertyParser.LEVEL_PROPERTY));
    }
    // check if the node has a node range constraint
    if (node.getTag(RangePropertyParser.RANGE_PROPERTY) != null) {
      final int[] range = (int[]) node.getTag(RangePropertyParser.RANGE_PROPERTY);
      query.setNodeConstraint(range[0], range[1]);
    }
    return query;
  }
View Full Code Here


  }

  @Test
  public void testFuzzyQuery2()
  throws Exception {
    final NodeQuery q1 = new NodeFuzzyQuery(new Term(SirenTestCase.DEFAULT_TEST_FIELD, "michel"));
    this._assertSirenQuery(new LuceneProxyNodeQuery(q1), "michel~");

    final TwigQuery q2 = new TwigQuery(1);
    q2.addChild(q1, NodeBooleanClause.Occur.MUST);
    this._assertSirenQuery(new LuceneProxyNodeQuery(q2), "* : michel~");

    final int numEdits = FuzzyQuery.floatToEdits(0.8f, "michel".codePointCount(0, "michel".length()));
    final NodeQuery q3 = new NodeFuzzyQuery(new Term(SirenTestCase.DEFAULT_TEST_FIELD, "michel"), numEdits);
    this._assertSirenQuery(new LuceneProxyNodeQuery(q3), "michel~0.8");

    // first tilde is escaped, not the second one
    final NodeQuery q4 = new NodeFuzzyQuery(new Term(SirenTestCase.DEFAULT_TEST_FIELD, "http://sw.deri.org/~aida"));
    this._assertSirenQuery(new LuceneProxyNodeQuery(q4), "'http://sw.deri.org/~aida'~");
  }
View Full Code Here

  }

  @Test
  public void testWildcardQuery2()
  throws Exception {
    final NodeQuery q1 = new NodeWildcardQuery(new Term(SirenTestCase.DEFAULT_TEST_FIELD, "st*e.ca?as"));
    this._assertSirenQuery(new LuceneProxyNodeQuery(q1), "st*e.ca?as");
  }
View Full Code Here

  @Test
  public void testBoostQuery()
  throws Exception {
    final BooleanQuery q = new BooleanQuery();
    q.add(ntq("c").getLuceneProxyQuery(), BooleanClause.Occur.MUST);
    final NodeQuery nq = ntq("b").getNodeQuery();
    nq.setBoost(2);
    q.add(new LuceneProxyNodeQuery(nq), BooleanClause.Occur.MUST);
    this._assertSirenQuery(q, "c b^2");
  }
View Full Code Here

  }

  @Test
  public void testRangeQueries()
  throws Exception {
    NodeQuery q = new NodeTermRangeQuery(SirenTestCase.DEFAULT_TEST_FIELD,
      new BytesRef("a"), new BytesRef("b"), true, true);
    this._assertSirenQuery(new LuceneProxyNodeQuery(q), "[ a TO b ]");

    q = new NodeTermRangeQuery(SirenTestCase.DEFAULT_TEST_FIELD,
      new BytesRef("a"), new BytesRef("b"), false, true);
View Full Code Here

    // Set the default datatypes
    final Map<String, Analyzer> datatypes = new HashMap<String, Analyzer>();
    datatypes.put("int", new IntNumericAnalyzer(4));
    parser.setDatatypeAnalyzers(datatypes);

    final NodeQuery rangeWrong = NodeNumericRangeQuery.newIntRange(SirenTestCase.DEFAULT_TEST_FIELD, 42, 12, 21, true, true);
    assertEquals(new LuceneProxyNodeQuery(rangeWrong), parser.parse("int([12 TO 21])", SirenTestCase.DEFAULT_TEST_FIELD));
  }
View Full Code Here

  }

  private static void processChildren(final List<QueryNode> children, final TwigQuery query) {
    for (final QueryNode child : children) {
      final Object obj = child.getTag(QueryTreeBuilder.QUERY_TREE_BUILDER_TAGID);
      final NodeQuery nodeQuery = (NodeQuery) obj;

      // Append child queries
      if (child instanceof ChildQueryNode) {
        query.addChild(nodeQuery, getModifierValue(child));
      }
View Full Code Here

        for (int i = 0; i < children.size(); i++) {
          twigQuery.addChild((NodeQuery) children.get(i),
            NodeQueryBuilderUtil.getModifierValue(aqn.getChildren().get(i), NodeBooleanClause.Occur.MUST));
        }
      } else if (v instanceof Query) {
        final NodeQuery valQuery = (NodeQuery) v;
        twigQuery.addChild(valQuery, Occur.MUST);
      } else {
        throw new QueryNodeException(new MessageImpl(QueryParserMessages.INVALID_SYNTAX,
          "Unexpected class of a Twig Query clause: " + v == null ? "null" : v.getClass().getName()));
      }
View Full Code Here

          /*
           * Nested array query. It is transformed as a TwigQuery with empty root
           */
          final TwigQuery twigQuery = new TwigQuery();
          for (final Query qn : ((ArrayQuery) v).getElements()) {
            final NodeQuery valQuery = (NodeQuery) qn;
            twigQuery.addChild(valQuery, NodeQueryBuilderUtil.getModifierValue(child, NodeBooleanClause.Occur.MUST));
          }
          arrayQuery.addElement(twigQuery);
        } else {
          arrayQuery.addElement((NodeQuery) v);
View Full Code Here

TOP

Related Classes of org.sindice.siren.search.node.NodeQuery

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.