Bonjour à tous,

Je cherche à faire un petit moteur de recherche pour mon application... Et j'ai un petit souci.

Pour le moment, mon code me retourne des Strings. J'aimerais faire en sorte que ces strings deviennent des requêtes.

Une idée?

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
 
Namespace MvcApplication4
    Public Class SearchController
        Inherits System.Web.Mvc.Controller
 
        Private db As schema_crmEntities = New schema_crmEntities
 
        ' Cette fonction sert à concaténer les chaines de caractère
        Function requete(lien As String, table As String, mot As String, first As Boolean)
            Dim suite As String
            If first = True Then
                suite = " " + "Where" + " " + table + ".Contains(""" + mot + """)"
            Else
                suite = " " + lien + " " + table + ".Contains(""" + mot + """)"
            End If
            Return (suite)
 
        End Function
 
 
        '
        ' GET: /Search
        Function Index() As ActionResult
            Return View()
        End Function
 
 
        '
        ' POST: /Search
 
        <HttpPost()>
        Function Index(search As String, choix As Integer) As ActionResult
            Dim test As Integer = Request("choix")
            Dim chaine As String = Request("searchString")
            Dim message As String = "message"
            Dim n As Integer = 0
            'For Each car In chaine
            'If car = " " Then n += 1
            'Next
 
            Dim first As Boolean
            Dim lien As String
 
            'If choix = 1 Or choix = 2 Then
            Dim tabMots() As String = chaine.Split(New Char() {" "c}) 'transforme la chaine de caractères en un tableau de mots
            'Else
            If choix = 3 Then
                ReDim tabMots(0)
                tabMots(0) = chaine
            End If
 
 
            'End If
            If choix = 1 Then
                lien = "Or"
            End If
            If choix = 2 Then
                lien = "And"
            End If
 
 
            '        If choix = 3 Then
            ' message = chaine 'L'expression exacte
            'Recherche de l'expression dans la table meeting
            'Dim meetings = (From a In db.meeting
            'Where(a.compteRendu.Contains(chaine))
            '              Select a)
            'Recherche de l'expression dans la table Interview
            'Dim interviews = (From b In db.interview
            'Where(b.compteRendu.Contains(chaine))
            '                 Select b)
            'Recherche de l'expression dans la table opportunite
            'Dim opportunites As IEnumerable(Of opportunite) = (From c In db.opportunite
            'Where(c.nomOffre.Contains(chaine))
            '                                                   Select c)
            '
            'Recherche de l'expression dans la table Client
            'Dim clients = (From d In db.client
            'Where(d.nomCompteClient.Contains(chaine))
            '              Select d)
            'Recherche de l'expression dans la table Contact
            'Dim contacts As IEnumerable(Of contact) = (From e In db.contact
            'Where(e.nom.Contains(chaine) Or e.prenom.Contains(chaine) Or e.titre.Contains(chaine) Or e.departement.Contains(chaine) Or e.qualifications.Contains(chaine) Or e.langue1.Contains(chaine) Or e.langue2.Contains(chaine) Or e.langue3.Contains(chaine) Or e.langue4.Contains(chaine) Or e.langue5.Contains(chaine))
            '              Select e)
 
            'End If
 
 
            first = True
            Dim requete1 As String = "(From a In db.meeting"
            For Each mot In tabMots
                requete1 += requete(lien, "a.compteRendu", mot, first)
                first = False
            Next
            requete1 += " Select a)"
 
            first = True
            Dim requete2 As String = "(From b in db.Interview"
            For Each mot In tabMots
                requete2 += requete(lien, "b.compteRendu", mot, first)
                first = False
            Next
            requete2 += " Select b)"
 
            first = True
            Dim requete3 As String = "(From c in db.Opportunite"
            For Each mot In tabMots
                requete3 += requete(lien, "c.nomOffre", mot, first)
                first = False
            Next
            requete3 += " Select c)"
 
            first = True
            Dim requete4 As String = "(From d in db.Client"
            For Each mot In tabMots
                requete4 += requete(lien, "d.nomCompteClient", mot, first)
                first = False
            Next
            requete4 += " Select d)"
 
            first = True
            Dim requete5 As String = "(From e in db.Contact"
            For Each mot In tabMots
                requete5 += requete(lien, "e.nom", mot, first)
                first = False
                requete5 += requete(lien, "e.prenom", mot, first)
                requete5 += requete(lien, "e.titre", mot, first)
                requete5 += requete(lien, "e.departement", mot, first)
                requete5 += requete(lien, "e.qualifications", mot, first)
                requete5 += requete(lien, "e.langue1", mot, first)
                requete5 += requete(lien, "e.langue2", mot, first)
                requete5 += requete(lien, "e.langue3", mot, first)
                requete5 += requete(lien, "e.langue4", mot, first)
                requete5 += requete(lien, "e.langue5", mot, first)
            Next
            requete5 += " Select e)"
 
            Dim meetings = requete1
            Dim interviews = requete2
            Dim opportunites = requete3
            Dim clients = requete4
            Dim contacts = requete5
 
            Dim model = New SearchModel With {
                .Contacts = contacts,
                .Meetings = meetings,
                .Interviews = interviews,
                .Opportunites = opportunites,
                .Clients = clients
                }
 
 
            ViewBag.message = message
            ViewBag.requete1 = requete1
            ViewBag.requete2 = requete2
            ViewBag.requete3 = requete3
            ViewBag.requete4 = requete4
            ViewBag.requete5 = requete5
            Return View(model)
        End Function
    End Class
End Namespace

Ca ne sert à rien de lire tout ce qu'il y a au dessus. J'ai fait un petit résumé ici du code pour le rendre un peu plus clair.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
 
Namespace MvcApplication4
    Public Class SearchController
        Inherits System.Web.Mvc.Controller
 
        Private db As schema_crmEntities = New schema_crmEntities
 
        ' Cette fonction sert à concaténer les chaines de caractère
        Function requete(lien As String, table As String, mot As String, first As Boolean)
            Dim suite As String
            If first = True Then
                suite = " " + "Where" + " " + table + ".Contains(""" + mot + """)"
            Else
                suite = " " + lien + " " + table + ".Contains(""" + mot + """)"
            End If
            Return (suite)
 
        End Function
 
 
        '
        ' GET: /Search
        Function Index() As ActionResult
            Return View()
        End Function
 
 
        '
        ' POST: /Search
 
        <HttpPost()>
        Function Index(search As String, choix As Integer) As ActionResult
            Dim test As Integer = Request("choix")
            Dim chaine As String = Request("searchString")
            Dim message As String = "message"
            Dim n As Integer = 0
            'For Each car In chaine
            'If car = " " Then n += 1
            'Next
 
            Dim first As Boolean
            Dim lien As String
 
            Dim tabMots() As String = chaine.Split(New Char() {" "c}) 
            If choix = 3 Then
                ReDim tabMots(0)
                tabMots(0) = chaine
            End If
 
            If choix = 1 Then
                lien = "Or"
            End If
            If choix = 2 Then
                lien = "And"
            End If
 
            first = True
            Dim requete1 As String = "(From a In db.meeting"
            For Each mot In tabMots
                requete1 += requete(lien, "a.compteRendu", mot, first)
                first = False
            Next
            requete1 += " Select a)"
 
            Dim meetings = requete1
 
            Dim model = New SearchModel With {
                .Contacts = contacts,
                }
 
 
            Return View(model)
        End Function
    End Class
End Namespace