Version of search to search a single table.
Namespace: NetricsServerInterface
Assembly: NetricsServerInterface (in NetricsServerInterface.dll)
Syntax
Visual Basic (Declaration) |
---|
Public Function search( _ ByVal tblCfg As NetricsSearchCfg, _ ByVal opts As NetricsSearchOpts _ ) As NetricsSearchResponse _ Implements INetricsServerInterface.search |
C# |
---|
public NetricsSearchResponse search( NetricsSearchCfg tblCfg, NetricsSearchOpts opts ) |
C++ |
---|
public: NetricsSearchResponse search( NetricsSearchCfg tblCfg, NetricsSearchOpts opts ) sealed |
J# |
---|
public NetricsSearchResponse search( NetricsSearchCfg tblCfg, NetricsSearchOpts opts ) |
JScript |
---|
public
function search( tblCfg : NetricsSearchCfg, opts : NetricsSearchOpts ) : NetricsSearchResponse |
Parameters
- tblCfg
- opts
Implements
INetricsServerInterface.search
Example
This sample shows how to perform a search of a TIBCO Patterns Engine table.
![]() | |
---|---|
// In this example a Simple search will be configured. The sample demonstrates searching // the names table for the query string "brown dennis". The fields to matched against this // string are "last" and "first". The weight for "last" is 1.0 and for "first" is .5. In this // case the "last" name will have a higher importance in the score so that records with a "last" // match will have a higher similarity score than those of "first" and will appear higher in the // result set in the response. 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); // Quuery will contain the query string or tokens to be matched against String query = "brown dennis"; // Table is the TIBCO Patterns Engine table to be search/matched against query String table = "names"; // 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" , "first"}; // FieldWeights is an array that must be the same length as fields and contain the // weights (0.0 - 1.0) of each field that contribute to the overall score of the result double[] fieldWeights = { 1.0, .5 }; // 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); // Add a Simple query to the NetricsSearchCfg using the query, fieldNames and fieldWeights tblCfg.setNetricsQuery(NetricsQuery.Simple(query, fieldNames, fieldWeights)); // 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"); } } } // The following is an example of a multi-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 "first" field. Each of these queries are referred to as a querylet. We will // apply a higher weight to the "last" field querylet and apply a the "nicknames" thesaurus to the // "first" field querylet treating the related terms within the thesaurus as equivalent. 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 TIBCO Patterns Engine 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 = "brown"; // 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 = "den"; fieldNames[0] = "first"; nqs[1] = NetricsQuery.Simple(query, fieldNames, null); // Use the nicknames thesaurus for this querylet associated with "first" field search // and with the weight of 1.0 to treat related terms or synanyms the same. // i.e. "Den" is equivalent to "Dennis" nqs[1].useThesaurus("nicknames", 1.0); // QueryletWeights is an array that must be the same length as the number of querylets // and is the weight applied to each querylet in the search which impacts the similarity // scrore. In this case there will be two querylets that will be ANDed together to create // a single search configuration double[] queryletWeights = { 1.0, .5 }; // Now AND the two Simple querys together to create the final NetricsQuery for the search NetricsQuery nqAnded = NetricsQuery.And(queryletWeights, nqs); // Set the NetricsSearchCfg; tblCfg.setNetricsQuery(nqAnded); // 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"); } } } // This an example of using a Cognate Query. It uses the same string comparison algorithm but performs // the match with multiple query strings. For instance, a first and last name can be searched against // the first and last name fields of the database. This aids in finding transposted fields (where a first // name occurs in the last name field or vice versa). The length of the qstrs array must always equal the // length of the fldnames array. The fldweights array should also be that length if is used. The noncogwgt // is the weight to assign transposed field matches (if noncogwgt is set to .8, a first name match in the // last name field would contribute 80% to the final score). 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); // Quuery array will contain the query strings or tokens to be matched against String [] queryStringArray = {"brown", "dennis"}; // Table is the TIBCO Patterns Engine table to be search/matched against query String table = "names"; // 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", "first" }; // FieldWeights is an array that must be the same length as fields and contain the // weights (0.0 - 1.0) of each field that contribute to the overall score of the result double[] fieldWeights = { 1.0, .5 }; // 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); // Add a Cognate query to the NetricsSearchCfg using the query strings, fieldNames, // fieldWeights and a cognateweight which is used to lower the score of miss fielded // records. In this case "last"="brown" and "first"="dennis" is an exact match // with a similarity score of 1, while "last"="dennis" and "first"="brown" will be a // match with a similarity score of .8 // Use a cognate weight of .8 double cognateweight = .8; tblCfg.setNetricsQuery(NetricsQuery.Cognate(queryStringArray, fieldNames, fieldWeights, cognateweight)); // 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"); } } } |