Click or drag to resize
SphinxClientQuery Method
Sends the specified query to searchd returns its result. If no index name is given, the query will be executed against all indexes. If a comment is provided it will be written to the query log by searchd.

Namespace: SphinxConnector.NativeApi
Assembly: SphinxConnector (in SphinxConnector.dll) Version: 3.12.6
Syntax
public SphinxSearchResult Query(
	string query,
	string indexName = "*",
	string comment = ""
)

Parameters

query
Type: SystemString
The query to execute.
indexName (Optional)
Type: SystemString
The name of the index(es) to query. Use "*" for all indexes.
comment (Optional)
Type: SystemString
A comment for this query, which will be written to the sphinx query log.

Return Value

Type: SphinxSearchResult
An instance of the SphinxSearchResult class with the query result.
Exceptions
ExceptionCondition
ArgumentNullException Parameter query or indexName is null.
ArgumentException Parameter query or indexName is empty.
InvalidOperationException There are queries which have been added via AddQuery(String, String, String), but have not yet been executed. Use RunQueries to execute these queries.
-or-
SortMode has been set to a value other than Relevance, but SortBy is empty. -or-
SortMode has been set to Relevance, but SortBy is not empty.
SphinxClientException An error occured while executing the query. See exception message and inner exception for details.
Remarks
Note that the index name is case-sensitive!
Examples
SphinxClient sphinxClient = new SphinxClient(); //Use SphinxClient with the default options.
SphinxSearchResult result = sphinxClient.Query("query", "myindex", "comment");

foreach (SphinxMatch match in result.Matches)
{
    Console.WriteLine("DocumentId {0} Weight {1}", match.DocumentId, match.Weight);
}
To query multiple indexes, pass a comma separated string with the index names as a parameter to the Query() method:
SphinxClient sphinxClient = new SphinxClient(); //Use SphinxClient with the default options.
SphinxSearchResult result = sphinxClient.Query("query", "myindex, myOtherIndex");
See Also