none
Search engine RRS feed

  • Question

  • hi,

    I'm wanting to create an advanced search on a asp.net page that when a phrase is entered it runs a command and returns results based on relevance

    so my example would be to search for the phrase "big red bus"

    it would then search my sql table

    id   | result

    1    | green bike

    2    | silver bus

    3    | red bus

    4    | red car

    5    | big red bus

    and would then display the results via relevance or how many words it matched up with

    so the order displayed to my user would be

    5    | big red bus

    3    | red bus

    2    | silver bus

    4    | red car

    any help on where to look for relevant code or the best method to go about this would be great

    thanks

    Tuesday, January 22, 2019 5:02 PM

All replies

  • Hi

    Here is one way.

    This is a stand alone example with NO exception handling.

    This example uses a couple of default DataGridViews to displkay the data from two DataTables (d1 and d2)

    Image

    Code

    ' Form1 with DataGridView1,
    ' DataGridView2, TextBox1 and Button1
    Option Strict On
    Option Explicit On
    Public Class Form1
      Dim dt, dt2 As New DataTable("Freddy")
      Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        With dt
          .Columns.Add("ID")
          .Columns.Add("Result")
          .Rows.Add(1, "Green Bike")
          .Rows.Add(2, "Silver Bike")
          .Rows.Add(3, "Red Bus")
          .Rows.Add(4, "Red Car")
          .Rows.Add(5, "Big Red Bus")
        End With
        DataGridView1.DataSource = dt.DefaultView
        With dt2
          .Columns.Add("ID")
          .Columns.Add("Result")
          .Columns.Add("SortID")
        End With
        DataGridView2.DataSource = dt2.DefaultView
        DataGridView2.Columns("SortID").Visible = False
      End Sub
      Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        dt2.Clear()
        Dim s As New List(Of String)
        s = TextBox1.Text.ToUpper.Split(" "c).ToList
    
        For i As Integer = 0 To dt.Rows.Count - 1
          Dim c As Integer = 0
          Dim s2 As New List(Of String)
          s2 = dt(i).Item("Result").ToString.ToUpper.Split(" "c).ToList
          For Each a As String In s
            If s2.Contains(a) Then c += 1
          Next
          dt2.Rows.Add(i + 1, dt(i).Item("Result").ToString, c)
        Next
        DataGridView2.Sort(DataGridView2.Columns("SortID"), ComponentModel.ListSortDirection.Descending)
      End Sub
    End Class
    



    Regards Les, Livingston, Scotland


    • Edited by leshay Tuesday, January 22, 2019 6:03 PM Forgot to inc ID numnbers
    Tuesday, January 22, 2019 5:58 PM
  • The only way I would attempt to do this is with the ADO.NET Entity Framework and using Linq.

     https://docs.microsoft.com/en-us/dotnet/visual-basic/programming-guide/language-features/linq/introduction-to-linq

    You can do the same in a non MVC solution and just straight up use an ASP.NET Webform using ADO.NET Entity Framework, which is a C# example.

    https://docs.microsoft.com/en-us/aspnet/core/tutorials/first-mvc-app/search?view=aspnetcore-2.2

    Lambda style VB...
    dim movies = movies.Where(func(s) s.Title.Contains("Big Red One")
    
    

    https://docs.microsoft.com/en-us/dotnet/visual-basic/programming-guide/concepts/linq/getting-started-with-linq

    http://www.entityframeworktutorial.net/what-is-entityframework.aspx

    It doesn't matter a whole lot how you learn to use EF in a Win or Web form application, becuase once you understand basics on  how to use EF,you got it.

    https://code.msdn.microsoft.com/windowsapps/Entity-Framework-6-for-06edd4a8

    Also EF is used havily in ASP.NET solutions.

    ASP.NET can be discussed at the ASP.NET forums VB and C# using ASP.NET.

    https://forums.asp.net/

    Go query the MS SQL Server database  tables using Linq and the ADO.NET Entity Framework.....

    If you need help with EF, ASP.NET has an EF forum and MSDN has an EF forum too. 

    https://social.msdn.microsoft.com/Forums/en-US/home?forum=adodotnetentityframework

    • Edited by DA924x Wednesday, January 23, 2019 4:12 AM
    Wednesday, January 23, 2019 4:08 AM