Z
Zeya
I have an application where I am required to run a full text query. My
database is MySQL and code in C#. The way all queries are SELECT * FROM
table WHERE firstname = ? and using command parameter the value of ? is
added. But, how would I do the same in case of full text search.
SELECT *, ROUND( MATCH(title, comments) AGAINST (? IN BOOLEAN MODE ) *
10, 2 ) AS score FROM table WHERE MATCH(title,comments) AGAINST (? IN
BOOLEAN MODE ) ORDER BY score DESC
When I provide the value as titl*, I don't get anything. But, when I
hard code the query like:
SELECT *, ROUND( MATCH(title, comments) AGAINST ('titl*' IN BOOLEAN
MODE ) * 10, 2 ) AS score FROM table WHERE MATCH(title,comments)
AGAINST ('titl*' IN BOOLEAN MODE ) ORDER BY score DESC
I get good result.
This is how I am building parameters:
public static OdbcCommand BuildCommand ( ArrayList QueryParameters,
string Query )
{
OdbcCommand Command = new OdbcCommand();
Command.CommandType = CommandType.Text;
Command.CommandText = Query;
for( int i = 0; i <= QueryParameters.Count - 1;
i++ )
{
string[] Parameter =
(string[])QueryParameters[ i ];
Command.Parameters.Add( new
OdbcParameter( Parameter[ 0 ],
Parameter[ 1 ] ) );
}
return Command;
}
Any help will be appreciated.
Thanks.
database is MySQL and code in C#. The way all queries are SELECT * FROM
table WHERE firstname = ? and using command parameter the value of ? is
added. But, how would I do the same in case of full text search.
SELECT *, ROUND( MATCH(title, comments) AGAINST (? IN BOOLEAN MODE ) *
10, 2 ) AS score FROM table WHERE MATCH(title,comments) AGAINST (? IN
BOOLEAN MODE ) ORDER BY score DESC
When I provide the value as titl*, I don't get anything. But, when I
hard code the query like:
SELECT *, ROUND( MATCH(title, comments) AGAINST ('titl*' IN BOOLEAN
MODE ) * 10, 2 ) AS score FROM table WHERE MATCH(title,comments)
AGAINST ('titl*' IN BOOLEAN MODE ) ORDER BY score DESC
I get good result.
This is how I am building parameters:
public static OdbcCommand BuildCommand ( ArrayList QueryParameters,
string Query )
{
OdbcCommand Command = new OdbcCommand();
Command.CommandType = CommandType.Text;
Command.CommandText = Query;
for( int i = 0; i <= QueryParameters.Count - 1;
i++ )
{
string[] Parameter =
(string[])QueryParameters[ i ];
Command.Parameters.Add( new
OdbcParameter( Parameter[ 0 ],
Parameter[ 1 ] ) );
}
return Command;
}
Any help will be appreciated.
Thanks.