FullTextSearch: Contains and Score

Posts   
 
    
rango
User
Posts: 8
Joined: 16-Feb-2015
# Posted on: 16-Feb-2015 15:54:16   

I have a table something like this table1(int Id, varchar2() Name, varchar2() Details) I am trying to build a predicate expression for the following SQL is it possible to generate it.

SELECT A.Id, A.Details, score(10) FROM table1 A WHERE CONTAINS (a.Details, 'abc',10) > 0 order by score(10) desc;

Using the FieldFullTextSearchPredicate

predExp.Add(new FieldFullTextSearchPredicate( table1Fields.Details, FullTextSearchOperator.Contains, 'abc'));

i was only able to get something like this

SELECT A.Id, A.Details FROM table1 A WHERE CONTAINS (a.Details, 'abc');

but unable to use the score operator.

LLBLgen pro V 3.5. Oracle DB

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 16-Feb-2015 18:42:40   

There is 2 parts into this. First the predicate then the Order clause.

For the predicate you need to use a normal FieldCompareValuePredicate ... (SomeField > 0) And for the field you need to use a DBFunctionCall as an expression.

Pseudo code:

IExpression containExression = new DbFunctionCall("Contains({0},'{1}', 10)",
                             new object[] {tabel1Fields.Details, "abc"});

var field = tabel1Fields.Details;
field.ExpressionToApply = containExression;

predicate.Add(field > 0);

For the second part you can try a DBFunctionCall to generate the Score part.

Something like:

IExpression scoreExp = new DbFunctionCall("Score(10)", new object[] {});
var field2 = tabel1Fields.Details;
field2.ExpressionToApply = scoreExp;

ISortClause scoreSortClause = new SortClause(field2, null, SortOperator.Descending);
scoreSortClause.EmitAliasForExpressionAggregateField = false;
ISortExpression sorter = new SortExpression(scoreSortClause);

rango
User
Posts: 8
Joined: 16-Feb-2015
# Posted on: 16-Feb-2015 22:58:23   

Thanks walaa for your reply

I tried this my resultant query looks something like this

SELECT A.Id, A.Details, score(10) FROM table1 A WHERE CONTAINS (a.Details, 'abc',10) > 0 order by score(10)() desc;

I am getting an extra set of braces after this.

rango
User
Posts: 8
Joined: 16-Feb-2015
# Posted on: 17-Feb-2015 00:01:04   

instead of IExpression scoreExp = new DbFunctionCall("Score(10)", new object[] {});

i used IExpression scoreExp = new DbFunctionCall("Score({0})", new object[] {10});

it worked.

Thanks a lot !!

rango
User
Posts: 8
Joined: 16-Feb-2015
# Posted on: 24-Feb-2015 23:45:33   

I am receiving a error

ORA-29909: label for the ancillary operator is not a literal number.

Looks like i cant bind variables in score or contains operator

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 25-Feb-2015 06:57:05   

Try

IExpression scoreExp = new DbFunctionCall("Score(10)", null);
David Elizondo | LLBLGen Support Team
daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 25-Feb-2015 07:02:01   
David Elizondo | LLBLGen Support Team
rango
User
Posts: 8
Joined: 16-Feb-2015
# Posted on: 25-Feb-2015 15:12:53   

Its something like this. I am still getting a extra set of braces at the end of score. SELECT A.Id, A.Details, score(10) FROM table1 A WHERE CONTAINS (a.Details, 'abc',10) > 0 order by score(10)() desc;

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39861
Joined: 17-Aug-2003
# Posted on: 25-Feb-2015 15:14:00   

Please don't reopen the old thread, you've started 2 threads on the same topic, this one is closed, please continue with the new one.

Frans Bouma | Lead developer LLBLGen Pro