You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@lucenenet.apache.org by Sawan Sharma <ss...@chambal.com> on 2007/05/24 06:52:01 UTC

Solr Java code to VB.NET conversion problem

 Hi All,

I am using Solr facets logic to implement faceted searching in my web site.

One problem I am facing here is that I am using BitArray class of .NET
instead of BitSet class of java. The BitSet class has one method
"Cardinality" which is not available in BitArray. This method returns number
of True bits in BitSet. To achieve this goal I have used following logic...

       Dim c As Integer = 0
        For Each bit As Boolean In BitArray
            If bit Then
                c += 1
            End If
        Next
        Return c

Here I have used Loop and it consume little bit more time while preparing
facets.

I would be interested in hearing what others think about this problem and
how to best implement this functionality.

Thanks in advance

Sawan

Re: Solr Java code to VB.NET conversion problem

Posted by Patrick Burrows <pb...@gmail.com>.
Ah... I see. I've never actually used the BitArray type before. There is no
way to convert from BitArray to a numeric type. That is too bad. It really
leaves iterating through the entire array as the only way to check all the
values.

Can you not use a numeric type instead? I'm not sure what value a BitArray
brings, over an array of ints (for instance). The operations and methods
to manipulate individual bits have been around since the stone age (re: the
K&R algorithm). The BitArray seems to just get in the way.

Unfortunately, it sounds like making this change would break DotLucene (or
at least backwards compatibility).




On 5/24/07, Jokin Cuadrado <jo...@gmail.com> wrote:
>
> I think the problem here is that you can't access to the intern
> representation of the bitarray, the way migth be a subclass, but
> bitarray is marked as not inheritable.
>
> you can use  lucene.net.util.bitset, wich is (from the file):
>
> Optimized implementation of a vector of bits.  This is more-or-less like
> java.util.BitSet, but also includes the following
>
> but this would change the signature of the toHits function and would
> bea breaking change.
>
> as you can see is not a simple question.
>
>
>
> On 5/24/07, Patrick Burrows <pb...@gmail.com> wrote:
> > ...though, apparently Kernighan didn't invent the method. From the link
> I
> > posted:
> >
> >
> > Published in 1988, the C Programming Language 2nd Ed. (by Brian W.
> Kernighan
> > and Dennis M. Ritchie) mentions this in exercise 2-9. On April 19, 2006
> Don
> > Knuth pointed out to me that this method "was first published by Peter
> > Wegner in CACM 3 (1960), 322. (Also discovered independently by Derrick
> > Lehmer and published in 1964 in a book edited by Beckenbach.)"
> >
> >
> >
> > On 5/24/07, Patrick Burrows <pb...@gmail.com> wrote:
> >
> > > Here's how Kernighan does it (the K in K&R)[1], translated to C#:
> > >
> > > int x = 3;
> > > int c;
> > > for (c = 0; x!=0; c++)
> > > {
> > >     x &= x - 1;
> > > }
> > >
> > > the above has the advantage over your original code in that it only
> loops
> > > for the number of bits that are set, instead of over every bit.
> > >
> > >
> > > [1]
> > >
> http://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetKernighan
> > >
> > >
> > > On 5/24/07, Sawan Sharma <ss...@chambal.com> wrote:
> > > >
> > > > Hi All,
> > > >
> > > > I am using Solr facets logic to implement faceted searching in my
> web
> > > > site.
> > > >
> > > > One problem I am facing here is that I am using BitArray class of
> .NET
> > > > instead of BitSet class of java. The BitSet class has one method
> > > > "Cardinality" which is not available in BitArray. This method
> returns
> > > > number
> > > > of True bits in BitSet. To achieve this goal I have used following
> > > > logic...
> > > >
> > > >       Dim c As Integer = 0
> > > >        For Each bit As Boolean In BitArray
> > > >            If bit Then
> > > >                c += 1
> > > >            End If
> > > >        Next
> > > >        Return c
> > > >
> > > > Here I have used Loop and it consume little bit more time while
> > > > preparing
> > > > facets.
> > > >
> > > > I would be interested in hearing what others think about this
> problem
> > > > and
> > > > how to best implement this functionality.
> > > >
> > > > Thanks in advance
> > > >
> > > > Sawan
> > > >
> > >
> > >
> > >
> > > --
> > > -
> > > P
> >
> >
> >
> >
> > --
> > -
> > P
> >
>



-- 
-
P

Re: Solr Java code to VB.NET conversion problem

Posted by Patrick Burrows <pb...@gmail.com>.
The BetterBitArray which the LuceneBitArray inherits from has the methods
(TrueCount). Their algorithm, though, is as slow as the original code posted
here. But inside the BetterBitArray the values are stored as an array of
ints, so you could easily increase the speed of the check using the better
algorithms.




On 5/24/07, Jokin Cuadrado <jo...@gmail.com> wrote:
>
> i have found the a bitarray implementation by beagle (desktop search
> on linux with mono and lucene)
>
> http://www.koders.com/csharp/fid6CEE5E59B633E02C32956D97D2D758995E82FA0B.aspx
>
> might be a good starting point.
>
> On 5/24/07, Jokin Cuadrado <jo...@gmail.com> wrote:
> > I think the problem here is that you can't access to the intern
> > representation of the bitarray, the way migth be a subclass, but
> > bitarray is marked as not inheritable.
> >
> > you can use  lucene.net.util.bitset, wich is (from the file):
> >
> > Optimized implementation of a vector of bits.  This is more-or-less like
> > java.util.BitSet, but also includes the following
> >
> > but this would change the signature of the toHits function and would
> > bea breaking change.
> >
> > as you can see is not a simple question.
> >
> >
> >
> > On 5/24/07, Patrick Burrows <pb...@gmail.com> wrote:
> > > ...though, apparently Kernighan didn't invent the method. From the
> link I
> > > posted:
> > >
> > >
> > > Published in 1988, the C Programming Language 2nd Ed. (by Brian W.
> Kernighan
> > > and Dennis M. Ritchie) mentions this in exercise 2-9. On April 19,
> 2006 Don
> > > Knuth pointed out to me that this method "was first published by Peter
> > > Wegner in CACM 3 (1960), 322. (Also discovered independently by
> Derrick
> > > Lehmer and published in 1964 in a book edited by Beckenbach.)"
> > >
> > >
> > >
> > > On 5/24/07, Patrick Burrows <pb...@gmail.com> wrote:
> > >
> > > > Here's how Kernighan does it (the K in K&R)[1], translated to C#:
> > > >
> > > > int x = 3;
> > > > int c;
> > > > for (c = 0; x!=0; c++)
> > > > {
> > > >     x &= x - 1;
> > > > }
> > > >
> > > > the above has the advantage over your original code in that it only
> loops
> > > > for the number of bits that are set, instead of over every bit.
> > > >
> > > >
> > > > [1]
> > > >
> http://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetKernighan
> > > >
> > > >
> > > > On 5/24/07, Sawan Sharma <ss...@chambal.com> wrote:
> > > > >
> > > > > Hi All,
> > > > >
> > > > > I am using Solr facets logic to implement faceted searching in my
> web
> > > > > site.
> > > > >
> > > > > One problem I am facing here is that I am using BitArray class of
> .NET
> > > > > instead of BitSet class of java. The BitSet class has one method
> > > > > "Cardinality" which is not available in BitArray. This method
> returns
> > > > > number
> > > > > of True bits in BitSet. To achieve this goal I have used following
> > > > > logic...
> > > > >
> > > > >       Dim c As Integer = 0
> > > > >        For Each bit As Boolean In BitArray
> > > > >            If bit Then
> > > > >                c += 1
> > > > >            End If
> > > > >        Next
> > > > >        Return c
> > > > >
> > > > > Here I have used Loop and it consume little bit more time while
> > > > > preparing
> > > > > facets.
> > > > >
> > > > > I would be interested in hearing what others think about this
> problem
> > > > > and
> > > > > how to best implement this functionality.
> > > > >
> > > > > Thanks in advance
> > > > >
> > > > > Sawan
> > > > >
> > > >
> > > >
> > > >
> > > > --
> > > > -
> > > > P
> > >
> > >
> > >
> > >
> > > --
> > > -
> > > P
> > >
> >
>



-- 
-
P

Re: Solr Java code to VB.NET conversion problem

Posted by Jokin Cuadrado <jo...@gmail.com>.
i have found the a bitarray implementation by beagle (desktop search
on linux with mono and lucene)
http://www.koders.com/csharp/fid6CEE5E59B633E02C32956D97D2D758995E82FA0B.aspx

might be a good starting point.

On 5/24/07, Jokin Cuadrado <jo...@gmail.com> wrote:
> I think the problem here is that you can't access to the intern
> representation of the bitarray, the way migth be a subclass, but
> bitarray is marked as not inheritable.
>
> you can use  lucene.net.util.bitset, wich is (from the file):
>
> Optimized implementation of a vector of bits.  This is more-or-less like
> java.util.BitSet, but also includes the following
>
> but this would change the signature of the toHits function and would
> bea breaking change.
>
> as you can see is not a simple question.
>
>
>
> On 5/24/07, Patrick Burrows <pb...@gmail.com> wrote:
> > ...though, apparently Kernighan didn't invent the method. From the link I
> > posted:
> >
> >
> > Published in 1988, the C Programming Language 2nd Ed. (by Brian W. Kernighan
> > and Dennis M. Ritchie) mentions this in exercise 2-9. On April 19, 2006 Don
> > Knuth pointed out to me that this method "was first published by Peter
> > Wegner in CACM 3 (1960), 322. (Also discovered independently by Derrick
> > Lehmer and published in 1964 in a book edited by Beckenbach.)"
> >
> >
> >
> > On 5/24/07, Patrick Burrows <pb...@gmail.com> wrote:
> >
> > > Here's how Kernighan does it (the K in K&R)[1], translated to C#:
> > >
> > > int x = 3;
> > > int c;
> > > for (c = 0; x!=0; c++)
> > > {
> > >     x &= x - 1;
> > > }
> > >
> > > the above has the advantage over your original code in that it only loops
> > > for the number of bits that are set, instead of over every bit.
> > >
> > >
> > > [1]
> > > http://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetKernighan
> > >
> > >
> > > On 5/24/07, Sawan Sharma <ss...@chambal.com> wrote:
> > > >
> > > > Hi All,
> > > >
> > > > I am using Solr facets logic to implement faceted searching in my web
> > > > site.
> > > >
> > > > One problem I am facing here is that I am using BitArray class of .NET
> > > > instead of BitSet class of java. The BitSet class has one method
> > > > "Cardinality" which is not available in BitArray. This method returns
> > > > number
> > > > of True bits in BitSet. To achieve this goal I have used following
> > > > logic...
> > > >
> > > >       Dim c As Integer = 0
> > > >        For Each bit As Boolean In BitArray
> > > >            If bit Then
> > > >                c += 1
> > > >            End If
> > > >        Next
> > > >        Return c
> > > >
> > > > Here I have used Loop and it consume little bit more time while
> > > > preparing
> > > > facets.
> > > >
> > > > I would be interested in hearing what others think about this problem
> > > > and
> > > > how to best implement this functionality.
> > > >
> > > > Thanks in advance
> > > >
> > > > Sawan
> > > >
> > >
> > >
> > >
> > > --
> > > -
> > > P
> >
> >
> >
> >
> > --
> > -
> > P
> >
>

Re: Solr Java code to VB.NET conversion problem

Posted by Jokin Cuadrado <jo...@gmail.com>.
I think the problem here is that you can't access to the intern
representation of the bitarray, the way migth be a subclass, but
bitarray is marked as not inheritable.

you can use  lucene.net.util.bitset, wich is (from the file):

Optimized implementation of a vector of bits.  This is more-or-less like
java.util.BitSet, but also includes the following

but this would change the signature of the toHits function and would
bea breaking change.

as you can see is not a simple question.



On 5/24/07, Patrick Burrows <pb...@gmail.com> wrote:
> ...though, apparently Kernighan didn't invent the method. From the link I
> posted:
>
>
> Published in 1988, the C Programming Language 2nd Ed. (by Brian W. Kernighan
> and Dennis M. Ritchie) mentions this in exercise 2-9. On April 19, 2006 Don
> Knuth pointed out to me that this method "was first published by Peter
> Wegner in CACM 3 (1960), 322. (Also discovered independently by Derrick
> Lehmer and published in 1964 in a book edited by Beckenbach.)"
>
>
>
> On 5/24/07, Patrick Burrows <pb...@gmail.com> wrote:
>
> > Here's how Kernighan does it (the K in K&R)[1], translated to C#:
> >
> > int x = 3;
> > int c;
> > for (c = 0; x!=0; c++)
> > {
> >     x &= x - 1;
> > }
> >
> > the above has the advantage over your original code in that it only loops
> > for the number of bits that are set, instead of over every bit.
> >
> >
> > [1]
> > http://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetKernighan
> >
> >
> > On 5/24/07, Sawan Sharma <ss...@chambal.com> wrote:
> > >
> > > Hi All,
> > >
> > > I am using Solr facets logic to implement faceted searching in my web
> > > site.
> > >
> > > One problem I am facing here is that I am using BitArray class of .NET
> > > instead of BitSet class of java. The BitSet class has one method
> > > "Cardinality" which is not available in BitArray. This method returns
> > > number
> > > of True bits in BitSet. To achieve this goal I have used following
> > > logic...
> > >
> > >       Dim c As Integer = 0
> > >        For Each bit As Boolean In BitArray
> > >            If bit Then
> > >                c += 1
> > >            End If
> > >        Next
> > >        Return c
> > >
> > > Here I have used Loop and it consume little bit more time while
> > > preparing
> > > facets.
> > >
> > > I would be interested in hearing what others think about this problem
> > > and
> > > how to best implement this functionality.
> > >
> > > Thanks in advance
> > >
> > > Sawan
> > >
> >
> >
> >
> > --
> > -
> > P
>
>
>
>
> --
> -
> P
>

Re: Solr Java code to VB.NET conversion problem

Posted by Patrick Burrows <pb...@gmail.com>.
...though, apparently Kernighan didn't invent the method. From the link I
posted:


Published in 1988, the C Programming Language 2nd Ed. (by Brian W. Kernighan
and Dennis M. Ritchie) mentions this in exercise 2-9. On April 19, 2006 Don
Knuth pointed out to me that this method "was first published by Peter
Wegner in CACM 3 (1960), 322. (Also discovered independently by Derrick
Lehmer and published in 1964 in a book edited by Beckenbach.)"



On 5/24/07, Patrick Burrows <pb...@gmail.com> wrote:

> Here's how Kernighan does it (the K in K&R)[1], translated to C#:
>
> int x = 3;
> int c;
> for (c = 0; x!=0; c++)
> {
>     x &= x - 1;
> }
>
> the above has the advantage over your original code in that it only loops
> for the number of bits that are set, instead of over every bit.
>
>
> [1]
> http://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetKernighan
>
>
> On 5/24/07, Sawan Sharma <ss...@chambal.com> wrote:
> >
> > Hi All,
> >
> > I am using Solr facets logic to implement faceted searching in my web
> > site.
> >
> > One problem I am facing here is that I am using BitArray class of .NET
> > instead of BitSet class of java. The BitSet class has one method
> > "Cardinality" which is not available in BitArray. This method returns
> > number
> > of True bits in BitSet. To achieve this goal I have used following
> > logic...
> >
> >       Dim c As Integer = 0
> >        For Each bit As Boolean In BitArray
> >            If bit Then
> >                c += 1
> >            End If
> >        Next
> >        Return c
> >
> > Here I have used Loop and it consume little bit more time while
> > preparing
> > facets.
> >
> > I would be interested in hearing what others think about this problem
> > and
> > how to best implement this functionality.
> >
> > Thanks in advance
> >
> > Sawan
> >
>
>
>
> --
> -
> P




-- 
-
P

Re: Solr Java code to VB.NET conversion problem

Posted by Patrick Burrows <pb...@gmail.com>.
Here's how Kernighan does it (the K in K&R)[1], translated to C#:

int x = 3;
int c;
for (c = 0; x!=0; c++)
{
    x &= x - 1;
}

the above has the advantage over your original code in that it only loops
for the number of bits that are set, instead of over every bit.


[1]
http://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetKernighan


On 5/24/07, Sawan Sharma <ss...@chambal.com> wrote:
>
> Hi All,
>
> I am using Solr facets logic to implement faceted searching in my web
> site.
>
> One problem I am facing here is that I am using BitArray class of .NET
> instead of BitSet class of java. The BitSet class has one method
> "Cardinality" which is not available in BitArray. This method returns
> number
> of True bits in BitSet. To achieve this goal I have used following
> logic...
>
>       Dim c As Integer = 0
>        For Each bit As Boolean In BitArray
>            If bit Then
>                c += 1
>            End If
>        Next
>        Return c
>
> Here I have used Loop and it consume little bit more time while preparing
> facets.
>
> I would be interested in hearing what others think about this problem and
> how to best implement this functionality.
>
> Thanks in advance
>
> Sawan
>



-- 
-
P