Indexing search....
-
We are implemenmting the MicroSoft Indexing search in our site.our client asked to give provision to search the main folders only, not for SubFolders. So we decided to use the SHALLOW TRAVERSAL OF. But still now we didnt get the correct syntax. My code: System.Data.OleDb.OleDbConnection odbSearch = new System.Data.OleDb.OleDbConnection("Provider=\"MSIDXS\";Data Source=\"Agaram\";"); System.Data.OleDb.OleDbCommand cmdSearch = new System.Data.OleDb.OleDbCommand(); cmdSearch.Connection = odbSearch; odbSearch.Open(); cmdSearch.CommandText = "select Vpath, path, FileName, size, write, attrib, Characterization, DocTitle, rank from scope('' SHALLOW TRAVERSAL OF ("/Software")'') where FREETEXT(contents,'" + searchText + "') order by rank desc "; System.Data.OleDb.OleDbDataAdapter SqlDa = new System.Data.OleDb.OleDbDataAdapter(cmdSearch); DataSet Ds = new DataSet(); SqlDa.Fill(Ds); odbSearch.Close(); /Software is the main folder in my project The Error is at the Select Query. Error Details: Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. Compiler Error Message: CS1002: ; expected Source Error: Line 34: cmdSearch.CommandText = "select Vpath, path, FileName, size, write, attrib, Characterization, DocTitle, rank from scope('' SHALLOW TRAVERSAL OF ("/Software")'') where FREETEXT(contents,'" + searchText + "') order by rank desc ";
-
We are implemenmting the MicroSoft Indexing search in our site.our client asked to give provision to search the main folders only, not for SubFolders. So we decided to use the SHALLOW TRAVERSAL OF. But still now we didnt get the correct syntax. My code: System.Data.OleDb.OleDbConnection odbSearch = new System.Data.OleDb.OleDbConnection("Provider=\"MSIDXS\";Data Source=\"Agaram\";"); System.Data.OleDb.OleDbCommand cmdSearch = new System.Data.OleDb.OleDbCommand(); cmdSearch.Connection = odbSearch; odbSearch.Open(); cmdSearch.CommandText = "select Vpath, path, FileName, size, write, attrib, Characterization, DocTitle, rank from scope('' SHALLOW TRAVERSAL OF ("/Software")'') where FREETEXT(contents,'" + searchText + "') order by rank desc "; System.Data.OleDb.OleDbDataAdapter SqlDa = new System.Data.OleDb.OleDbDataAdapter(cmdSearch); DataSet Ds = new DataSet(); SqlDa.Fill(Ds); odbSearch.Close(); /Software is the main folder in my project The Error is at the Select Query. Error Details: Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. Compiler Error Message: CS1002: ; expected Source Error: Line 34: cmdSearch.CommandText = "select Vpath, path, FileName, size, write, attrib, Characterization, DocTitle, rank from scope('' SHALLOW TRAVERSAL OF ("/Software")'') where FREETEXT(contents,'" + searchText + "') order by rank desc ";
-
We are implemenmting the MicroSoft Indexing search in our site.our client asked to give provision to search the main folders only, not for SubFolders. So we decided to use the SHALLOW TRAVERSAL OF. But still now we didnt get the correct syntax. My code: System.Data.OleDb.OleDbConnection odbSearch = new System.Data.OleDb.OleDbConnection("Provider=\"MSIDXS\";Data Source=\"Agaram\";"); System.Data.OleDb.OleDbCommand cmdSearch = new System.Data.OleDb.OleDbCommand(); cmdSearch.Connection = odbSearch; odbSearch.Open(); cmdSearch.CommandText = "select Vpath, path, FileName, size, write, attrib, Characterization, DocTitle, rank from scope('' SHALLOW TRAVERSAL OF ("/Software")'') where FREETEXT(contents,'" + searchText + "') order by rank desc "; System.Data.OleDb.OleDbDataAdapter SqlDa = new System.Data.OleDb.OleDbDataAdapter(cmdSearch); DataSet Ds = new DataSet(); SqlDa.Fill(Ds); odbSearch.Close(); /Software is the main folder in my project The Error is at the Select Query. Error Details: Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. Compiler Error Message: CS1002: ; expected Source Error: Line 34: cmdSearch.CommandText = "select Vpath, path, FileName, size, write, attrib, Characterization, DocTitle, rank from scope('' SHALLOW TRAVERSAL OF ("/Software")'') where FREETEXT(contents,'" + searchText + "') order by rank desc ";
Hi You need to split the string "\Software" as "\"" for each double quotes with escape character: See below:
cmdSearch.CommandText = "SELECT Vpath, path, FileName, size, write, attrib, Characterization, DocTitle, rank FROM SCOPE('shallow traversal of " + "\"" + "/Software" + "\"" + "') where FREETEXT(contents,'" + searchText + "') order by rank desc ";
Let me know if that works.Harini
-
Hi You need to split the string "\Software" as "\"" for each double quotes with escape character: See below:
cmdSearch.CommandText = "SELECT Vpath, path, FileName, size, write, attrib, Characterization, DocTitle, rank FROM SCOPE('shallow traversal of " + "\"" + "/Software" + "\"" + "') where FREETEXT(contents,'" + searchText + "') order by rank desc ";
Let me know if that works.Harini
-
If
Moghan wrote:
("/Software")'') where FREETEXT(contents,'" + searchText + "') order by rank desc ";
is a new line of code then you need to put a + in the line before at the end so that it knows its the end of that line of code
-
Ok ... That is good!!
Harini
-
Hi You need to split the string "\Software" as "\"" for each double quotes with escape character: See below:
cmdSearch.CommandText = "SELECT Vpath, path, FileName, size, write, attrib, Characterization, DocTitle, rank FROM SCOPE('shallow traversal of " + "\"" + "/Software" + "\"" + "') where FREETEXT(contents,'" + searchText + "') order by rank desc ";
Let me know if that works.Harini
Hi, One more thing, replace the variable searchText as parameter to avoid security (SQL Injection).
Harini N K wrote:
cmdSearch.CommandText = "SELECT Vpath, path, FileName, size, write, attrib, Characterization, DocTitle, rank FROM SCOPE('shallow traversal of " + "\"" + "/Software" + "\"" + "') where FREETEXT(contents,'" + searchText + "') order by rank desc ";
This is a good coding practice in any langauge.
Harini
-
Hi, One more thing, replace the variable searchText as parameter to avoid security (SQL Injection).
Harini N K wrote:
cmdSearch.CommandText = "SELECT Vpath, path, FileName, size, write, attrib, Characterization, DocTitle, rank FROM SCOPE('shallow traversal of " + "\"" + "/Software" + "\"" + "') where FREETEXT(contents,'" + searchText + "') order by rank desc ";
This is a good coding practice in any langauge.
Harini