Java Code Examples for org.apache.solr.search.SolrIndexSearcher#QueryCommand

The following examples show how to use org.apache.solr.search.SolrIndexSearcher#QueryCommand . 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: LocalDatasetGraph.java    From SolRDF with Apache License 2.0 6 votes vote down vote up
@Override
protected boolean _containsGraph(final Node graphNode) {
    final SolrIndexSearcher.QueryCommand cmd = new SolrIndexSearcher.QueryCommand();
    cmd.setQuery(new MatchAllDocsQuery());
    cmd.setLen(0);
    cmd.setFilterList(new TermQuery(new Term(Field.C, asNtURI(graphNode))));				
    
    final SolrIndexSearcher.QueryResult result = new SolrIndexSearcher.QueryResult();
    try {
		request.getSearcher().search(result, cmd);
	    return result.getDocListAndSet().docList.matches() > 0;
	} catch (final Exception exception) {
		LOGGER.error(MessageCatalog._00113_NWS_FAILURE, exception);
		throw new SolrException(ErrorCode.SERVER_ERROR, exception);
	}	    
}
 
Example 2
Source File: DeepPagingIterator.java    From SolRDF with Apache License 2.0 5 votes vote down vote up
/**
 * Builds a new iterator with the given data.
 * 
 * @param searcher the Solr index searcher.
 * @param queryCommand the query command that will be submitted.static 
 * @param sort the sort specs.
 * @param consumer the Graph event consumer that will be notified on relevant events.
 */
DeepPagingIterator(
		final SolrIndexSearcher searcher, 
		final SolrIndexSearcher.QueryCommand queryCommand, 
		final SortSpec sort, 
		final GraphEventConsumer consumer) {
	this.searcher = searcher;
	this.queryCommand = queryCommand;
	this.sentCursorMark = new CursorMark(searcher.getSchema(), sort);
	this.queryCommand.setCursorMark(sentCursorMark);
	this.consumer = consumer;
}
 
Example 3
Source File: LocalGraph.java    From SolRDF with Apache License 2.0 5 votes vote down vote up
/**
 * Graph size query command lazy loader.
 * 
 * @return the graph size query command.
 */
SolrIndexSearcher.QueryCommand graphSizeQueryCommand() {
	if (graphSizeQueryCommand == null) {
		graphSizeQueryCommand = new SolrIndexSearcher.QueryCommand();
		graphSizeQueryCommand.setQuery(new MatchAllDocsQuery());
		graphSizeQueryCommand.setLen(0);
		graphSizeQueryCommand.setFilterList(graphTermQuery);	
	}
	return graphSizeQueryCommand;
}
 
Example 4
Source File: LocalGraph.java    From SolRDF with Apache License 2.0 4 votes vote down vote up
SolrIndexSearcher.QueryCommand queryCommand(final Triple pattern, final SortSpec sortSpec) throws SyntaxError {
    final SolrIndexSearcher.QueryCommand cmd = new SolrIndexSearcher.QueryCommand();
    cmd.setQuery(new MatchAllDocsQuery());
    cmd.setSort(sortSpec.getSort());
    cmd.setLen(queryFetchSize);
    cmd.setFlags(cmd.getFlags() | SolrIndexSearcher.GET_DOCSET);
    
    final List<Query> filters = new ArrayList<Query>();
    
	final Node s = pattern.getMatchSubject();
	final Node p = pattern.getMatchPredicate();
	final Node o = pattern.getMatchObject();
	
	if (s != null) {
		filters.add(new TermQuery(new Term(Field.S, asNt(s))));
	}
	
	if (p != null) {
		filters.add(new TermQuery(new Term(Field.P, asNtURI(p))));
	}
	
	if (o != null) {
		if (o.isLiteral()) {
			final String language = o.getLiteralLanguage();
			filters.add(
					isNotNullOrEmptyString(language) 
						? languageTermQuery(language) 
						: NULL_LANGUAGE_TERM_QUERY);
			
			final String literalValue = o.getLiteralLexicalForm(); 
			final RDFDatatype dataType = o.getLiteralDatatype();
			registry.get(
					dataType != null 
						? dataType.getURI() 
						: null).addFilterConstraint(filters, literalValue, request);
		} else {
			filters.add(new TermQuery(new Term(Field.TEXT_OBJECT, asNt(o))));		
		}
	}
	
	filters.add(graphTermQuery);				
	
	cmd.setFilterList(filters);
	return cmd;
}