Nextis.SmartSearch.Client: Porovnání verzí

Z Podpora.nextis.cz
Přejít na: navigace, hledání
Řádka 4: Řádka 4:
  
 
==== Referenced libraries ====
 
==== Referenced libraries ====
* Core.UI.Culture.dll
+
* Core.UI.Culture.dll (provided by Nextis)
* Nextis.SmartSearch.Client.dll
+
* Nextis.SmartSearch.Client.dll (provided by Nextis)
* Nextis.SmartSearch.Proxy.dll
+
* Nextis.SmartSearch.Proxy.dll (provided by Nextis)
  
 
==== Framework ====
 
==== Framework ====
Řádka 19: Řádka 19:
 
==== Declaration of the client object ====
 
==== Declaration of the client object ====
 
<syntaxhighlight lang="vb">
 
<syntaxhighlight lang="vb">
Private WithEvents Client As Nextis.SmartSearch.Client.SmartSearchClient
 
</syntaxhighlight><syntaxhighlight lang="vb.net">
 
 
Private WithEvents Client As Nextis.SmartSearch.Client.SmartSearchClient
 
Private WithEvents Client As Nextis.SmartSearch.Client.SmartSearchClient
 
</syntaxhighlight>
 
</syntaxhighlight>
 
 
==== Initialization of the client object ====
 
==== Initialization of the client object ====
 
<syntaxhighlight lang="vb.net">
 
<syntaxhighlight lang="vb.net">
Řádka 30: Řádka 27:
 
     With Config
 
     With Config
 
         .Mode = Nextis.SmartSearch.Client.SmartSearchClient.ClientMode.RemoteWS
 
         .Mode = Nextis.SmartSearch.Client.SmartSearchClient.ClientMode.RemoteWS
         .WSAddress = "obelix2.nextis.cz:32888"
+
         .WSAddress = "smartsearch.nextis.cz:port"
         .AuthorizationToken = "nextis"
+
         .AuthorizationToken = "token"
 
     End With
 
     End With
 
     Me.Client = New Nextis.SmartSearch.Client.SmartSearchClient(Config)
 
     Me.Client = New Nextis.SmartSearch.Client.SmartSearchClient(Config)
 
End Sub
 
End Sub
 +
</syntaxhighlight>Put your authorization token and address instead of the address in the example.
 +
 +
INFO: After the initialization of client object, should be the status connected <code>Client.Status =SmartSearchClient.ClientStatuses._initialized</code>
 +
 +
==== Searching through the client ====
 +
 +
===== 1.Creating request =====
 +
<syntaxhighlight lang="vb.net">
 +
'Create request
 +
Dim rq As New Nextis.SmartSearch.Proxy.SmartSearchRequest('Text to recognize', Core.UI.Culture.Languages.de)
 +
 +
'Enable/disable recognition options
 +
With rq
 +
    .AllowCar = True
 +
    .AllowCode = True
 +
    .AllowKBA = False 'Not implemented yet
 +
    .AllowText = True
 +
    .AllowVIN = True
 +
    '.CarSpecificModelYearFrom = 1990 'Allows you to limit the vehicle specific result to vehicles, manufactured since the specified construction year
 +
End With
 +
</syntaxhighlight>Put text to recognize into the request and choose the proper language from the enum of supported languages.
 +
 +
===== 3.Sending request =====
 +
 +
====== Asynchronous ======
 +
<syntaxhighlight lang="vb.net">
 +
Me.Client.SmartSearchAsync(rq)
 +
</syntaxhighlight>
 +
* The result is available only within the event SearchFinished
 +
* This version is most useful in a winforms application
 +
* In case of more threads (search requests) at the same time is always returned the last one and all previous are cancelled
 +
 +
====== Synchronous ======
 +
<syntaxhighlight lang="vb.net">
 +
Dim rp As Nextis.SmartSearch.Proxy.SmartSearchResult = Me.Client.SmartSearch(rq)
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
* The result is available within the event SearchFinished and also as a return value of the method
 +
* Most useful in a web application to manage multi-threading on your own
  
==== Searching through the client ====
+
===== 4.Getting response =====
 +
For both synchronous and asynchronous calling, you can get the result within the event <code>Client.SearchFinished</code> that is also the preferred option.<syntaxhighlight lang="vb.net">
 +
Private Sub Client_SearchFinished(Data As SmartSearchResult) Handles Client.SearchFinished
 +
    Dim Info As String = ""
 +
    If Data.ResultState = Nextis.SmartSearch.Proxy.Definitions.ResponseStatus.Ok Then
 +
        For Each SearchType As Nextis.SmartSearch.Proxy.Definitions.SearchTargetTypes In Data.ResultPercentage.Keys
 +
            Info &= SearchType.ToString & ": " & Data.ResultPercentage(SearchType) & "%" & vbCrLf
 +
        Next
  
===== Creating request =====
+
        'Vehicle specific data (filled whend enginde decides that user is lookinf for specific vehicle)
 +
        If Data.ResultPercentage(Definitions.SearchTargetTypes.Car) > 50.0 Then
 +
            If Not Data.VehicleSpecificData Is Nothing Then
 +
                For Each cr As SmartSearch.Proxy.VehicleSpecific.VehicleSearchResult In Data.VehicleSpecificData.Models
  
===== Sending request =====
+
                    'Case when result contain only vehicle specific data (does not contain any generic articles)
 +
                    If Data.VehicleSpecificData.Articles.Count = 0 Then
 +
                        Dim vInfo As String = cr.ManuID & "_" & cr.ModelID & "_" & cr.EngineID & "_" & -1 & ", "
 +
                        vInfo &= cr.ManuName + " " + cr.ModelName & ", "
 +
                        If cr.EngineID > 0 Then
 +
                            vInfo &= cr.EngineName & ", "
 +
                            vInfo &= cr.EnginePowerHP & ", "
 +
                            vInfo &= cr.EnginePowerKW & ", "
 +
                            vInfo &= cr.EngineConstFrom & " - " & IIf(Val(cr.EngineConstTo) > 2500, " > ", cr.EngineConstTo) & ", "
 +
                        Else
 +
                            vInfo &= "-" & ", "
 +
                            vInfo &= "-" & ", "
 +
                        End If
 +
                        vInfo &= "-"
 +
                        vInfo &= "Ranking:" & Format(cr.RankCar * 1000, "#00000") & "_" & cr.ModelName & "_" & cr.EngineName & ", "
 +
                        Info &= Chr(10) & vInfo
 +
                    Else
 +
                        'Case when result contains vehicle specific data and also generic articles
 +
                        For Each Article As SmartSearch.Proxy.VehicleSpecific.VehicleConstructionGroup In Data.VehicleSpecificData.Articles
 +
                            If cr.SupportedArticlesIDs.Contains(Article.ID) = True Then
 +
                                Dim vInfo As String = cr.ManuID & "_" & cr.ModelID & "_" & cr.EngineID & "_" & Article.ID & ", "
 +
                                vInfo &= cr.ManuName + " " + cr.ModelName & ", "
 +
                                If cr.EngineID > 0 Then
 +
                                    vInfo &= cr.EngineName & ", "
 +
                                    vInfo &= cr.EnginePowerHP & ", "
 +
                                    vInfo &= cr.EnginePowerKW & ", "
 +
                                    vInfo &= cr.EngineConstFrom & " - " & IIf(Val(cr.EngineConstTo) > 2500, " > ", cr.EngineConstTo) & ", "
 +
                                Else
 +
                                    vInfo &= "-" & ", "
 +
                                    vInfo &= "-" & ", "
 +
                                End If
 +
                                vInfo &= Article.Phrase & " " & " (ID " & Article.ID & ")" & ","
 +
                                vInfo &= "Ranking:" & Format(cr.RankCar * 1000, "#00000") & "_" & cr.ModelName & "_" & cr.EngineName & "_" & Format(Article.Match, "#00000.0000")
 +
                                Info &= Chr(10) & vInfo
 +
                            End If
 +
                        Next
 +
                    End If
 +
                Next
 +
            End If
 +
        End If
 +
    Else
 +
        Info = Data.ResultState.ToString
 +
    End If
  
===== Getting response =====
+
    Me.TextBox2.Text = Info
 +
End Sub
 +
</syntaxhighlight>The example above shows, ho to handle the result of the SmartSearch.Client. The variable Data as SmartSearchResult contains all possible information about the pattern recognition, vehicle specific data including EngineID's, GenericArticleID's and so on.
  
 
==== Obtaining the service state ====
 
==== Obtaining the service state ====
 +
Provides general information about the SmartSearch service, you are connected to.<syntaxhighlight lang="vb.net">
 +
Dim ServiceInfoResponse = Me.Client.ServiceInfo
 +
With ServiceInfoResponse
 +
    '.ActiveLanguages (list of currently supported languages)
 +
    '.ArticleCount (count of all available generic articles)
 +
    '.CarModelCount (count of all available vehicle models)
 +
    '.RelationCount (count of relations between vehicles and generic articles)
 +
    '.ResultState (general information that request has been processed properly)
 +
    '.Loaded (true if service is properly loaded into the memory)
 +
End With
 +
</syntaxhighlight>

Verze z 5. 7. 2019, 11:27

This article describes, how to implement and use Nextis.SmartSearch technology within the third party products.

Prerequisities

Referenced libraries

  • Core.UI.Culture.dll (provided by Nextis)
  • Nextis.SmartSearch.Client.dll (provided by Nextis)
  • Nextis.SmartSearch.Proxy.dll (provided by Nextis)

Framework

  • .NET Framework ver.: 4.6.1 and higher

Connection information

  • Authorization token (provided by Nextis)
  • Service location/address (provided by Nextis)

Implementation

Declaration of the client object

Private WithEvents Client As Nextis.SmartSearch.Client.SmartSearchClient

Initialization of the client object

Sub Initialize()
    Dim Config As New Nextis.SmartSearch.Client.SmartSearchClientConfiguration()
    With Config
        .Mode = Nextis.SmartSearch.Client.SmartSearchClient.ClientMode.RemoteWS
        .WSAddress = "smartsearch.nextis.cz:port"
        .AuthorizationToken = "token"
    End With
    Me.Client = New Nextis.SmartSearch.Client.SmartSearchClient(Config)
End Sub
Put your authorization token and address instead of the address in the example.

INFO: After the initialization of client object, should be the status connected Client.Status =SmartSearchClient.ClientStatuses._initialized

Searching through the client

1.Creating request
'Create request
Dim rq As New Nextis.SmartSearch.Proxy.SmartSearchRequest('Text to recognize', Core.UI.Culture.Languages.de)

'Enable/disable recognition options
With rq
    .AllowCar = True
    .AllowCode = True
    .AllowKBA = False 'Not implemented yet
    .AllowText = True
    .AllowVIN = True
    '.CarSpecificModelYearFrom = 1990 'Allows you to limit the vehicle specific result to vehicles, manufactured since the specified construction year
End With
Put text to recognize into the request and choose the proper language from the enum of supported languages.
3.Sending request
Asynchronous
Me.Client.SmartSearchAsync(rq)
  • The result is available only within the event SearchFinished
  • This version is most useful in a winforms application
  • In case of more threads (search requests) at the same time is always returned the last one and all previous are cancelled
Synchronous
Dim rp As Nextis.SmartSearch.Proxy.SmartSearchResult = Me.Client.SmartSearch(rq)
  • The result is available within the event SearchFinished and also as a return value of the method
  • Most useful in a web application to manage multi-threading on your own
4.Getting response
For both synchronous and asynchronous calling, you can get the result within the event Client.SearchFinished that is also the preferred option.
Private Sub Client_SearchFinished(Data As SmartSearchResult) Handles Client.SearchFinished
    Dim Info As String = ""
    If Data.ResultState = Nextis.SmartSearch.Proxy.Definitions.ResponseStatus.Ok Then
        For Each SearchType As Nextis.SmartSearch.Proxy.Definitions.SearchTargetTypes In Data.ResultPercentage.Keys
            Info &= SearchType.ToString & ": " & Data.ResultPercentage(SearchType) & "%" & vbCrLf
        Next

        'Vehicle specific data (filled whend enginde decides that user is lookinf for specific vehicle)
        If Data.ResultPercentage(Definitions.SearchTargetTypes.Car) > 50.0 Then
            If Not Data.VehicleSpecificData Is Nothing Then
                For Each cr As SmartSearch.Proxy.VehicleSpecific.VehicleSearchResult In Data.VehicleSpecificData.Models

                    'Case when result contain only vehicle specific data (does not contain any generic articles)
                    If Data.VehicleSpecificData.Articles.Count = 0 Then
                        Dim vInfo As String = cr.ManuID & "_" & cr.ModelID & "_" & cr.EngineID & "_" & -1 & ", "
                        vInfo &= cr.ManuName + " " + cr.ModelName & ", "
                        If cr.EngineID > 0 Then
                            vInfo &= cr.EngineName & ", "
                            vInfo &= cr.EnginePowerHP & ", "
                            vInfo &= cr.EnginePowerKW & ", "
                            vInfo &= cr.EngineConstFrom & " - " & IIf(Val(cr.EngineConstTo) > 2500, " > ", cr.EngineConstTo) & ", "
                        Else
                            vInfo &= "-" & ", "
                            vInfo &= "-" & ", "
                        End If
                        vInfo &= "-"
                        vInfo &= "Ranking:" & Format(cr.RankCar * 1000, "#00000") & "_" & cr.ModelName & "_" & cr.EngineName & ", "
                        Info &= Chr(10) & vInfo
                    Else
                        'Case when result contains vehicle specific data and also generic articles
                        For Each Article As SmartSearch.Proxy.VehicleSpecific.VehicleConstructionGroup In Data.VehicleSpecificData.Articles
                            If cr.SupportedArticlesIDs.Contains(Article.ID) = True Then
                                Dim vInfo As String = cr.ManuID & "_" & cr.ModelID & "_" & cr.EngineID & "_" & Article.ID & ", "
                                vInfo &= cr.ManuName + " " + cr.ModelName & ", "
                                If cr.EngineID > 0 Then
                                    vInfo &= cr.EngineName & ", "
                                    vInfo &= cr.EnginePowerHP & ", "
                                    vInfo &= cr.EnginePowerKW & ", "
                                    vInfo &= cr.EngineConstFrom & " - " & IIf(Val(cr.EngineConstTo) > 2500, " > ", cr.EngineConstTo) & ", "
                                Else
                                    vInfo &= "-" & ", "
                                    vInfo &= "-" & ", "
                                End If
                                vInfo &= Article.Phrase & " " & " (ID " & Article.ID & ")" & ","
                                vInfo &= "Ranking:" & Format(cr.RankCar * 1000, "#00000") & "_" & cr.ModelName & "_" & cr.EngineName & "_" & Format(Article.Match, "#00000.0000")
                                Info &= Chr(10) & vInfo
                            End If
                        Next
                    End If
                Next
            End If
        End If
    Else
        Info = Data.ResultState.ToString
    End If

    Me.TextBox2.Text = Info
End Sub
The example above shows, ho to handle the result of the SmartSearch.Client. The variable Data as SmartSearchResult contains all possible information about the pattern recognition, vehicle specific data including EngineID's, GenericArticleID's and so on.

Obtaining the service state

Provides general information about the SmartSearch service, you are connected to.
Dim ServiceInfoResponse = Me.Client.ServiceInfo
With ServiceInfoResponse
    '.ActiveLanguages (list of currently supported languages)
    '.ArticleCount (count of all available generic articles)
    '.CarModelCount (count of all available vehicle models)
    '.RelationCount (count of relations between vehicles and generic articles)
    '.ResultState (general information that request has been processed properly)
    '.Loaded (true if service is properly loaded into the memory)
End With