Error when trying to use FieldFullTextSearch

Posts   
 
    
Zonkle
User
Posts: 18
Joined: 06-Mar-2005
# Posted on: 09-Mar-2005 11:41:33   

Hi,

I love your tool Otios simple_smile but I'm sure I will love it more when I get used to it. Thank you for ur help.

I have a problem when I am trying to do like a search on a table called "Products". I used this code just to search the "Products" table for any Product Name that has the entered value:


        Dim tosearch As String
        tosearch = Request.QueryString("search")

        Dim EntityFieldFactory As FactoryClasses.EntityFieldFactory
        Dim products As New CollectionClasses.ProductCollection
        Dim filter As IPredicateExpression = New PredicateExpression
        filter.Add(New FieldFullTextSearchPredicate(EntityFieldFactory.Create(ProductFieldIndex.ProductName), FullTextSearchOperator.Contains, tosearch))
        Dim amount As Integer = products.GetDbCount(filter, Nothing)


        resultgrid.DataSource = products.GetMulti(filter)
        resultgrid.DataBind()

And when I run that code I get this error in the browser:


Server Error in '/e-commerce' Application.
--------------------------------------------------------------------------------

An exception was caught during the execution of a retrieval query: Cannot use a CONTAINS or FREETEXT predicate on table 'dbo.Products' because it is not full-text indexed.. Check InnerException, QueryExecuted and Parameters of this exception to examine the cause of this exception. 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: SD.LLBLGen.Pro.ORMSupportClasses.ORMQueryExecutionException: An exception was caught during the execution of a retrieval query: Cannot use a CONTAINS or FREETEXT predicate on table 'dbo.Products' because it is not full-text indexed.. Check InnerException, QueryExecuted and Parameters of this exception to examine the cause of this exception.

Source Error: 


Line 511:           Dim scalarQuery As IRetrievalQuery = DynamicQueryEngine.CreateSelectDQ(fields, DbUtils.DetermineConnectionToUse(containingTransaction), _
Line 512:               Filter, 1, Nothing, relations, True, groupByClause)
Line 513:           Return MyBase.ExecuteScalarQuery(scalarQuery, containingTransaction)
Line 514:       End Function
Line 515:


Source File: C:\Inetpub\wwwroot\e-commerce\Functions\DaoClasses\ProductDAO.vb   Line: 513 

Stack Trace: 


[ORMQueryExecutionException: An exception was caught during the execution of a retrieval query: Cannot use a CONTAINS or FREETEXT predicate on table 'dbo.Products' because it is not full-text indexed.. Check InnerException, QueryExecuted and Parameters of this exception to examine the cause of this exception.]
   SD.LLBLGen.Pro.ORMSupportClasses.RetrievalQuery.ExecuteScalar() +171
   SD.LLBLGen.Pro.ORMSupportClasses.DaoBase.ExecuteScalarQuery(IRetrievalQuery queryToExecute, ITransaction containingTransaction) +151
   Commerce.DaoClasses.ProductDAO.GetScalar(IEntityFields fields, ITransaction containingTransaction, IPredicate Filter, IRelationCollection relations, IGroupByCollection groupByClause) in C:\Inetpub\wwwroot\e-commerce\Functions\DaoClasses\ProductDAO.vb:513
   Commerce.CollectionClasses.ProductCollection.GetScalar(ProductFieldIndex fieldIndex, IExpression expressionToExecute, AggregateFunction aggregateToApply, IPredicate filter, IRelationCollection relations, IGroupByCollection groupByClause) in C:\Inetpub\wwwroot\e-commerce\Functions\CollectionClasses\ProductCollection.vb:740
   Commerce.CollectionClasses.ProductCollection.GetDbCount(IPredicate filter, IRelationCollection relations) in C:\Inetpub\wwwroot\e-commerce\Functions\CollectionClasses\ProductCollection.vb:660
   e_commerce.search_results.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\e-commerce\search_results.aspx.vb:38
   System.Web.UI.Control.OnLoad(EventArgs e) +67
   System.Web.UI.Control.LoadRecursive() +35
   System.Web.UI.Page.ProcessRequestMain() +750




--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:1.1.4322.2032; ASP.NET Version:1.1.4322.2032 

So can you please tell me what is the problem ?

Thank you.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 09-Mar-2005 12:07:10   

The error says: "Cannot use a CONTAINS or FREETEXT predicate on table 'dbo.Products' because it is not full-text indexed.." So you should first create a full text index in sqlserver on a field in Products. simple_smile

Frans Bouma | Lead developer LLBLGen Pro
Zonkle
User
Posts: 18
Joined: 06-Mar-2005
# Posted on: 09-Mar-2005 15:02:24   

Yes you are right man I saw that.

There is another little thing please ....

In the table "Products" there is a Field called "CategoryID", so how can I make my code to automaticlly to retrive the name of the category from the "Category" table ?

Thank you a lot.

Zonkle
User
Posts: 18
Joined: 06-Mar-2005
# Posted on: 09-Mar-2005 16:45:14   

Hi man,

I appreciate that u help me man.

When I was testing my search function using the same code above... a problem happened that If I enter more than keyword an error happen.

For example If I type "Intel processor" in the search field, the error that comes out is :


Server Error in '/' Application.
An exception was caught during the execution of a retrieval query: Syntax error occurred near 'vaio'. Expected ''''' in search condition 'sony vaio'.. Check InnerException, QueryExecuted and Parameters of this exception to examine the cause of this exception.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: SD.LLBLGen.Pro.ORMSupportClasses.ORMQueryExecutionException: An exception was caught during the execution of a retrieval query: Syntax error occurred near 'vaio'. Expected ''''' in search condition 'sony vaio'.. Check InnerException, QueryExecuted and Parameters of this exception to examine the cause of this exception.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[ORMQueryExecutionException: An exception was caught during the execution of a retrieval query: Syntax error occurred near 'vaio'. Expected ''''' in search condition 'sony vaio'.. Check InnerException, QueryExecuted and Parameters of this exception to examine the cause of this exception.]
   SD.LLBLGen.Pro.ORMSupportClasses.RetrievalQuery.ExecuteScalar() +172
   SD.LLBLGen.Pro.ORMSupportClasses.DaoBase.ExecuteScalarQuery(IRetrievalQuery queryToExecute, ITransaction containingTransaction) +151
   Commerce.DaoClasses.ProductDAO.GetScalar(IEntityFields fields, ITransaction containingTransaction, IPredicate Filter, IRelationCollection relations, IGroupByCollection groupByClause)
   Commerce.CollectionClasses.ProductCollection.GetScalar(ProductFieldIndex fieldIndex, IExpression expressionToExecute, AggregateFunction aggregateToApply, IPredicate filter, IRelationCollection relations, IGroupByCollection groupByClause)
   Commerce.CollectionClasses.ProductCollection.GetDbCount(IPredicate filter, IRelationCollection relations)
   e_commerce.search_results.Page_Load(Object sender, EventArgs e)
   System.Web.UI.Control.OnLoad(EventArgs e) +67
   System.Web.UI.Control.LoadRecursive() +35
   System.Web.UI.Page.ProcessRequestMain() +750


Version Information: Microsoft .NET Framework Version:1.1.4322.2032; ASP.NET Version:1.1.4322.2032

Can you please tell me why that error happened?

Thank you.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 09-Mar-2005 20:45:53   

Specify the string without quotes, do you specify quotes?

Frans Bouma | Lead developer LLBLGen Pro
Zonkle
User
Posts: 18
Joined: 06-Mar-2005
# Posted on: 09-Mar-2005 21:19:38   

In the search box I enter the value without anything extra like: sony vaio

I think there is a way to handle the exceptions without showing that ugly error page right ? ... I will read the Manual more simple_smile

Thanks.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 10-Mar-2005 11:49:03   

Ah simple_smile

Well, I pass the value to search on in a parameter to the FREETEXT/CONTAINS methods. This means that I don't do anything with it, and I think FREETEXT/CONTAINS see the ' ' between the 2 words and then fail. I think you should add a line of code which checks if there is a ' ' in the string entered, and if so, you should add a double quote at both ends of the string and then pass it on to the predicate.

Frans Bouma | Lead developer LLBLGen Pro
Zonkle
User
Posts: 18
Joined: 06-Mar-2005
# Posted on: 10-Mar-2005 16:32:00   

Hi man,

I'm not sure I understand what do you mean confused

But look here please :

I made a Label in the search_results page to show the stings passed, and the qutation you see in the pic I added them .. I mean the qutation are not from the string, it is just HTML.

And in the Address bar above it was like : search_results.aspx?search=sony+vaio

Can you please explain what did you want me to do ? or maybe u can tell me some code.

Thanks.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 10-Mar-2005 16:54:44   

tosearch = Request.QueryString("search") If tosearch.IndexOf(" ") > 0 Then toSearch = """" & toSearch & """"

so in fact you're wrapping your search string in double quotes simple_smile

Frans Bouma | Lead developer LLBLGen Pro
Zonkle
User
Posts: 18
Joined: 06-Mar-2005
# Posted on: 10-Mar-2005 17:44:14   

Thank you very much my hero simple_smile It worked.

What is the IndexOf(" ") ?

Thanks again man, I swear you are so good simple_smile how can you catch up with all of these support question from all users ?! simple_smile

Thanks again.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 10-Mar-2005 17:59:35   

Zonkle wrote:

Thank you very much my hero simple_smile It worked.

What is the IndexOf(" ") ?

hehe simple_smile

That statement returns the first index of " " in the string it is called on. So if that index returned is >=0 then there is a space in your string. simple_smile

Thanks again man, I swear you are so good simple_smile how can you catch up with all of these support question from all users ?! simple_smile Thanks again.

It's sometimes a lot of work, but manageable. simple_smile Most of the questions are fairly straightforward though, so it doesn't take a lot of time to get them answered simple_smile

And thanks for the compliments simple_smile

Frans Bouma | Lead developer LLBLGen Pro
Zonkle
User
Posts: 18
Joined: 06-Mar-2005
# Posted on: 11-Mar-2005 11:43:25   

Good luck man simple_smile

About the IndexOf(" "), what if the space was at the beggining ? .... i think it has not meaning ,but what if the user entered (without the qutations ""): " sony vaio" ?

Oh ... as I thought is made error rage the same old one. And Also tried to put in the search box (with qutatuions): " sony vaio" or : "sony vaio" And they both made error rage Maybe I have to make more validation and exception handling ?

Hmm ..... I think I'm having diffuclties in making advanced searches. I don't know if you can help me in it ?flushed

Thanks man ..........

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 11-Mar-2005 11:55:34   

Use string.Trim simple_smile

Frans Bouma | Lead developer LLBLGen Pro