Possible bug in .Boost() or am I using it incorrectly?

69 views
Skip to first unread message

Tobias Sebring

unread,
Aug 2, 2012, 7:45:44 PM8/2/12
to rav...@googlegroups.com
This is the index:
public class Data_Search : AbstractIndexCreationTask<Data, Data_Search.Result>
{
public class Result
{
public string Text;
public string Texts;
}

public Data_Search()
{
Map = d => from d in data
select new
{
d.Text,
Texts = new object[] { d.Text, d.Variants.Select(x => x.Text) },
d.Type
};

Index(x => x.Text, FieldIndexing.Analyzed);
Index(x => x.Texts, FieldIndexing.Analyzed);

Analyze(x => x.Text, typeof(SimpleAnalyzer).FullName);
Analyze(x => x.Texts, typeof(SimpleAnalyzer).FullName);
}
}

This is the query I'm using:
var q = session.Advanced.LuceneQuery<Data, Data_Search>()
.UsingDefaultOperator(QueryOperator.And)
.OpenSubclause()
.Search("Text", text)
//.Boost(1.5m)
.OrElse()
.Search("Texts", text)
.CloseSubclause()
.AndAlso()
.OpenSubclause()
.WhereEquals(x => x.Type, type1)
.OrElse()
.WhereEquals(x => x.Type, type2)
.CloseSubclause()
.ToList();

As soon as I uncomment //.Boost(1.5m) the query will no longer return any results. This is true irregardless of where i put it and also true when I set the same boost on both sides of the OrElse. The only boost value that works is 1m and I suspect that is due to it being the default value.

This is on 1.2.2051-Unstable.

Tobias Sebring

unread,
Aug 2, 2012, 7:53:36 PM8/2/12
to ravendb
Some additional info: This only seems to happen when no results are
found for .Search("Text", text) but results are found
for .OrElse().Search("Texts", text).

Oren Eini (Ayende Rahien)

unread,
Aug 3, 2012, 1:44:03 AM8/3/12
to rav...@googlegroups.com
Can you create a failing test?

Tobias Sebring

unread,
Aug 3, 2012, 4:37:43 AM8/3/12
to ravendb
Here is a complete repro on 1.2.2055-Unstable:
https://dl.dropbox.com/u/6420016/DataQuery.zip

Query 1 will succeed due to .Boost(1m) (1m being key)
Query 2 will fail due to .Boost(1.5m) and matching on .OrElse
Query 3 will succeed even though .Boost(1.5m) due to matching
on .Where before .OrElse

I added another weird case in there which I would be happy if you
could have a look at. When using .OrElse.Not.Where(x => x.Type, type)
no match will be returned even though there is one document in the
index that should match this case. The code utilizes a workaround
which only works when there are two Types: .OrElse.Where(x => x.Type,
type == DataType.Type1 ? DataType.Type2 : DataType.Type1).

On Aug 3, 7:44 am, "Oren Eini (Ayende Rahien)" <aye...@ayende.com>
wrote:

Oren Eini (Ayende Rahien)

unread,
Aug 3, 2012, 4:46:31 AM8/3/12
to rav...@googlegroups.com
When running this, I get:

Initializing...
Deleting previously inserted documents...
Importing data...
Data import completed...
Waiting for non-stale index and querying...

.Boost(1m): This query will succeed...
Query returned 1 results...

Changed to .Boost(1.5m): This query will fail...
Query returned 1 results...

.Boost(1.5m) but this time we match on .Search("Text", name): This query will su
cceed...
Query returned 1 results...


Which seems to be fine.

Tobias Sebring

unread,
Aug 3, 2012, 5:08:52 AM8/3/12
to ravendb
That is odd. I have run this query many-many times and the second
query have never been successful. I just ran it again on a fresh
ravendb and it fails every time.

Any idea what could be causing this and/or what parameters in my
environment that is not part of the solution could play a part in the
causing the query to fail?

On Aug 3, 10:46 am, "Oren Eini (Ayende Rahien)" <aye...@ayende.com>
wrote:

Oren Eini (Ayende Rahien)

unread,
Aug 3, 2012, 5:11:14 AM8/3/12
to rav...@googlegroups.com
You don't have WaitForNonStaleResults there, it might be that

Tobias Sebring

unread,
Aug 3, 2012, 5:19:38 AM8/3/12
to ravendb
This line is used for each of the querys:
var datas = q.WaitForNonStaleResults().ToList();

Do I need to put it further up in the query expression? The code where
I initially experienced this issue is fully indexed with not a single
stale index and no write operations after initial import.

Could it be a culture issue or such?

On Aug 3, 11:11 am, "Oren Eini (Ayende Rahien)" <aye...@ayende.com>
wrote:

Oren Eini (Ayende Rahien)

unread,
Aug 3, 2012, 5:23:40 AM8/3/12
to rav...@googlegroups.com
inline

On Fri, Aug 3, 2012 at 12:19 PM, Tobias Sebring <tseb...@gmail.com> wrote:
This line is used for each of the querys:
var datas = q.WaitForNonStaleResults().ToList();

No, it doesn't matter 
 
Do I need to put it further up in the query expression? The code where
I initially experienced this issue is fully indexed with not a single
stale index and no write operations after initial import.

Could it be a culture issue or such?

I don't believe so.
And 2055 is very recent.

Just to be sure, what _is_ your culture settings?

Tobias Sebring

unread,
Aug 3, 2012, 5:25:18 AM8/3/12
to ravendb
Yep. It's the culture on my maching. Add this at the top of the main
function and the second query will fail:
Thread.CurrentThread.CurrentCulture = new CultureInfo("sv-SE");

Tobias Sebring

unread,
Aug 3, 2012, 5:34:17 AM8/3/12
to ravendb
I don't think the culture should be relevant in my code but I may be
wrong? If I run the second query trying to match a English string that
I also added to .Secondary on the document - it will still fail.

I had a friend run the same project on his manching with the same
result. Our default culture (sv-SE) will cause the second query to
fail, but changing the default culture for the thread to en-US causes
the second query to succeed.

Oren Eini (Ayende Rahien)

unread,
Aug 3, 2012, 11:52:33 AM8/3/12
to rav...@googlegroups.com
No, it isn't relevant.
That is a bug, I'll fix it.

Tobias Sebring

unread,
Aug 3, 2012, 12:33:06 PM8/3/12
to ravendb
I mentioned another problem I'm having with the repro code in
that .OrElse.Not.Where(x => x.Type, type) never returns any results.
I'm using .WhereEquals(x => x.Type, type == DataType.Type1 ?
DataType.Type2 : DataType.Type1) to work around this fact.

Do you know if this is another bug or if I'm using .Not.WhereEquals
incorrectly?

The repro contains code to test this and you may
uncomment .Not.WhereEquals in each of the queries to reproduce the
issue:
.Not.WhereEquals(x => x.Type, type) //this does not work (why?)
//.WhereEquals(x => x.Type, type == DataType.Type1 ? DataType.Type2 :
DataType.Type1)

On Aug 3, 5:52 pm, "Oren Eini (Ayende Rahien)" <aye...@ayende.com>
wrote:

Oren Eini (Ayende Rahien)

unread,
Aug 3, 2012, 12:34:56 PM8/3/12
to rav...@googlegroups.com
I can't follow this in pieces, can you show a full example?

Oren Eini (Ayende Rahien)

unread,
Aug 3, 2012, 12:35:10 PM8/3/12
to rav...@googlegroups.com
Note that in order for NOT to work, you need to have a positive side as well

Tobias Sebring

unread,
Aug 3, 2012, 1:22:10 PM8/3/12
to ravendb
Parameters:
Documents = [
{ Text = "test", Type = Type1 }
];

name = "test";
type = Type2;

Query:
var q = session.Advanced.LuceneQuery<Data, Data_Search>()
.UsingDefaultOperator(QueryOperator.And)
.OpenSubclause()
.Search("Text", name)
.Boost(2m)
.OrElse()
.Search("Texts", name)
.CloseSubclause()
.OpenSubclause()
.WhereEquals(x => x.Type, type)
.Boost(1.5m)
.OrElse()
.Not.WhereEquals(x => x.Type, type)
.CloseSubclause();
.WaitForNonStaleResults()
.ToList();

First subquery will match "test" == "test" on .Search("Text", name).
Second subquery will not match Type1 == Type2 on .WhereEquals(x =>
x.Type, type)
Second subquery should match Type1 != Type2 on .Not.WhereEquals(x =>
x.Type, type) but it does not.


On Aug 3, 6:35 pm, "Oren Eini (Ayende Rahien)" <aye...@ayende.com>
wrote:
> Note that in order for NOT to work, you need to have a positive side as well
>
> On Fri, Aug 3, 2012 at 7:34 PM, Oren Eini (Ayende Rahien) <aye...@ayende.com
>
>
>
>
>
>
>
> > wrote:
> > I can't follow this in pieces, can you show a full example?
>

Oren Eini (Ayende Rahien)

unread,
Aug 3, 2012, 4:02:53 PM8/3/12
to rav...@googlegroups.com
This is expected.
Not is based on doing a set not, which means that if the other side is empty, you get empty result.

You want to express a not like this:

   .OpenSubclause()
                .Where("*:*")
                .AndAlso()
                .Not.WhereEquals(x => x.Type, type)
   .CloseSubclause()

Match everything, except...

Tobias Sebring

unread,
Aug 3, 2012, 4:12:21 PM8/3/12
to ravendb
I see. Do you have any recommendation on how I could set up my query
when I wish to boost the score of one particular type but include all
types in the result?

Match everything but boost score if type equal x.

On Aug 3, 10:02 pm, "Oren Eini (Ayende Rahien)" <aye...@ayende.com>
wrote:
> ...
>
> read more »

Oren Eini (Ayende Rahien)

unread,
Aug 3, 2012, 4:13:45 PM8/3/12
to rav...@googlegroups.com
WhereEquals("Type", "one").Boost(1.5)
.WhereEquals("Type", "two") 

Note this assumes default operator of OR

Tobias Sebring

unread,
Aug 3, 2012, 4:41:52 PM8/3/12
to ravendb
This is what I have been doing - but what if Type is an enum that has
five or ten different values?

On Aug 3, 10:13 pm, "Oren Eini (Ayende Rahien)" <aye...@ayende.com>
wrote:
> ...
>
> read more »

Oren Eini (Ayende Rahien)

unread,
Aug 4, 2012, 5:07:24 AM8/4/12
to rav...@googlegroups.com
And you can for just one of them?
 WhereEquals("Type", "one").Boost(1.5)
 .WhereEquals("Type", "*") 

This would match any value.

Tobias Sebring

unread,
Aug 4, 2012, 7:36:52 AM8/4/12
to ravendb
I'm going to try that. Thanks so much for your help!

On Aug 4, 11:07 am, "Oren Eini (Ayende Rahien)" <aye...@ayende.com>
wrote:
> ...
>
> read more »
Reply all
Reply to author
Forward
0 new messages