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

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

Introduction

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

Prototype

public static void setMaxClauseCount(int maxClauseCount) 

Source Link

Document

Set the maximum number of clauses permitted per BooleanQuery.

Usage

From source file:org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexProviderService.java

License:Apache License

private void configureBooleanClauseLimit(Map<String, ?> config) {
    int booleanClauseLimit = PropertiesUtil.toInteger(config.get(PROP_BOOLEAN_CLAUSE_LIMIT),
            PROP_BOOLEAN_CLAUSE_LIMIT_DEFAULT);
    if (booleanClauseLimit != BooleanQuery.getMaxClauseCount()) {
        BooleanQuery.setMaxClauseCount(booleanClauseLimit);
        log.info("Changed the Max boolean clause limit to {}", booleanClauseLimit);
    }//from ww w  .  j  ava 2 s .  c o  m
}

From source file:org.apache.mahout.freqtermsets.ParallelFPStreamReducer.java

License:Apache License

@Override
protected void reduce(IntWritable key, Iterable<TransactionTree> values, Context context) throws IOException {

    TransactionTree cTree = new TransactionTree();
    int numPatterns = 0;
    for (TransactionTree tr : values) {
        for (Pair<IntArrayList, Long> p : tr) {
            cTree.addPattern(p.getFirst(), p.getSecond());
            ++numPatterns;/*from   w ww  .j  a  v a 2 s  .co m*/
        }
    }

    //    if (fisIxMultiReader != null) {
    if (fisIxReader != null) {
        BooleanQuery.setMaxClauseCount(numPatterns);
        BooleanQuery allPatternsQuery = new BooleanQuery();

        Iterator<Pair<IntArrayList, Long>> cTreeIter = cTree.iterator(true);
        while (cTreeIter.hasNext()) {
            IntArrayList newPatternIds = cTreeIter.next().getFirst();
            if (newPatternIds.size() == 1) {
                // This is already carried over by loading the older flists
                continue;
            }
            StringBuilder newPattenStr = new StringBuilder();
            for (int i = 0; i < newPatternIds.size(); ++i) {
                int id = newPatternIds.getQuick(i);
                String str = idStringMap.get(id);
                newPattenStr.append(str).append(" ");
            }
            try {
                allPatternsQuery.add(fisQparser.parse(newPattenStr.toString()), Occur.SHOULD);
                // fisSearcher.search(fisQparser.parse(newPattenStr.toString()),oldPatternsCollector);
            } catch (ParseException e) {
                context.setStatus("Parallel FPGrowth: caught a parse exception: " + e.getMessage());
                continue;
            }
        }

        fisSearcher.search(allPatternsQuery, new OldPatternsCollector(context, cTree));

    }

    List<Pair<Integer, Long>> localFList = Lists.newArrayList();
    for (Entry<Integer, MutableLong> fItem : cTree.generateFList().entrySet()) {
        localFList.add(new Pair<Integer, Long>(fItem.getKey(), fItem.getValue().toLong()));
    }

    Collections.sort(localFList, new CountDescendingPairComparator<Integer, Long>());

    FPGrowth<Integer> fpGrowth = new FPGrowth<Integer>();
    fpGrowth.generateTopKFrequentPatterns(
            //new IteratorAdapter(cTree.iterator()),
            cTree, localFList, minSupport, maxHeapSize, null,
            new IntegerStringOutputConverter(
                    new ContextWriteOutputCollector<IntWritable, TransactionTree, Text, TopKStringPatterns>(
                            context),
                    idStringMap, minWordsForLangDetection, repeatHashTag),
            new ContextStatusUpdater<IntWritable, TransactionTree, Text, TopKStringPatterns>(context),
            key.get(), numGroups);

}

From source file:org.apache.manifoldcf.examples.ManifoldCFSecurityFilter.java

License:Apache License

/** Calculate a complete subclause, representing something like:
* ((fieldAllowShare is empty AND fieldDenyShare is empty) OR fieldAllowShare HAS token1 OR fieldAllowShare HAS token2 ...)
*     AND fieldDenyShare DOESN'T_HAVE token1 AND fieldDenyShare DOESN'T_HAVE token2 ...
*@param allowField is the field name of the allow field.
*@param denyField is the field name of the deny field.
*@param allowOpen is the query to use if there are no allow access tokens.
*@param denyOpen is the query to use if there are no deny access tokens.
*@param userAccessTokens is the list of access tokens associated with the specified user.
*@return the calculated query.//  ww w . ja v  a2s  . c  om
*/
protected Query calculateCompleteSubquery(String allowField, String denyField, Query allowOpen, Query denyOpen,
        List<String> userAccessTokens) {
    BooleanQuery bq = new BooleanQuery();
    // No query limits!!
    bq.setMaxClauseCount(1000000);

    // Add the empty-acl case
    BooleanQuery subUnprotectedClause = new BooleanQuery();
    subUnprotectedClause.add(allowOpen, BooleanClause.Occur.MUST);
    subUnprotectedClause.add(denyOpen, BooleanClause.Occur.MUST);
    bq.add(subUnprotectedClause, BooleanClause.Occur.SHOULD);
    for (String accessToken : userAccessTokens) {
        bq.add(new TermQuery(new Term(allowField, accessToken)), BooleanClause.Occur.SHOULD);
        bq.add(new TermQuery(new Term(denyField, accessToken)), BooleanClause.Occur.MUST_NOT);
    }
    return bq;
}

From source file:org.apache.solr.core.SolrCore.java

License:Apache License

void booleanQueryMaxClauseCount() {
    synchronized (SolrCore.class) {
        if (boolean_query_max_clause_count == Integer.MIN_VALUE) {
            boolean_query_max_clause_count = solrConfig.booleanQueryMaxClauseCount;
            BooleanQuery.setMaxClauseCount(boolean_query_max_clause_count);
        } else if (boolean_query_max_clause_count != solrConfig.booleanQueryMaxClauseCount) {
            log.debug("BooleanQuery.maxClauseCount= " + boolean_query_max_clause_count + ", ignoring "
                    + solrConfig.booleanQueryMaxClauseCount);
        }//  w  w w .ja  va  2s.  c  o m
    }
}

From source file:org.apache.solr.legacy.TestNumericRangeQuery32.java

License:Apache License

@Override
public void setUp() throws Exception {
    super.setUp();
    // set the theoretical maximum term count for 8bit (see docs for the number)
    // super.tearDown will restore the default
    BooleanQuery.setMaxClauseCount(3 * 255 * 2 + 255);
}

From source file:org.apache.solr.legacy.TestNumericRangeQuery64.java

License:Apache License

@Override
public void setUp() throws Exception {
    super.setUp();
    // set the theoretical maximum term count for 8bit (see docs for the number)
    // super.tearDown will restore the default
    BooleanQuery.setMaxClauseCount(7 * 255 * 2 + 255);
}

From source file:org.compass.core.lucene.engine.LuceneSettings.java

License:Apache License

public void configure(CompassSettings settings) throws SearchEngineException {
    this.settings = settings;
    connection = settings.getSetting(CompassEnvironment.CONNECTION);
    if (connection == null) {
        throw new SearchEngineException("Lucene connection must be set in the settings. Please set ["
                + CompassEnvironment.CONNECTION + "]");
    }//  ww w .j a v a2  s  .c o m
    subContext = settings.getSetting(CompassEnvironment.CONNECTION_SUB_CONTEXT);
    if (log.isDebugEnabled()) {
        log.debug("Using connection [" + connection + "][" + subContext + "]");
    }
    // the alias property
    aliasProperty = settings.getSetting(CompassEnvironment.Alias.NAME, CompassEnvironment.Alias.DEFAULT_NAME);
    if (log.isDebugEnabled()) {
        log.debug("Using alias property [" + aliasProperty + "]");
    }

    extendedAliasProperty = settings.getSetting(CompassEnvironment.Alias.EXTENDED_ALIAS_NAME,
            CompassEnvironment.Alias.DEFAULT_EXTENDED_ALIAS_NAME);
    if (log.isDebugEnabled()) {
        log.debug("Using extended alias property [" + extendedAliasProperty + "]");
    }

    // get the all property
    allProperty = settings.getSetting(CompassEnvironment.All.NAME, CompassEnvironment.All.DEFAULT_NAME);
    if (log.isDebugEnabled()) {
        log.debug("Using default all property [" + allProperty + "]");
    }
    String allPropertyTermVectorSettings = settings.getSetting(CompassEnvironment.All.TERM_VECTOR, "no");
    if (log.isDebugEnabled()) {
        log.debug("Using all property term vector [" + allPropertyTermVectorSettings + "]");
    }
    allPropertyBoostSupport = settings.getSettingAsBoolean(CompassEnvironment.All.BOOST_SUPPORT, true);
    if (log.isDebugEnabled()) {
        log.debug("All property boost support is [" + allPropertyBoostSupport + "]");
    }
    if ("no".equals(allPropertyTermVectorSettings)) {
        allPropertyTermVector = Property.TermVector.NO;
    } else if ("yes".equals(allPropertyTermVectorSettings)) {
        allPropertyTermVector = Property.TermVector.YES;
    } else if ("positions".equals(allPropertyTermVectorSettings)) {
        allPropertyTermVector = Property.TermVector.WITH_POSITIONS;
    } else if ("offsets".equals(allPropertyTermVectorSettings)) {
        allPropertyTermVector = Property.TermVector.WITH_OFFSETS;
    } else if ("positions_offsets".equals(allPropertyTermVectorSettings)) {
        allPropertyTermVector = Property.TermVector.WITH_POSITIONS_OFFSETS;
    } else {
        throw new SearchEngineException("Unrecognized term vector setting for the all property ["
                + allPropertyTermVectorSettings + "]");
    }
    // get the default search term, defaults to the all property
    defaultSearchPropery = settings.getSetting(LuceneEnvironment.DEFAULT_SEARCH, allProperty);
    if (log.isDebugEnabled()) {
        log.debug("Using default search property [" + defaultSearchPropery + "]");
    }
    // lucene specifics parameters
    transactionLockTimout = settings.getSettingAsTimeInSeconds(LuceneEnvironment.Transaction.LOCK_TIMEOUT, 10)
            * 1000;
    if (log.isDebugEnabled()) {
        log.debug("Using transaction lock timeout [" + transactionLockTimout + "ms]");
    }
    IndexWriter.setDefaultWriteLockTimeout(transactionLockTimout);

    Lock.LOCK_POLL_INTERVAL = settings.getSettingAsLong(LuceneEnvironment.Transaction.LOCK_POLL_INTERVAL, 100);
    if (log.isDebugEnabled()) {
        log.debug("Using lock poll interval [" + Lock.LOCK_POLL_INTERVAL + "ms]");
    }

    lockDir = settings.getSetting("compass.transaction.lockDir");
    if (lockDir != null) {
        throw new IllegalArgumentException("compass.transaction.lockDir setting is no longer supported. "
                + "The lock by default is stored in the index directory now, and can be conrolled by using LockFactory");
    }

    maxMergeDocs = settings.getSettingAsInt(LuceneEnvironment.SearchEngineIndex.MAX_MERGE_DOCS,
            Integer.MAX_VALUE);

    // pure lucene transaction settings
    mergeFactor = settings.getSettingAsInt(LuceneEnvironment.SearchEngineIndex.MERGE_FACTOR, 10);
    maxBufferedDocs = settings.getSettingAsInt(LuceneEnvironment.SearchEngineIndex.MAX_BUFFERED_DOCS,
            IndexWriter.DISABLE_AUTO_FLUSH);
    maxBufferedDeletedTerms = settings.getSettingAsInt(
            LuceneEnvironment.SearchEngineIndex.MAX_BUFFERED_DELETED_TERMS, IndexWriter.DISABLE_AUTO_FLUSH);
    termIndexInterval = settings.getSettingAsInt(LuceneEnvironment.SearchEngineIndex.TERM_INDEX_INTERVAL,
            IndexWriter.DEFAULT_TERM_INDEX_INTERVAL);
    maxFieldLength = settings.getSettingAsInt(LuceneEnvironment.SearchEngineIndex.MAX_FIELD_LENGTH,
            IndexWriter.DEFAULT_MAX_FIELD_LENGTH);

    ramBufferSize = settings.getSettingAsDouble(LuceneEnvironment.SearchEngineIndex.RAM_BUFFER_SIZE,
            IndexWriter.DEFAULT_RAM_BUFFER_SIZE_MB);

    // cach invalidation settings
    cacheInvalidationInterval = settings.getSettingAsTimeInMillis(
            LuceneEnvironment.SearchEngineIndex.CACHE_INTERVAL_INVALIDATION,
            LuceneEnvironment.SearchEngineIndex.DEFAULT_CACHE_INTERVAL_INVALIDATION);
    if (log.isDebugEnabled()) {
        log.debug("Using cache invalidation interval [" + cacheInvalidationInterval + "ms]");
    }

    waitForCacheInvalidationOnIndexOperation = settings.getSettingAsBoolean(
            LuceneEnvironment.SearchEngineIndex.WAIT_FOR_CACHE_INVALIDATION_ON_INDEX_OPERATION, false);
    if (log.isDebugEnabled()) {
        log.debug("Wait for cahce invalidation on index operatrion is set to ["
                + waitForCacheInvalidationOnIndexOperation + "]");
    }

    BooleanQuery.setMaxClauseCount(settings.getSettingAsInt(LuceneEnvironment.Query.MAX_CLAUSE_COUNT,
            BooleanQuery.getMaxClauseCount()));
    if (log.isDebugEnabled()) {
        log.debug("Setting *static* Lucene BooleanQuery maxClauseCount to [" + BooleanQuery.getMaxClauseCount()
                + "]");
    }
}

From source file:org.cytoscape.search.internal.util.CustomMultiFieldQueryParser.java

License:Open Source License

protected Query getRangeQuery(String field, String part1, String part2, boolean inclusive)
        throws ParseException {

    // a workaround to avoid a TooManyClauses exception.
    // Temporary until RangeFilter is implemented.
    BooleanQuery.setMaxClauseCount(5120); // 5 * 1024      

    if (attrFields.getType(field) == Integer.class) {
        try {//from w  w w .  j  av  a 2s. c om

            int num1 = Integer.parseInt(part1);
            int num2 = Integer.parseInt(part2);

            Query q = NumericRangeQuery.newIntRange(field, num1, num2, inclusive, inclusive);

            return q;
        } catch (NumberFormatException e) {
            throw new ParseException(e.getMessage());
        }
    }
    if (attrFields.getType(field) == Double.class) {
        try {
            double num1 = Double.parseDouble(part1);
            double num2 = Double.parseDouble(part2);

            Query q = NumericRangeQuery.newDoubleRange(field, num1, num2, inclusive, inclusive);
            return q;

        } catch (NumberFormatException e) {
            throw new ParseException(e.getMessage());
        }
    }

    return super.getRangeQuery(field, part1, part2, inclusive);
}

From source file:org.dbpedia.spotlight.model.SpotlightConfiguration.java

License:Apache License

public SpotlightConfiguration(String fileName) throws ConfigurationException {

    //read config properties
    Properties config = new Properties();
    try {/*  w w  w. ja va2s.com*/
        config.load(new FileInputStream(new File(fileName)));
    } catch (IOException e) {
        throw new ConfigurationException("Cannot find configuration file " + fileName, e);
    }

    //Read the spotter configuration from the properties file
    spotterConfiguration = new SpotterConfiguration(fileName);

    disambiguatorConfiguration = new DisambiguatorConfiguration(fileName);

    //set spotterFile, indexDir...
    contextIndexDirectory = disambiguatorConfiguration.contextIndexDirectory;

    //optionally use separate candidate map
    candidateMapDirectory = config.getProperty("org.dbpedia.spotlight.candidateMap.dir", "").trim();
    if (candidateMapDirectory == null || !new File(candidateMapDirectory).isDirectory()) {
        LOG.info("Could not use candidateMap.dir, using index.dir both for context and candidate searching.");
        candidateMapDirectory = contextIndexDirectory;
    }

    try {
        BufferedReader r = new BufferedReader(
                new FileReader(new File(contextIndexDirectory, similarityThresholdsFile)));
        String line;
        similarityThresholds = new ArrayList<Double>();
        while ((line = r.readLine()) != null) {
            similarityThresholds.add(Double.parseDouble(line));
        }
    } catch (FileNotFoundException e) {
        throw new ConfigurationException("Similarity threshold file '" + similarityThresholdsFile
                + "' not found in index directory " + contextIndexDirectory, e);
    } catch (NumberFormatException e) {
        throw new ConfigurationException(
                "Error parsing similarity value in '" + contextIndexDirectory + "/" + similarityThresholdsFile,
                e);
    } catch (IOException e) {
        throw new ConfigurationException(
                "Error reading '" + contextIndexDirectory + "/" + similarityThresholdsFile, e);
    }

    taggerFile = config.getProperty("org.dbpedia.spotlight.tagging.hmm", "").trim();
    if (taggerFile == null || !new File(taggerFile).isFile()) {
        throw new ConfigurationException("Cannot find POS tagger model file " + taggerFile);
    }

    language = config.getProperty("org.dbpedia.spotlight.language", "English");

    stopWordsFile = config.getProperty("org.dbpedia.spotlight.data.stopWords." + language.toLowerCase(), "")
            .trim();
    if ((stopWordsFile == null) || !new File(stopWordsFile.trim()).isFile()) {
        LOG.warn("Cannot find stopwords file '" + stopWordsFile + "'. Using default Lucene English StopWords.");
        stopWords = DEFAULT_STOPWORDS;
    } else {
        try {
            BufferedReader bufferedReader = new BufferedReader(new FileReader(stopWordsFile.trim()));
            String line = null;
            while ((line = bufferedReader.readLine()) != null) {
                stopWords.add(line.trim());
            }
            bufferedReader.close();
        } catch (Exception e1) {
            LOG.error("Could not read stopwords file.");
            stopWords = DEFAULT_STOPWORDS;
        }
    }

    analyzer = Factory.analyzer().from(
            config.getProperty("org.dbpedia.spotlight.lucene.analyzer", "SnowballAnalyzer"), language,
            stopWords);

    serverURI = config.getProperty("org.dbpedia.spotlight.web.rest.uri", "").trim();
    if (serverURI != null && !serverURI.endsWith("/")) {
        serverURI = serverURI.concat("/");
    }
    try {
        new URI(serverURI);
    } catch (URISyntaxException e) {
        throw new ConfigurationException("Server URI not valid.", e);
    }

    // Configure lucene to accept a larger number of or queries
    BooleanQuery.setMaxClauseCount(3072);

    sparqlEndpoint = config.getProperty("org.dbpedia.spotlight.sparql.endpoint", "").trim(); //TODO how to fail gracefully for endpoint?
    sparqlMainGraph = config.getProperty("org.dbpedia.spotlight.sparql.graph", "").trim();
    ;

    String maxCacheSizeString = config.getProperty("jcs.default.cacheattributes.MaxObjects", "").trim();
    try {
        maxCacheSize = new Long(maxCacheSizeString.trim());
    } catch (Exception ignored) {
        LOG.error(ignored);
    }

    /**
     * These configuration parameters are for an alternative way to load DBpediaResources (from an in-memory database instead of Lucene)
     */
    String coreDbType = config.getProperty("org.dbpedia.spotlight.core.database", "").trim();
    String coreJdbcDriver = config.getProperty("org.dbpedia.spotlight.core.database.jdbcdriver", "").trim();
    String coreDbConnector = config.getProperty("org.dbpedia.spotlight.core.database.connector", "").trim();
    String coreDbUser = config.getProperty("org.dbpedia.spotlight.core.database.user", "").trim();
    String coreDbPassword = config.getProperty("org.dbpedia.spotlight.core.database.password", "").trim();
    try {
        if (coreDbType.equals("jdbc")) {
            LOG.info("Core database from JDBC: " + coreDbConnector);
            createDBpediaResourceFactory(coreJdbcDriver, coreDbConnector, coreDbUser, coreDbPassword);
        } else {
            //else we leave the factory null, in that case, lucene will be used in BaseSearcher
            LOG.info("Core database from Lucene: " + contextIndexDirectory);
        }
    } catch (Exception e) {
        LOG.warn("Tried to use core database provided, but failed. Will use Lucene index as core database.", e);
    }
    //...

}

From source file:org.easynet.resource.queryparser.QueryParserBase.java

License:Apache License

/**
 * Initializes a query parser. Called by the QueryParser constructor
 * /*from w w w  .j ava 2s  .c  o  m*/
 * @param matchVersion
 *            Lucene version to match. See <a
 *            href="QueryParser.html#version">here</a>.
 * @param f
 *            the default field for query terms.
 * @param a
 *            used to find terms in the query text.
 */
public void init(Version matchVersion, String f, Analyzer a) {
    setAnalyzer(a);
    field = f;
    if (matchVersion.onOrAfter(Version.LUCENE_4_10_1)) {
        setAutoGeneratePhraseQueries(false);
    } else {
        setAutoGeneratePhraseQueries(true);
    }

    BooleanQuery.setMaxClauseCount(Integer.MAX_VALUE);
    fieldQueryTextStore = new QueryParserFieldQueryTextStore();
    referenceStore = new ReferenceStore();
}