Create an OR Query Expression Node
Namespace: NetricsServerInterface
Assembly: NetricsServerInterface (in NetricsServerInterface.dll)
Syntax
| Visual Basic (Declaration) |
|---|
| Public Shared Function Or( _ ByVal weights As Double(), _ ByVal nqs As NetricsQuery() _ ) As NetricsQuery |
| C# |
|---|
| public static NetricsQuery Or( double[] weights, NetricsQuery[] nqs ) |
| C++ |
|---|
| public: static NetricsQuery Or( array<double>^ weights, array<NetricsQuery>^ nqs ) |
| J# |
|---|
| public static NetricsQuery Or( double[] weights, NetricsQuery[] nqs ) |
| JScript |
|---|
| public static
function Or( weights : double[], nqs : NetricsQuery[] ) : NetricsQuery |
Parameters
- weights
- list of floats that are the weights for the sub expressions of this query
- nqs
- list of NetricsQuery objects that are the sub expressions for this OR
Remarks
This is used to choose between multiple NetricsQuery scores by taking the maximum score. To weight the individual scores, the user can utilize the weights parameter.
Example
This sample shows an OR query using 2 querylets that are then Or'd together.
Copy Code
| |
|---|---|
// This is an example of an OR query where different query strings can be used in a search across
// different fields within a table. This requires first configuring a Simple query for each query
// string along with the fields to be searched and then either "And" or "Or" them together. In this
// example we will query the "names" table using a query string against the "last" field and a another
// query string against the "ssn" field. Each of these queries are referred to as a querylet. We will
// Or them together to get the highest similarity score for either the "last" field querylet or the
// "ssn" field querylet.
using System;
using NetricsServerInterface;
class MyClass
{
private static NetricsServerInterface.NetricsServerInterface si = null;
public static void Main()
{
try
{
String host = "localhost";
int port = 5051;
si = new NetricsServerInterface.NetricsServerInterface(host, port);
// Table is the ibi™ Patterns - Search table to be search/matched against query
String table = "names";
// Going to use 2 NetricsQuery for the search configuration
NetricsQuery[] nqs = new NetricsQuery[2];
// Create NetricsSearchOpts object using the defaults
NetricsSearchOpts opts = new NetricsSearchOpts();
// Create the NetricsSearchCfg pointing to the table to be searched/matched against
NetricsSearchCfg tblCfg = new NetricsSearchCfg(table);
// Query will contain the query string for the first querylet which is "last
String query = "Zeuinsky";
// FieldNames contain the fields within the table to be searhed/matched against.
// If fieldNames is set to null then all fields will be searched/matched against
String[] fieldNames = { "last" };
// Create a Simple query for the "last" names search
nqs[0] = NetricsQuery.Simple(query, fieldNames, null);
// Set up the second Simple query
query = "123456789";
fieldNames[0] = "ssn";
nqs[1] = NetricsQuery.Simple(query, fieldNames, null);
// Now Or the two Simple querys together to create the final NetricsQuery for the search.
// Use null in first paramter to indicate the querylets will have the same weight relative
// to each other if that is what is desired
NetricsQuery nqOred = NetricsQuery.Or(null, nqs);
// Set the NetricsSearchCfg;
tblCfg.setNetricsQuery(nqOred);
// Perform the search/match using the NetricsSearchCfg and NetricsSearchOpts
NetricsSearchResponse resp = si.search(tblCfg, opts);
String s = "";
// Get the results of the search/match
NetricsSearchResult[] res = resp.getSearchResults();
// Create viables for result processing
String[] xfieldNames;
String[] xfields;
// Iterate through the result records
for (int i = 0; i < res.Length; i++)
{
// Get the fieldNames in the result record
xfieldNames = res[i].getFieldNames();
// Get the data for each fieldName in result record
xfields = res[i].getFields();
// Get the score for this result record
double score = res[i].getMatchScore();
// Build the printline for the result record
s = s + "Rank=" + i + ", Score=" + score.ToString();
for (int x = 0; x < xfields.Length; x++)
{
s = s + ", " + xfieldNames[x] + "=" + xfields[x];
}
s = s + "\n";
}
Console.WriteLine(s);
}
catch (NetricsException e)
{
Console.Write(e.getErrorDescription() + "\n");
}
}
}
| |