Example usage for org.apache.lucene.search BooleanQuery getMaxClauseCount

List of usage examples for org.apache.lucene.search BooleanQuery getMaxClauseCount

Introduction

In this page you can find the example usage for org.apache.lucene.search BooleanQuery getMaxClauseCount.

Prototype

public static int getMaxClauseCount() 

Source Link

Document

Return the maximum number of clauses permitted, 1024 by default.

Usage

From source file:org.rssowl.core.internal.persist.search.ModelSearchImpl.java

License:Open Source License

public List<SearchHit<NewsReference>> searchNews(Collection<ISearchCondition> conditions,
        ISearchCondition scope, boolean matchAllConditions) throws PersistenceException {
    try {//  ww  w  .  j a v a2  s.  c o  m
        return doSearchNews(conditions, scope, matchAllConditions);
    }

    /* Too Many Clauses - Increase Clauses Limit */
    catch (TooManyClauses e) {

        /* Disable Clauses Limit */
        if (BooleanQuery.getMaxClauseCount() != ModelSearchImpl.MAX_CLAUSE_COUNT) {
            BooleanQuery.setMaxClauseCount(MAX_CLAUSE_COUNT);
            return doSearchNews(conditions, scope, matchAllConditions);
        }

        /* Maximum reached */
        throw new PersistenceException(Messages.ModelSearchImpl_ERROR_WILDCARDS, e);
    }
}

From source file:org.rssowl.core.internal.persist.search.ModelSearchQueries.java

License:Open Source License

/**
 * Creates a Lucene {@link Query} from the given parameters.
 *
 * @param conditions the search conditions for the query.
 * @param scope a specific {@link ISearchCondition} that scopes the results.
 * As such, the scope condition is a must criteria for the results.
 * @param matchAllConditions <code>true</code> to match all conditions and
 * <code>false</code> otherwise.
 * @return a {@link Query} from the given parameters.
 * @throws IOException in case of an error.
 *///  ww  w .  ja v  a2  s. com
public static Query createQuery(Collection<ISearchCondition> conditions, ISearchCondition scope,
        boolean matchAllConditions) throws IOException {
    try {
        return internalCreateQuery(conditions, scope, matchAllConditions);
    }

    /* Too Many Clauses - Increase Clauses Limit */
    catch (TooManyClauses e) {

        /* Disable Clauses Limit */
        if (BooleanQuery.getMaxClauseCount() != ModelSearchImpl.MAX_CLAUSE_COUNT) {
            BooleanQuery.setMaxClauseCount(ModelSearchImpl.MAX_CLAUSE_COUNT);
            return internalCreateQuery(conditions, scope, matchAllConditions);
        }

        /* Maximum reached */
        throw e;
    }
}

From source file:org.rssowl.core.tests.model.ModelSearchTest4.java

License:Open Source License

/**
 * @throws Exception/*from w  w w.jav  a  2s.  c  o  m*/
 */
@Test
public void testMaxClauseCount() throws Exception {
    int maxClauseCount = BooleanQuery.getMaxClauseCount();

    IFeed feed = fFactory.createFeed(null, new URI("http://www.feed.com/feed.xml"));
    createNews(feed, "Foo", "http://www.news.com/news3.html", State.READ);
    DynamicDAO.save(feed);

    waitForIndexer();

    ISearchField field = fFactory.createSearchField(INews.TITLE, fNewsEntityName);

    List<ISearchCondition> conditions = new ArrayList<ISearchCondition>();
    for (int i = 0; i < 1030; i++) {
        ISearchCondition condition1 = fFactory.createSearchCondition(field, SearchSpecifier.CONTAINS,
                "foo" + i);
        conditions.add(condition1);
    }

    conditions.add(fFactory.createSearchCondition(field, SearchSpecifier.CONTAINS, "foo"));

    List<SearchHit<NewsReference>> result = fModelSearch.searchNews(conditions, false);
    assertEquals(1, result.size());
    assertEquals("Foo", result.get(0).getResult().resolve().getTitle());

    BooleanQuery.setMaxClauseCount(maxClauseCount);
}

From source file:org.rssowl.core.tests.model.ModelSearchTest4.java

License:Open Source License

/**
 * @throws Exception//from   www. j a v a2 s .  c o m
 */
@Test
public void testMaxClauseCountForQuery() throws Exception {
    int maxClauseCount = BooleanQuery.getMaxClauseCount();
    BooleanQuery.setMaxClauseCount(3);

    IFolderChild root = fFactory.createFolder(null, null, "Root");
    IFeed feed1 = DynamicDAO.save(fFactory.createFeed(null, new URI("http://www.feed.com/feed1.xml")));
    IFeed feed2 = DynamicDAO.save(fFactory.createFeed(null, new URI("http://www.feed.com/feed2.xml")));
    IFeed feed3 = DynamicDAO.save(fFactory.createFeed(null, new URI("http://www.feed.com/feed3.xml")));
    IFeed feed4 = DynamicDAO.save(fFactory.createFeed(null, new URI("http://www.feed.com/feed4.xml")));

    DynamicDAO
            .save(fFactory.createBookMark(null, (IFolder) root, new FeedLinkReference(feed1.getLink()), "BM1"));
    DynamicDAO
            .save(fFactory.createBookMark(null, (IFolder) root, new FeedLinkReference(feed2.getLink()), "BM1"));
    DynamicDAO
            .save(fFactory.createBookMark(null, (IFolder) root, new FeedLinkReference(feed3.getLink()), "BM1"));
    DynamicDAO
            .save(fFactory.createBookMark(null, (IFolder) root, new FeedLinkReference(feed4.getLink()), "BM1"));

    ISearchField field = fFactory.createSearchField(INews.LOCATION, fNewsEntityName);
    List<ISearchCondition> conditions = new ArrayList<ISearchCondition>();
    conditions.add(fFactory.createSearchCondition(field, SearchSpecifier.IS,
            ModelUtils.toPrimitive(Collections.singletonList(root))));

    Query query = ModelSearchQueries.createQuery(conditions, null, false);
    assertNotNull(query);

    BooleanQuery.setMaxClauseCount(maxClauseCount);
}

From source file:org.sindice.siren.qparser.json.builders.BooleanQueryNodeBuilder.java

License:Apache License

public BooleanQuery build(final QueryNode queryNode) throws QueryNodeException {
    final BooleanQueryNode booleanNode = (BooleanQueryNode) queryNode;
    final BooleanQuery bQuery = new BooleanQuery(true);
    final List<QueryNode> children = booleanNode.getChildren();

    for (final QueryNode child : children) {
        final Object obj = child.getTag(QueryTreeBuilder.QUERY_TREE_BUILDER_TAGID);
        // wrap the query into a LuceneProxyNodeQuery
        final Query query = new LuceneProxyNodeQuery((NodeQuery) obj);
        try {// w w  w  .  j ava 2 s .  com
            bQuery.add(query, getModifierValue(child));
        } catch (final TooManyClauses ex) {
            throw new QueryNodeException(new MessageImpl(QueryParserMessages.TOO_MANY_BOOLEAN_CLAUSES,
                    BooleanQuery.getMaxClauseCount(), queryNode.toQueryString(new EscapeQuerySyntaxImpl())),
                    ex);
        }
    }
    return bQuery;
}

From source file:org.sindice.siren.qparser.json.builders.TwigQueryNodeBuilder.java

License:Apache License

@Override
public TwigQuery build(final QueryNode queryNode) throws QueryNodeException {
    final TwigQueryNode twigNode = (TwigQueryNode) queryNode;
    final List<QueryNode> children = twigNode.getChildren();
    final TwigQuery query = new TwigQuery();

    // check if the node has a level constraint
    if (twigNode.getTag(LevelPropertyParser.LEVEL_PROPERTY) != null) {
        query.setLevelConstraint((Integer) twigNode.getTag(LevelPropertyParser.LEVEL_PROPERTY));
    }/* w w w  .  j  ava  2s .co  m*/

    // check if the node has a node range constraint
    if (twigNode.getTag(RangePropertyParser.RANGE_PROPERTY) != null) {
        final int[] range = (int[]) twigNode.getTag(RangePropertyParser.RANGE_PROPERTY);
        query.setNodeConstraint(range[0], range[1]);
    }

    // process root query
    if (twigNode.hasRoot()) {
        final String rootExpr = twigNode.getRoot().toString();
        final String field = twigNode.getField().toString();
        query.addRoot((NodeQuery) keywordParser.parse(rootExpr, field));
    }

    // process child and descendant queries
    try {
        processChildren(children, query);
    } catch (final TooManyClauses ex) {
        throw new QueryNodeException(new MessageImpl(QueryParserMessages.TOO_MANY_BOOLEAN_CLAUSES,
                BooleanQuery.getMaxClauseCount(), twigNode.toQueryString(new EscapeQuerySyntaxImpl())), ex);
    }

    return query;
}

From source file:retriever.TermStats.java

DocStats(CrossLingualAligner aligner, int docId) {
    this.docId = docId;
    this.reader = aligner.enIndexReader;
    termStats = new ArrayList<>();
    BooleanQuery.setMaxClauseCount(8192);
    MAX_QUERY_TERMS = BooleanQuery.getMaxClauseCount();
    queryToDocRatio = Float.parseFloat(aligner.prop.getProperty("querysel.q_to_d_ratio", "0.4"));
    qSelLambda = Float.parseFloat(aligner.prop.getProperty("querysel.lambda", "0.4"));
}

From source file:suonos.lucene.QueryHelper.java

License:Apache License

public Query createQuery(String field, List<String> values, Occur occur) {

    // Safety check.
    ////from w  w  w .  j  a  v a 2 s .  c o m
    if (values.size() >= BooleanQuery.getMaxClauseCount()) {
        throw new IllegalArgumentException();
    }

    BooleanQuery.Builder bldr = new BooleanQuery.Builder();
    for (String id : values) {
        bldr.add(createQuery(field, id), occur);
    }
    return bldr.build();
}