Hi friends
i want to make a indexing like windows's indexing
this is it's code but i don't work how i can correct it?
public void Search() { try { OleDbConnection cn = new OleDbConnection("Provider='MSIDXS';Data Source='TestCatalog'"); string goal = textBox1.Text.ToString(); string query = "select Path from scpoe() WHERE FREETEXT(contents, '" + goal + "')"; OleDbCommand cmd = new OleDbCommand(query, cn); cn.Open(); OleDbDataReader dr = cmd.ExecuteReader(); while (dr.Read()) { listView1.Items.Add(dr[0].ToString()); } dr.Close(); cn.Close(); } catch (Exception) { MessageBox.Show("Not Found"); } } private void button1_Click(object sender, EventArgs e) { this.Search(); }
|
I think it's better to explain some thing about it:
when you type only a word like"windowsForm" in search Textbox with this Query it must shows all of documents that included this word and show it in listview but it doesn't work
PLZ Help
Kirtan PatelPosted Aug 19, 2009, 8:10 AM
Take a Look at The Link below It Will help you to refer Queries :)
http://www.codeproject.com/KB/database/Indexing_Service_HOW-TO.aspx
MaharajePosted Aug 19, 2009, 5:56 AM
Kirtan PatelPosted Aug 19, 2009, 1:45 AM
Your Query Having Mistake i think
Where like below
WHERE FREETEXT('You Text for Best Match')
and for that Error You are getting is Not Seems under My Provided Project Files In Above post take a look at it :)or You can Use
WHERE FREETEXT(FileName, ' maharaje ')or
WHERE FileName LIKE '%test%'// It Will resturn all the File Name which contain 'test' wordHappy Coding :) in Select("note ....) "note" is a column name i have in my data table that i filled from database . may be you dont have the same column name becase you are using Indexing Service
MaharajePosted Aug 19, 2009, 1:36 AM
on this line :
foreach (DataRow rw in dt.Select("note like '%" + textBox1.Text.Trim() + "%'"))
when i type only one char
MaharajePosted Aug 19, 2009, 1:25 AM
Kirtan PatelPosted Aug 19, 2009, 12:20 AM
Indexing Search Here I have Filled my datatable with from database but you can build DataTable from your custom
data in coding also :) Add All your Drives / Folders Etc in DataTable and Display ListView From that Datatable and
Search on it :)
namespace LiveSearchSample
{
public partial class Form1 : Form
{
DataView dv;
DataTable dt;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
// You can Also Construct Datatable With Whatever Data it is weather its in database or Not :)
SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database1.mdf;Integrated Security=True;User Instance=True");
con.Open();
SqlCommand comm = new SqlCommand("select * from Reminder",con);
SqlDataAdapter da = new SqlDataAdapter(comm);
dt = new DataTable();
da.Fill(dt);
//Here the main Process Starts
foreach (DataRow rw in dt.Rows)
{
string[] u = new string[2];
u[0] = rw[0].ToString();
u[1] = rw[1].ToString();
listView1.Items.Add(new ListViewItem(u));
}
con.Close();
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
if (textBox2.Text.Trim() != "")
{
listView1.Items.Clear();
foreach (DataRow rw in dt.Select("note like '%"+textBox2.Text.Trim()+"%'"))
{
string[] u = new string[2];
u[0] = rw[0].ToString();
u[1] = rw[1].ToString();
listView1.Items.Add(new ListViewItem(u));
}
}
else
{
listView1.Items.Clear();
foreach (DataRow rw in dt.Rows)
{
string[] u = new string[2];
u[0] = rw[0].ToString();
u[1] = rw[1].ToString();
listView1.Items.Add(new ListViewItem(u));
}
}
}
}
}
Kirtan PatelPosted Aug 18, 2009, 11:28 PM
You Can Still Perform this Because you can Build a DataTable From The list of Files you have and then
Use That dv.RowFilter :) still if you need assistance i am here to help you out :)
MaharajePosted Aug 18, 2009, 9:24 PM
i think you are right i forgot to say that this search isn't in the DB it is about all of your system(Folders, Drives,...) ?! I have Problem with this i need the answer for it
Kirtan PatelPosted Aug 18, 2009, 8:08 AM
I have Coded the Functionality
you need It Will Search As You Type in Text Box and Display result in DataGridView ( Here i used gridview instead of
ListView but you can use ListView also :)
Included Project Files Take a Look at it Link is At below of the post and if any problem let me know
namespace LiveSearchSample
{
public partial class Form1 : Form
{
DataView dv;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database1.mdf;Integrated Security=True;User Instance=True");
con.Open();
SqlCommand comm = new SqlCommand("select * from users",con);
SqlDataAdapter da = new SqlDataAdapter(comm);
DataTable dt = new DataTable();
da.Fill(dt);
dv = new DataView();
//Set DataView to DataTable
dv = dt.DefaultView;
//Show DataView in DataGridView
dataGridView1.DataSource = dv;
con.Close();
}
private void txtSearch_TextChanged(object sender, EventArgs e)
{
string SearchText = txtSearch.Text.Trim();
//Live Search Code
dv.RowFilter = "Username like '" + SearchText + "%'";
}
}
}