Create a weighted field query expression node.
Namespace: NetricsServerInterface
Assembly: NetricsServerInterface (in NetricsServerInterface.dll)
Syntax
Visual Basic (Declaration) |
---|
Public Shared Function Wgtbyfield( _ ByVal fieldName As String, _ ByVal nq As NetricsQuery _ ) As NetricsQuery |
C# |
---|
public static NetricsQuery Wgtbyfield( string fieldName, NetricsQuery nq ) |
C++ |
---|
public: static NetricsQuery Wgtbyfield( String fieldName, NetricsQuery nq ) |
J# |
---|
public static NetricsQuery Wgtbyfield( string fieldName, NetricsQuery nq ) |
JScript |
---|
public static
function Wgtbyfield( fieldName : String, nq : NetricsQuery ) : NetricsQuery |
Remarks
This replaces record weights from earlier versions of Netrics software. Essentially the user can pass in a currently constructed NetricsQuery to be weighted by the value in a specified field in a each record in the result set. It is assumed that the value of that field is a floating point value.
Example
This sample shows how to perform a search of a TIBCO Patterns Engine table using a Simple query apply the Wgtbyfield method to influence the similarity score on record result set..
![]() | |
---|---|
// In this example a Simple search will be configured. The sample demonstrates searching // the "books" table for the query string "StephenKing". The field to matched against this // string is "Author". The similarity score for each record in the result set will be altered // by the multiplier value in a field called "Wgt". 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); // Query will contain the query string or tokens to be matched against String query = "StephenKing"; // Table is the TIBCO Patterns Engine table to be search/matched against query String table = "books"; // 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 = { "Author" }; // 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 // using the field "Wgt" as a multiplier to the record similarity score in the result set tblCfg.setNetricsQuery(NetricsQuery.Wgtbyfield("Wgt", NetricsQuery.Simple(query, fieldNames, null))); // 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"); } } } |