显示标签为“implement”的博文。显示所有博文
显示标签为“implement”的博文。显示所有博文

2012年3月22日星期四

Full Text Search for Find Methods

Hello,
I have to implement a method FindProduct, which takes a parameter search query and returns product based on the query.

I think i can use full text search here but don't know how. I tried to read a various way but could not figure out.

123 [DataObjectMethodAttribute(DataObjectMethodType.Select,true)]4public DataLayer.shopDBDataSet.ProductsDataTable GetProducts()5 {6return Adapter.GetProducts();7 }89 [DataObjectMethodAttribute(DataObjectMethodType.Insert,true)]10public bool AddProduct(string UPCCode,string Description,string Size)11 {12 shopDBDataSet.ProductsDataTable products =new shopDBDataSet.ProductsDataTable();13 shopDBDataSet.ProductsRow productRow = products.NewProductsRow();1415 productRow.UPCCode = UPCCode;16 productRow.Description = Description;17 productRow.Size = Size;1819 products.AddProductsRow(productRow);20int rowsAffected = Adapter.Update(products);21return rowsAffected == 1;22 }2324 [DataObjectMethodAttribute(DataObjectMethodType.Delete,true)]25public bool DeleteProduct(string UPCCode)26 {27int rowsAffected = Adapter.Delete(UPCCode);28return rowsAffected == 1;29 }3031 [DataObjectMethodAttribute(DataObjectMethodType.Select,false)]32public DataLayer.shopDBDataSet.ProductsDataTable FindProducts(string searchQuery)33 {3435throw new System.NotImplementedException();3637 }38

You can see the method at line number 32. I could not figure out the way to implement it although i know full text search is a good choice.

I have following table adapter

GetProducts(); GetProductsByManufacturerName(); GetProductsByManufacturerID(), and GetProductsByUPCCode();

Product table contains UPCCode, Description, Size columns

But i need to get the product which returns the description containing search query.

I know some of you have done something similar to this.

Could you please guide me...

Thanks in advance

...

The Full Text index require four predicates CONTAINS,CONTAINSTABLE,FREETEXT and FREETEXTTABLE and the Microsoft search service and the catalog must be populated before you can get search results. You can implement it in your application but there is limited support for SQL Server Express. The links below will take you in the right direction if you decide to implement it. Hope this helps.

http://msdn2.microsoft.com/en-us/library/ms142559.aspx
http://msdn2.microsoft.com/en-us/library/ms142547.aspx

http://msdn2.microsoft.com/en-us/library/ms189760.aspx

|||

Thanks a lot...

i got the full text indexes for my tables.

But do you suggest me to create a productstableadapter that uses FREETEXT SQL query.

or just call it from the function.

Thanks

|||

There are samples provided by Microsoft but I think you should use a stored proc like the samples in my first post and call the stored proc in your ADO.NET code. Hope this helps.

|||

Thank you again...

how do i pass search query entered by user.

SELECT ProductName
FROM Products
WHERE FREETEXT (ProductName, 'spread' )
instead of spread i would like to pass user input.
 
 
thanks once again 

|||

Then the CONTAINS predicate is more suited for your needs because it can be used in seven or more context when searching, run a search for all four predicates I posted in my first reply in SQL Server BOL(books online). Here are all the uses of CONTAINS. Hope this helps.

A. Using CONTAINS with <simple_term>

B. Using CONTAINS and phrase in <simple_term>

C. Using CONTAINS with <prefix_term>

D. Using CONTAINS and OR with <prefix_term>

E. Using CONTAINS with <proximity_term>

F. Using CONTAINS with <generation_term>

G. Using CONTAINS with <weighted_term>

H. Using CONTAINS with variables

|||

Hey Caddre (my favorite poster)

I want to piggy back on this. I implemented the code used in the links above but something still isn't right. Here's my code:

<code>

Sub search(ByVal sender As Object, ByVal e As System.EventArgs)
GridView1.Visible = True
Dim DBCOnnection As SqlConnection
Dim Criterion As String = Request.QueryString("Criterion")
DBCOnnection = New SqlConnection("Data Source=server/db;Initial Catalog=SOS_KnowledgeBase;Integrated Security=True")
DBCOnnection.Open()

Dim strSQL As String
Dim objDataset As New DataSet()
Dim objAdapter As New System.Data.SqlClient.SqlDataAdapter()

strSQL = "exec dbo.sp_search @.Application, @.Category, @.textsearch"

objAdapter.SelectCommand = New System.Data.SqlClient.SqlCommand(strSQL, DBCOnnection)
objAdapter.SelectCommand.Parameters.AddWithValue("@.Application", DDLApp.SelectedItem.Text)
objAdapter.SelectCommand.Parameters.AddWithValue("@.Category", DDLCat.SelectedItem.Text)
objAdapter.SelectCommand.Parameters.AddWithValue("@.textsearch", textsearch.Text)
objAdapter.Fill(objDataset)
Dim oView As New DataView(objDataset.Tables(0))
GridView1.DataSource = oView
GridView1.DataBind()

DBCOnnection.Close()
If GridView1.PageCount <= 0 Then
Label1.Text = "No Results Matched Your Query."
Else

If GridView1.PageCount > 0 Then
Label1.Text = ""
End If

End If
Button1.Visible = False
Button2.Visible = True


End Sub

</code>

<html>

<asp:content id="Content1" contentplaceholderid="headertext" runat="server">

<asp:DropDownList ID="DDLApp" runat="server" DataTextField="Application" DataValueField="Application" AutoPostBack="True" DataSourceID="Application" AppendDataBoundItems="True" OnSelectedIndexChanged="refresh">
<asp:ListItem Value="0">-- Choose an Application --</asp:ListItem>
</asp:DropDownList><br />

<asp:SqlDataSource ID="Application" runat="server" ConnectionString="<%$ ConnectionStrings:SOSKB %>"
SelectCommand="SELECT DISTINCT Application.Application, Article.ApplicationID FROM Application INNER JOIN Article ON Application.ApplicationID = Article.ApplicationID">
</asp:SqlDataSource>
<asp:DropDownList ID="DDLCat" runat="server" DataTextField="Category"
DataValueField="Category" DataSourceID="Category" AppendDataBoundItems="True">
<asp:ListItem Value="0" Selected="True">-- Select All --</asp:ListItem>
</asp:DropDownList><asp:SqlDataSource ID="Category" runat="server" ConnectionString="<%$ ConnectionStrings:SOSKB %>"
SelectCommand="SELECT DISTINCT Category.Category FROM Category INNER JOIN Article ON Category.CategoryID = Article.CategoryID INNER JOIN Application ON Article.ApplicationID = Application.ApplicationID WHERE (Application.Application = ISNULL(@.Application, Application.Application)) ORDER BY Category.Category">
<SelectParameters>
<asp:ControlParameter ControlID="DDLApp" Name="Application" PropertyName="SelectedValue" />
</SelectParameters>
</asp:SqlDataSource>

<asp:Label ID="textsearch" runat="server" CssClass="box-title" Text="Keyword(s)"></asp:Label><br />
<asp:TextBox ID="searchbox" runat="server"></asp:TextBox>
<br />
<br />
<asp:Button ID="Button1" runat="server" OnClick="search" Text="Search Now" Width="83px" />

</asp:content>

</html>

<stored proc>

CREATE PROCEDURE [sp_search]

@.Application nvarchar (25),
@.Category nvarchar(25),
@.textsearch nvarchar(100)

AS

Begin

If @.Category ='-- Select All --'
SELECT Article.ArticleID, Application.Application, Category.Category,
Article.Title, Article.DateUpdated AS [Last Updated]
FROM Article INNER JOIN Application ON
Article.ApplicationID = Application.ApplicationID
INNER JOIN Category ON Article.CategoryID = Category.CategoryID
WHERE Application.Application = ISNULL(@.Application, Application.Application) AND
Category.Category = ISNULL(null, Category.Category) AND
Article.Title IN (
SELECT Title
From Article
WHERE (CONTAINS(*, @.textsearch)))

If @.@.RowCount=0
--raiserror ("No Results.", 16, 1)
RETURN @.@.Error
End
GO

</stored proc>

Here's the error I keep getting:

System.Data.SqlClient.SqlException was unhandled by user code
Class=15
ErrorCode=-2146232060
LineNumber=13
Message="Syntax error occurred near '('. Expected '' in search condition 'Keyword(s)'."
Number=7631
Procedure="sp_search"
Server="my server"
Source=".Net SqlClient Data Provider"
State=1
StackTrace:
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
at System.Data.SqlClient.SqlDataReader.HasMoreRows()
at System.Data.SqlClient.SqlDataReader.ReadInternal(Boolean setTimeout)
at System.Data.SqlClient.SqlDataReader.Read()
at System.Data.ProviderBase.DataReaderContainer.Read()
at System.Data.Common.DataAdapter.FillLoadDataRow(SchemaMapping mapping)
at System.Data.Common.DataAdapter.FillFromReader(DataSet dataset, DataTable datatable, String srcTable, DataReaderContainer dataReader, Int32 startRecord, Int32 maxRecords, DataColumn parentChapterColumn, Object parentChapterValue)
at System.Data.Common.DataAdapter.Fill(DataSet dataSet, String srcTable, IDataReader dataReader, Int32 startRecord, Int32 maxRecords)
at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet)
at ASP.search_aspx.search(Object sender, EventArgs e) in D:\Documents and Settings\uid\My Documents\Visual Studio 2005\WebSites\SOSKnowledgeBase\search.aspx:line 33
at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

Can you tell me what I am doing wrong here? Thanks.

Cordell

|||

Never mind...so stupid. I was referencing a label instead of the actual textbox!!!!!

Now that this is fixed, does anyone know a link or two that shows me how to strip commas, periods, etc from textbox entries before you pass it to a procedure?

Cordell

|||

I think you are calling Contains too late in your query in the WHERE clause of a JOIN which is just a filter and if you are in Express there is limited support for Express. You should check out the other three predicates especially the tables version. Hope this helps.

FreetextTable

http://msdn2.microsoft.com/en-us/library/ms177652.aspx

Containstable

http://msdn2.microsoft.com/en-us/library/ms189760.aspx

And thanks for the compliment.

2012年3月19日星期一

Full text memory usage

Hi
I work with SQL 2005 and I know how it uses RAM but I know just some basic
stuff about Full-text catalogs and since we plan to implement them in the
future I need to know a few things.
1. Can you set min and max memory for full text service like it can be set
for SQL service?
2. Does it start using RAM as it needs it until it hits maximum and then
release it only if some other process needs RAM like SQL does?
3. How much RAM could be expected for Full text sevice to use on 20GB
catalog? (just estimate)
4. On x86 windows, full text service is limited to max 3GB of RAM (with /3GB
switch in boot.ini probably). Is on x64 Windows limitation 4GB and on IA64
there is no such limitations? Can you confirm that?
Thanks
Tom
answers inline.
Hilary Cotter
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html
Looking for a FAQ on Indexing Services/SQL FTS
http://www.indexserverfaq.com
"Tom" <tomman@.hotmail.com> wrote in message
news:OI3fNNUfHHA.444@.TK2MSFTNGP04.phx.gbl...
> Hi
> I work with SQL 2005 and I know how it uses RAM but I know just some basic
> stuff about Full-text catalogs and since we plan to implement them in the
> future I need to know a few things.
> 1. Can you set min and max memory for full text service like it can be set
> for SQL service?
No.
> 2. Does it start using RAM as it needs it until it hits maximum and then
> release it only if some other process needs RAM like SQL does?
Not really, like any other windows application it can see up to 2 Gigs on a
32 bit system, on a 64 bit system it may see then entire physical memory. It
uses what it needs. Depending on the other applications running on this
server its working memory set may be paged to disk. It makes extensive use
of the file system cache.

> 3. How much RAM could be expected for Full text sevice to use on 20GB
> catalog? (just estimate)
We have about 12 20 gig catalogs - memory used is 40 Mgs.
That depends on your queries mainly. The indexer runs in process with SQL
Server.
> 4. On x86 windows, full text service is limited to max 3GB of RAM (with
> /3GB switch in boot.ini probably). Is on x64 Windows limitation 4GB and on
> IA64 there is no such limitations? Can you confirm that?
That is correct on 64 bit systems applications provided they are coded for
it can see the entire physical ram. So your entire catalogs could be in ram
on systems with larger memory.
>
> Thanks
> Tom
>
|||With SQL Server 2005, you typically will try to limit it to not starve the
OS. So, in an X64 environment with 12GB -- I might give 10 to SQL and allow
2 for the OS (everything else).
When you introduce full-text on this system of total 12GB, how do you
prevent FTE from starving the OS?
So, I would set 8GB for SQL and leave 4GB for the OS+FTE+everything else.
Is there nothing to guarentee that FTE doesn't over utilize that 4GB and
cause OS level latency?
I thought there might be some level of governing this by using the:
ft crawl bandwidth (max) & ft notify bandwidth (max)
sp_configure options but it doesn't seem that is what the purpose of those
are for.
Thanks,
Robert Towne
|||the full-text engine does not compete with the OS. SQL Server will complete
with other application, like sql fts. Set
sp_configure 'max server memory'
to 2 gigs less than the total memory, so fts has enough memory to operate.
"sql411@.nospam.com" <sql411nospamcom@.discussions.microsoft.com> wrote in
message news:0988A377-5262-4986-98CF-17BAAD4C9D32@.microsoft.com...
> With SQL Server 2005, you typically will try to limit it to not starve the
> OS. So, in an X64 environment with 12GB -- I might give 10 to SQL and
> allow
> 2 for the OS (everything else).
> When you introduce full-text on this system of total 12GB, how do you
> prevent FTE from starving the OS?
> So, I would set 8GB for SQL and leave 4GB for the OS+FTE+everything else.
> Is there nothing to guarentee that FTE doesn't over utilize that 4GB and
> cause OS level latency?
> I thought there might be some level of governing this by using the:
> ft crawl bandwidth (max) & ft notify bandwidth (max)
> sp_configure options but it doesn't seem that is what the purpose of those
> are for.
>
> Thanks,
> Robert Towne
>
|||OK, i was thinking that FTE in 2005 ran in a seperate memory space than what
is specified in SQL Server's 'max server memory'. Very helpful to know &
many thanks..
"Hilary Cotter" wrote:

> the full-text engine does not compete with the OS. SQL Server will complete
> with other application, like sql fts. Set
> sp_configure 'max server memory'
> to 2 gigs less than the total memory, so fts has enough memory to operate.
>
|||I thought the same as Robert.
So if FTS operates with large full-text indexes they will be cached in
memory space under SQLService?
How can I determin how much memory that SQL uses is actually used for
full-text catalog and how much for other data?
I usually use "Database pages" counter to see how much data and indexes are
cached in RAM.
Tom
"sql411@.nospam.com" <sql411nospamcom@.discussions.microsoft.com> wrote in
message news:4A8CC880-DB65-4DBA-8EDE-A67BB88DF9FE@.microsoft.com...
> OK, i was thinking that FTE in 2005 ran in a seperate memory space than
> what
> is specified in SQL Server's 'max server memory'. Very helpful to know &
> many thanks..
> "Hilary Cotter" wrote:
>
|||SQL FTE doesn't use much ram, but SQL Server will apply memory pressure on
all other applications on this box. That is why it is important to cap sql
server so SQL FTE has room to operate.
I don't think ms has exposed counters to determine how much memory of the
SQL Engine SQL FTS uses (some of the indexing operations are integrated into
the engine), but the indexes are not caches in SQL Server's data cache. They
are part of the file system cache.
"Tom" <tomman@.hotmail.com> wrote in message
news:ur1wkEzgHHA.4064@.TK2MSFTNGP02.phx.gbl...
>I thought the same as Robert.
> So if FTS operates with large full-text indexes they will be cached in
> memory space under SQLService?
> How can I determin how much memory that SQL uses is actually used for
> full-text catalog and how much for other data?
> I usually use "Database pages" counter to see how much data and indexes
> are cached in RAM.
> Tom
>
> "sql411@.nospam.com" <sql411nospamcom@.discussions.microsoft.com> wrote in
> message news:4A8CC880-DB65-4DBA-8EDE-A67BB88DF9FE@.microsoft.com...
>

2012年2月19日星期日

fts SQL Server Personal on XP Pro

Hi,
I have SQL Server 2000 Personal edition installed on XP
Pro and am trying to implement the full-text search
facility. There doesn't seem to be any option to install
fts on my SQL Server CD so I assumed it should be
installed by default.
However, when I try
EXEC sp_fulltext_database @.action = 'Enable'
I get the following error
erver: Msg 7609, Level 17, State 2, Procedure
sp_fulltext_database, Line 46
Full-Text Search is not installed, or a full-text
component cannot be loaded.
Is FTS possible with this version of SQLServer?
thanks
Maracatu
maracatu,
No, the SQL Server 2000 "Full-Text Search" components are not supported with
the Personal Edition. See SQL 2000 BOL title "Features Supported by the
Editions of SQL Server 2000" for editions that support SQL FTS.
Regards,
John
"maracatu" <jarrod@.dovelight.com> wrote in message
news:1ccfa01c42241$c5b48fe0$a101280a@.phx.gbl...
> Hi,
> I have SQL Server 2000 Personal edition installed on XP
> Pro and am trying to implement the full-text search
> facility. There doesn't seem to be any option to install
> fts on my SQL Server CD so I assumed it should be
> installed by default.
> However, when I try
> EXEC sp_fulltext_database @.action = 'Enable'
> I get the following error
> erver: Msg 7609, Level 17, State 2, Procedure
> sp_fulltext_database, Line 46
> Full-Text Search is not installed, or a full-text
> component cannot be loaded.
> Is FTS possible with this version of SQLServer?
> thanks
> Maracatu
|||Hmmmm.... This article on MSDN says that Full Text IS supported on Personal Edition...
http://msdn.microsoft.com/library/de...ar_ts_1cdv.asp
Posted using Wimdows.net NntpNews Component -
Post Made from http://www.SqlJunkies.com/newsgroups Our newsgroup engine supports Post Alerts, Ratings, and Searching.
|||SqlJunkies User,
Hmmm is right... Actually we both referenced the same doc (your MSDN
reference is the same info that is in the SQL BOL reference I quoted...
However, the initial poster may need to specifically install the SQL FTS
components via the SQL CD's "custom installation" and select the "Full-text
Search" components in order to install it. I've not tested this myself as I
don't use the Personal Edition of SQL Server on WinXP as I use the Developer
Edition. If you have the Personal Edition, perhaps you could test this
yourself and post the results here... ;-)
Regards,
John
"SqlJunkies User" <User@.-NOSPAM-SqlJunkies.com> wrote in message
news:#W##QXpREHA.1276@.TK2MSFTNGP11.phx.gbl...
> Hmmmm.... This article on MSDN says that Full Text IS supported on
Personal Edition...
>
http://msdn.microsoft.com/library/de...ar_ts_1cdv.asp
>
> --
> Posted using Wimdows.net NntpNews Component -
> Post Made from http://www.SqlJunkies.com/newsgroups Our newsgroup engine
supports Post Alerts, Ratings, and Searching.
|||I had the exact same problem. I found and posted the article mentioned in the last post. I then found article Q827449 that tells how to reinstall Full Text by running some stuff on the SQL CD. I followed all the instructions, but didn't seem to make it
work. Something still missing. Then, when running the Setup for SQL 2000 Personal Edition again (Not uninstalling my first one), and choosing a Custom Install to Add/Remove components, the option for Full Text was already checked. It would not let me
uncheck it (Setup didn't recognize that I had changed anything and wouldn't continue). Finally, had to uninstall, whack all SQL related registry keys, and reinstall. On the reinstall, chose Custom Install. Full Text is NOT checked by default. Checked
it, and finished the install. Full Text is now available and usable on my SQL 2000 Personal Edition on XP Professional. If you haven't "damaged" you SQL install by following Q827449, you might be able to add it by running Setup again and choosing Custo
m Install to Add/Remove Components...
Posted using Wimdows.net NntpNews Component -
Post Made from http://www.SqlJunkies.com/newsgroups Our newsgroup engine supports Post Alerts, Ratings, and Searching.
|||Hi,
In order to un-check the option for Full Text Search that was already
checked, you must delete or rename the following Tracking Key:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL
Server\<Instance_Name>\Tracking\
{E07FDDA7-5A21-11d2-9DAD-00C04F79D434}
Note, if your SQL Server 2000 is not a named instance, remove
"<Instance_Name>\" and be sure to be logged on to the server as either
Administrator or as a member of the server's Admin Group.
Once you've done removed (renamed) the above tracking key, then delete the
MSSearch directory from either:
drive_letter:\Program Files\Common Files\Microsoft Shared\
or
drive_letter::\Program Files\Common Files\System\
Then using your SQL Server 2000 installation CD re-install via "Custom
Installation" the Full-Text Search component (it should be un-checked). When
this completes find and save these files: SearchSetup.log (usually under
\windows or \winnt folders) and sqlsp.log. If any problems, you should post
these files.
I'm not sure why the procedures in Q827449 failed for you, but if you follow
the above procedures, it will always work as I've posted the above methods
many, many times in this newsgroup (microsoft.public.sqlserver.fulltext) and
always with successful results.
Regards,
John
<CSaalfeld@.-NOSPAM-Earthlink.net> wrote in message
news:OEdOfICSEHA.3052@.TK2MSFTNGP12.phx.gbl...
> I had the exact same problem. I found and posted the article mentioned in
the last post. I then found article Q827449 that tells how to reinstall
Full Text by running some stuff on the SQL CD. I followed all the
instructions, but didn't seem to make it work. Something still missing.
Then, when running the Setup for SQL 2000 Personal Edition again (Not
uninstalling my first one), and choosing a Custom Install to Add/Remove
components, the option for Full Text was already checked. It would not let
me uncheck it (Setup didn't recognize that I had changed anything and
wouldn't continue). Finally, had to uninstall, whack all SQL related
registry keys, and reinstall. On the reinstall, chose Custom Install. Full
Text is NOT checked by default. Checked it, and finished the install. Full
Text is now available and usable on my SQL 2000 Personal Edition on XP
Professional. If you haven't "damaged" you SQL install by following
Q827449, you might be able to add it by running Setup again and choosing
Custom Install to Add/Remove Components...
>
> --
> Posted using Wimdows.net NntpNews Component -
> Post Made from http://www.SqlJunkies.com/newsgroups Our newsgroup engine
supports Post Alerts, Ratings, and Searching.