Java Code Examples for org.apache.lucene.search.BooleanQuery#setMaxClauseCount()

The following examples show how to use org.apache.lucene.search.BooleanQuery#setMaxClauseCount() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LuceneHelperImpl.java    From tephra with MIT License 6 votes vote down vote up
private synchronized Directory get(String key) {
    if (map == null) {
        map = new ConcurrentHashMap<>();
        BooleanQuery.setMaxClauseCount(Integer.MAX_VALUE);
    }

    return map.computeIfAbsent(key, k -> {
        Path path = Paths.get(context.getAbsoluteRoot(), root, k, "index");
        io.mkdirs(path.toFile());
        if (logger.isInfoEnable())
            logger.info("设置Lucene索引根目录[{}:{}]。", k, path);
        try {
            return FSDirectory.open(path);
        } catch (IOException e) {
            logger.warn(e, "打开Lucene索引目录[{}:{}]时发生异常!", k, path);

            return null;
        }
    });
}
 
Example 2
Source File: LuceneHelper.java    From dexter with Apache License 2.0 6 votes vote down vote up
/**
 * Opens or creates a lucene index in the given directory
 * 
 * @param wikiIdtToLuceneIdSerialization
 *            - the file containing the serialized mapping between wiki-id
 *            and Lucene documents ids
 * 
 * @param indexPath
 *            - the path of the directory with the Lucene's index
 */
protected LuceneHelper(File wikiIdtToLuceneIdSerialization, File indexPath) {
	logger.info("opening lucene index in folder {}", indexPath);
	config = new IndexWriterConfig(Version.LUCENE_41, ANALYZER);
	this.wikiIdtToLuceneIdSerialization = wikiIdtToLuceneIdSerialization;

	BooleanQuery.setMaxClauseCount(1000);

	try {
		index = FSDirectory.open(indexPath);
		// writer.commit();
	} catch (Exception e) {
		logger.error("opening the index: {}", e.toString());
		System.exit(1);
	}

	summarizer = new ArticleSummarizer();
	writer = getWriter();
	collectionSize = writer.numDocs();
	wikiIdToLuceneId = Collections.emptyMap();
}
 
Example 3
Source File: BibleSearchIndex.java    From Quelea with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Search for bible chapters that match the given filter.
 *
 * @param queryString the query string to filter.
 * @param type ignored - may be null.
 * @return a list of all bible chapters that match the given filter.
 */
@Override
public BibleChapter[] filter(String queryString, FilterType type) {
    String sanctifyQueryString = SearchIndexUtils.makeLuceneQuery(queryString);
    if(chapters.isEmpty() || sanctifyQueryString.isEmpty()) {
        return chapters.values().toArray(new BibleChapter[chapters.size()]);
    }
    List<BibleChapter> ret;
    try (DirectoryReader dr = DirectoryReader.open(index)) {
        IndexSearcher searcher = new IndexSearcher(dr);
        BooleanQuery.setMaxClauseCount(Integer.MAX_VALUE);
        Query q = new ComplexPhraseQueryParser("text", analyzer).parse(sanctifyQueryString);
        TopScoreDocCollector collector = TopScoreDocCollector.create(10000,10000);
        searcher.search(q, collector);
        ScoreDoc[] hits = collector.topDocs().scoreDocs;
        ret = new ArrayList<>();
        for(int i = 0; i < hits.length; ++i) {
            int docId = hits[i].doc;
            Document d = searcher.doc(docId);
            BibleChapter chapter = chapters.get(Integer.parseInt(d.get("number")));
            ret.add(chapter);
        }
        return ret.toArray(new BibleChapter[ret.size()]);
    }
    catch (ParseException | IOException ex) {
        LOGGER.log(Level.WARNING, "Invalid query string: " + sanctifyQueryString, ex);
        return new BibleChapter[0];
    }
}
 
Example 4
Source File: AbstractLuceneIndexerAndSearcherFactory.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Set the max number of queries in a llucen boolean query
 * 
 * @param queryMaxClauses int
 */
@Override
public void setQueryMaxClauses(int queryMaxClauses)
{
    this.queryMaxClauses = queryMaxClauses;
    BooleanQuery.setMaxClauseCount(this.queryMaxClauses);
}
 
Example 5
Source File: Txt2PubmedId.java    From bluima with Apache License 2.0 5 votes vote down vote up
public Txt2PubmedId(File indexPath) throws IOException {

		Directory dir = FSDirectory.open(indexPath);
		indexReader = DirectoryReader.open(dir);
		searcher = new IndexSearcher(indexReader);

		Analyzer analyzer = Txt2PubmedIdIndexer.getAnalyzer();

		parser = new QueryParser(LUCENE_41, CONTENT_FIELD, analyzer);
		BooleanQuery.setMaxClauseCount(MAX_VALUE);
	}
 
Example 6
Source File: BoolQueryParser.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Inject
public BoolQueryParser(Settings settings) {
    BooleanQuery.setMaxClauseCount(settings.getAsInt("index.query.bool.max_clause_count", settings.getAsInt("indices.query.bool.max_clause_count", BooleanQuery.getMaxClauseCount())));
}
 
Example 7
Source File: Lucene.java    From StreamingRec with Apache License 2.0 4 votes vote down vote up
@Override
public LongArrayList recommendInternal(ClickData clickData) {
	//create a result list
	LongArrayList results = new LongArrayList();
	try {
		//determine the input query, which can either be based on the current item 
		//or all items from the current session depending on the configuration
		String input;
		if (!wholeSession){
			//extract the content from the current item
			input = extractContent(clickData.click.item);
		}else{
			//iteratively append the content of every item from the current user session
			input="";
			for (int i = 0 ; i<clickData.session.size(); i++ ){
				input += " "+ extractContent(clickData.session.get(i).item);
			}
		}
		//avoid an exception that happens for too large queries
           BooleanQuery.setMaxClauseCount(Integer.MAX_VALUE);
           //create a query
		Query q = new QueryParser("text", analyzer)
				.parse(QueryParserUtil.escape(input));
		//set an unreasonably high retrieval amount, because we want a long recommendation list
		int hitsPerPage = 100000;
		//instantiate the retrieval objects
		IndexReader reader = DirectoryReader.open(index);
		IndexSearcher searcher = new IndexSearcher(reader);
		TopScoreDocCollector collector = TopScoreDocCollector.create(hitsPerPage);
		//execute the query
		searcher.search(q, collector);
		//iterate the hits and extract the item ids
		ScoreDoc[] hits = collector.topDocs().scoreDocs;
		for (int i = 1; i < hits.length; ++i) {
			if (hits[i].score < minScore) {
				//stop retrieving, if the lucene score is too low
				break;
			}
			int docId = hits[i].doc;
			Document d = searcher.doc(docId);
			results.add(Long.parseLong(d.get("id")));
		}
		reader.close();
	} catch (ParseException | IOException e) {
		e.printStackTrace();
	}
	//return the results
	return results;
}
 
Example 8
Source File: StartNode.java    From lumongo with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
	LogUtil.loadLogConfig();

	OptionParser parser = new OptionParser();
	OptionSpec<File> mongoConfigArg = parser.accepts(AdminConstants.MONGO_CONFIG).withRequiredArg().ofType(File.class).describedAs("Mongo properties file")
					.required();
	OptionSpec<String> serverAddressArg = parser.accepts(AdminConstants.ADDRESS).withRequiredArg().describedAs("Specific Server Address Manually");
	OptionSpec<Integer> hazelcastPortArg = parser.accepts(AdminConstants.HAZELCAST_PORT).withRequiredArg().ofType(Integer.class)
					.describedAs("Hazelcast port if multiple instances on one server (expert)");


	try {
		OptionSet options = parser.parse(args);

		File mongoConfigFile = options.valueOf(mongoConfigArg);
		String serverAddress = options.valueOf(serverAddressArg);
		Integer hazelcastPort = options.valueOf(hazelcastPortArg);

		MongoConfig mongoConfig = MongoConfig.getNodeConfig(mongoConfigFile);

		if (serverAddress == null) {
			serverAddress = ServerNameHelper.getLocalServer();
			System.out.println("Using <" + serverAddress + "> as the server address.  If this is not correct please specify on command line");
		}

		if (hazelcastPort == null) {
			hazelcastPort = LumongoConstants.DEFAULT_HAZELCAST_PORT;
		}

		BooleanQuery.setMaxClauseCount(16 * 1024);
		FacetsConfig.DEFAULT_DIM_CONFIG.multiValued = true;

		LumongoNode luceneNode = new LumongoNode(mongoConfig, serverAddress, hazelcastPort);

		luceneNode.start();
		luceneNode.setupShutdownHook();

	}
	catch (OptionException e) {
		System.err.println("ERROR: " + e.getMessage());
		parser.formatHelpWith(new LumongoHelpFormatter());
		parser.printHelpOn(System.err);
		System.exit(2);
	}

}