You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@lucene.apache.org by Erik Hatcher <li...@ehatchersolutions.com> on 2003/01/20 03:34:35 UTC

SearchBean in action?

Are folks using the SearchBean code found in the 
contributions/searchbean area of the sandbox?

I've just spent a while attempting to get an example working with it 
and I've ended up having to tweak the code to get it working partially. 
  First, I encountered a compilation error because of an unhandled 
exception, so I fixed that.  Next I encountered hard-coded things such 
as the Analyzer and the field to sort by in both SearchBean and 
HitsIterator.  So rather than using SearchBean I just opted for using 
the HitsIterator to sort by a field.  But its constrained to only do 
descending sort order.

If you are using SearchBean and the related HitsIterator and other bits 
to enhance your search results by sorting by a field, care to share 
some example code?  I'd like for it to be a useful addition to my 
searching features, but so far it seems like I'd have to customize it 
so much that I might as well adapt the ideas to my own code rather than 
use it directly.

Thanks,
	Erik


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: SearchBean in action?

Posted by Terry Steichen <te...@net-frame.com>.
Erik,

> > , and (c) - quite
> > frankly - I don't know how to use Bugzilla.
>
> Point, clickclickclickclickclick, its real easy man.  :)  (sorry, I
> couldn't resist the King of the Hill paraphrase)

That's, uh.., not terribly helpful, King of the Hill.  Now you've shown how
stupid I am for all the world (as represented by this list) to see, guess
I'll stop playing Good Samaritan and get back to coding.

Terry



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: SearchBean in action?

Posted by Erik Hatcher <li...@ehatchersolutions.com>.
On Monday, January 20, 2003, at 07:33  PM, Terry Steichen wrote:
> Erik,
>
> You're welcome to the changes.  But (a) I'm not sure the changes are 
> general
> enough to appropriately be added to the code base

The current CVS of HitsIterator is hard-coded to a single field to sort 
upon.  Your code is more general, as well as the changes I made locally 
and independently.  So at least that part seems generally applicable.

> , (b) when/if you commit
> them then there's no need for me to do anything else

All I'm asking is that you diff your code, if you like, and submit it 
as a patch, and note anything you feel isn't general enough and I could 
tweak it appropriately.

> , and (c) - quite
> frankly - I don't know how to use Bugzilla.

Point, clickclickclickclickclick, its real easy man.  :)  (sorry, I 
couldn't resist the King of the Hill paraphrase)

	Erik


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: SearchBean in action?

Posted by Terry Steichen <te...@net-frame.com>.
Erik,

You're welcome to the changes.  But (a) I'm not sure the changes are general
enough to appropriately be added to the code base, (b) when/if you commit
them then there's no need for me to do anything else, and (c) - quite
frankly - I don't know how to use Bugzilla.

Regards,

Terry

----- Original Message -----
From: "Erik Hatcher" <li...@ehatchersolutions.com>
To: "Lucene Users List" <lu...@jakarta.apache.org>
Sent: Monday, January 20, 2003 7:06 PM
Subject: Re: SearchBean in action?


> Terry,
>
> Thanks for sharing your changes.
>
> I have commit access to the sandbox, so if I get into using the
> HitsIterator more I'll be happy to commit these types of changes as
> long as no other dev folks complain.
>
> If you can find the time, please post your patches to Bugzilla for safe
> keeping, and bug me from time to time to review and possibly commit.
>
> I'll probably at least commit the patch to fix the compilation error.
>
> Erik
>
>
> On Monday, January 20, 2003, at 10:32  AM, Terry Steichen wrote:
> > Erik,
> >
> > I got a bit out of sync with the CVS build (because it took a while to
> > integrate the changes), so I can't quickly do a simple diff.  Instead,
> > I'm
> > including the changed methods in HitsIterator in this message
> > verbatim. Not
> > real pretty code, I know, but it does work just fine.
> >
> > Regards and HTH,
> >
> > Terry
>
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>
>
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: SearchBean in action?

Posted by Erik Hatcher <li...@ehatchersolutions.com>.
Terry,

Thanks for sharing your changes.

I have commit access to the sandbox, so if I get into using the 
HitsIterator more I'll be happy to commit these types of changes as 
long as no other dev folks complain.

If you can find the time, please post your patches to Bugzilla for safe 
keeping, and bug me from time to time to review and possibly commit.

I'll probably at least commit the patch to fix the compilation error.

	Erik


On Monday, January 20, 2003, at 10:32  AM, Terry Steichen wrote:
> Erik,
>
> I got a bit out of sync with the CVS build (because it took a while to
> integrate the changes), so I can't quickly do a simple diff.  Instead, 
> I'm
> including the changed methods in HitsIterator in this message 
> verbatim. Not
> real pretty code, I know, but it does work just fine.
>
> Regards and HTH,
>
> Terry


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: SearchBean in action?

Posted by Peter Carlson <ca...@bookandhammer.com>.
Thanks for the additions.

I put SearchBean up in contributions to provide for a simple example of 
sorting.

I will go through and add your suggestions as it seems to be used by 
some people in their systems.

If you have any other items you think should be changed I'd be up for 
your suggestions.

Thanks for the code Terry.

--Peter



On Monday, January 20, 2003, at 07:32 AM, Terry Steichen wrote:

> Erik,
>
> I got a bit out of sync with the CVS build (because it took a while to
> integrate the changes), so I can't quickly do a simple diff.  Instead, 
> I'm
> including the changed methods in HitsIterator in this message 
> verbatim. Not
> real pretty code, I know, but it does work just fine.
>
> Regards and HTH,
>
> Terry
>
> Note: direction can be 'r', 'a' or 'd' (default)
> public HitsIterator(Hits hits, String sortField, String direction) 
> throws
> IOException{
>         this.hitsCollection = hits;
>         if (sortField != null){
>             if ((direction != null) && (!direction.equals("r"))){
>                 sortByField(sortField, direction);
>             }
>         }
>         totalHits = getTotalHits();
>         setPageCount();
>  }
>
>
>  private void sortByField(String fieldName, String direction) throws
> IOException{
>         long start = System.currentTimeMillis();
>         Comparator c = null;
>         if (fieldName == null){
>             return;
>         }
>         SortedField sf = SortedField.getSortedField(fieldName);
>   int dirflag = -1;
>   if(direction.equals("a")) {
>    dirflag = 1;
>   } else if(direction.equals("r")) {
>    dirflag = 0;
>   }
>         if (sf !=null){
>             c = (Comparator) new CompareDocumentsByField(dirflag);
>         } else {
>             arrayOfIndividualHits = null;
>             return;
>         }
>   int i = 0;
>   int id = 0;
>   String fv = null;
>   try{
>          arrayOfIndividualHits = new Object[hitsCollection.length()];
>          long first = System.currentTimeMillis();
>          for (i=0; i<hitsCollection.length(); i++) {
>              id = hitsCollection.id(i);
>     try {
>      fv = sf.getFieldValue(id);
>     } catch (Exception e) {
>      fv = null;
>     }
>     if(fv != null && fv.length() > 0) {
>               arrayOfIndividualHits[i] = new IndividualHit(i, fv,
> hitsCollection.score(i));
>      fv = null;
>     }
>          }
>   } catch (Exception e) {
>    msg("Error ["+fv+"]:"+e);
>   }
>         long second = System.currentTimeMillis();
>
>         Arrays.sort(arrayOfIndividualHits, c);
>    }

>
>
>
>
>
> ----- Original Message -----
> From: "Erik Hatcher" <li...@ehatchersolutions.com>
> To: "Lucene Users List" <lu...@jakarta.apache.org>
> Sent: Monday, January 20, 2003 8:48 AM
> Subject: Re: SearchBean in action?
>
>
>> On Sunday, January 19, 2003, at 11:17  PM, Terry Steichen wrote:
>>> I've recently made some specific additional changes (regarding
>>> scoring, as I
>>> recall).  At this point I don't recall which of these have been
>>> included in
>>> the distribution and which have not.
>>
>> I'm using the latest CVS HEAD version of the searchbean codebase, just
>> for comparisons sake.
>>
>>> However, since then I've been using SearchBean extensively and, my
>>> version
>>> at least, works fine for sorting in either ascending or descending
>>> date (or
>>> relevance) order on whatever field I choose.
>>
>> How are you switching between ascending and descending sort?
>>
>> In HitsIterator, its hardcoded to a particular field.  Why?  I've
>> removed this restriction and here is the diff:
>>
>>       public HitsIterator(Hits hits, String sortFlag) throws 
>> IOException{
>>           this.hitsCollection = hits;
>>           if (sortFlag != null){
>> -            if ((sortFlag != "") &&
>> (sortFlag.equals(SearchBean.SORT_FIELD_RELEVANCE))){
>> -                file://logger.debug("Sorting hits by field 
>> "+sortFlag);
>> +            if (sortFlag != "") {
>> +                System.out.println("Sorting hits by field 
>> "+sortFlag);
>>                   sortByField(sortFlag);
>>                   file://logger.debug("Completed sorting by field
> "+sortFlag);
>>               }
>>
>>
>>
>>> Please let me know what kind of problems you're having and I'll see 
>>> if
>>> I can
>>> help.
>>
>> SearchBean itself is hardcoded to the StandardAnalyzer.  To be
>> generally useful this needs to be made configurable.
>>
>> Those were the main issues I've had.  I'm assuming you've made changes
>> in your version of SearchBean to account for at least the field name 
>> to
>> sort on, or you're always using "relevance" :)
>>
>> Erik
>>
>>
>> --
>> To unsubscribe, e-mail:
> <ma...@jakarta.apache.org>
>> For additional commands, e-mail:
> <ma...@jakarta.apache.org>
>>
>
>
> --
> To unsubscribe, e-mail:   
> <ma...@jakarta.apache.org>
> For additional commands, e-mail: 
> <ma...@jakarta.apache.org>
>
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: SearchBean in action?

Posted by Terry Steichen <te...@net-frame.com>.
Erik,

I got a bit out of sync with the CVS build (because it took a while to
integrate the changes), so I can't quickly do a simple diff.  Instead, I'm
including the changed methods in HitsIterator in this message verbatim. Not
real pretty code, I know, but it does work just fine.

Regards and HTH,

Terry

Note: direction can be 'r', 'a' or 'd' (default)
public HitsIterator(Hits hits, String sortField, String direction) throws
IOException{
        this.hitsCollection = hits;
        if (sortField != null){
            if ((direction != null) && (!direction.equals("r"))){
                sortByField(sortField, direction);
            }
        }
        totalHits = getTotalHits();
        setPageCount();
 }


 private void sortByField(String fieldName, String direction) throws
IOException{
        long start = System.currentTimeMillis();
        Comparator c = null;
        if (fieldName == null){
            return;
        }
        SortedField sf = SortedField.getSortedField(fieldName);
  int dirflag = -1;
  if(direction.equals("a")) {
   dirflag = 1;
  } else if(direction.equals("r")) {
   dirflag = 0;
  }
        if (sf !=null){
            c = (Comparator) new CompareDocumentsByField(dirflag);
        } else {
            arrayOfIndividualHits = null;
            return;
        }
  int i = 0;
  int id = 0;
  String fv = null;
  try{
         arrayOfIndividualHits = new Object[hitsCollection.length()];
         long first = System.currentTimeMillis();
         for (i=0; i<hitsCollection.length(); i++) {
             id = hitsCollection.id(i);
    try {
     fv = sf.getFieldValue(id);
    } catch (Exception e) {
     fv = null;
    }
    if(fv != null && fv.length() > 0) {
              arrayOfIndividualHits[i] = new IndividualHit(i, fv,
hitsCollection.score(i));
     fv = null;
    }
         }
  } catch (Exception e) {
   msg("Error ["+fv+"]:"+e);
  }
        long second = System.currentTimeMillis();

        Arrays.sort(arrayOfIndividualHits, c);
   }





----- Original Message -----
From: "Erik Hatcher" <li...@ehatchersolutions.com>
To: "Lucene Users List" <lu...@jakarta.apache.org>
Sent: Monday, January 20, 2003 8:48 AM
Subject: Re: SearchBean in action?


> On Sunday, January 19, 2003, at 11:17  PM, Terry Steichen wrote:
> > I've recently made some specific additional changes (regarding
> > scoring, as I
> > recall).  At this point I don't recall which of these have been
> > included in
> > the distribution and which have not.
>
> I'm using the latest CVS HEAD version of the searchbean codebase, just
> for comparisons sake.
>
> > However, since then I've been using SearchBean extensively and, my
> > version
> > at least, works fine for sorting in either ascending or descending
> > date (or
> > relevance) order on whatever field I choose.
>
> How are you switching between ascending and descending sort?
>
> In HitsIterator, its hardcoded to a particular field.  Why?  I've
> removed this restriction and here is the diff:
>
>       public HitsIterator(Hits hits, String sortFlag) throws IOException{
>           this.hitsCollection = hits;
>           if (sortFlag != null){
> -            if ((sortFlag != "") &&
> (sortFlag.equals(SearchBean.SORT_FIELD_RELEVANCE))){
> -                file://logger.debug("Sorting hits by field "+sortFlag);
> +            if (sortFlag != "") {
> +                System.out.println("Sorting hits by field "+sortFlag);
>                   sortByField(sortFlag);
>                   file://logger.debug("Completed sorting by field
"+sortFlag);
>               }
>
>
>
> > Please let me know what kind of problems you're having and I'll see if
> > I can
> > help.
>
> SearchBean itself is hardcoded to the StandardAnalyzer.  To be
> generally useful this needs to be made configurable.
>
> Those were the main issues I've had.  I'm assuming you've made changes
> in your version of SearchBean to account for at least the field name to
> sort on, or you're always using "relevance" :)
>
> Erik
>
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: SearchBean in action?

Posted by Erik Hatcher <li...@ehatchersolutions.com>.
On Sunday, January 19, 2003, at 11:17  PM, Terry Steichen wrote:
> I've recently made some specific additional changes (regarding 
> scoring, as I
> recall).  At this point I don't recall which of these have been 
> included in
> the distribution and which have not.

I'm using the latest CVS HEAD version of the searchbean codebase, just 
for comparisons sake.

> However, since then I've been using SearchBean extensively and, my 
> version
> at least, works fine for sorting in either ascending or descending 
> date (or
> relevance) order on whatever field I choose.

How are you switching between ascending and descending sort?

In HitsIterator, its hardcoded to a particular field.  Why?  I've 
removed this restriction and here is the diff:

      public HitsIterator(Hits hits, String sortFlag) throws IOException{
          this.hitsCollection = hits;
          if (sortFlag != null){
-            if ((sortFlag != "") && 
(sortFlag.equals(SearchBean.SORT_FIELD_RELEVANCE))){
-                //logger.debug("Sorting hits by field "+sortFlag);
+            if (sortFlag != "") {
+                System.out.println("Sorting hits by field "+sortFlag);
                  sortByField(sortFlag);
                  //logger.debug("Completed sorting by field "+sortFlag);
              }



> Please let me know what kind of problems you're having and I'll see if 
> I can
> help.

SearchBean itself is hardcoded to the StandardAnalyzer.  To be 
generally useful this needs to be made configurable.

Those were the main issues I've had.  I'm assuming you've made changes 
in your version of SearchBean to account for at least the field name to 
sort on, or you're always using "relevance" :)

	Erik


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: SearchBean in action?

Posted by Terry Steichen <te...@net-frame.com>.
Erik,

Back in September I ran into similar problems and suggested (to the list) a
number of changes, some or all of which have, I believe, been incorporated.
I've recently made some specific additional changes (regarding scoring, as I
recall).  At this point I don't recall which of these have been included in
the distribution and which have not.

However, since then I've been using SearchBean extensively and, my version
at least, works fine for sorting in either ascending or descending date (or
relevance) order on whatever field I choose.

Please let me know what kind of problems you're having and I'll see if I can
help.

Regards,

Terry

----- Original Message -----
From: "Erik Hatcher" <li...@ehatchersolutions.com>
To: <lu...@jakarta.apache.org>
Sent: Sunday, January 19, 2003 9:34 PM
Subject: SearchBean in action?


> Are folks using the SearchBean code found in the
> contributions/searchbean area of the sandbox?
>
> I've just spent a while attempting to get an example working with it
> and I've ended up having to tweak the code to get it working partially.
>   First, I encountered a compilation error because of an unhandled
> exception, so I fixed that.  Next I encountered hard-coded things such
> as the Analyzer and the field to sort by in both SearchBean and
> HitsIterator.  So rather than using SearchBean I just opted for using
> the HitsIterator to sort by a field.  But its constrained to only do
> descending sort order.
>
> If you are using SearchBean and the related HitsIterator and other bits
> to enhance your search results by sorting by a field, care to share
> some example code?  I'd like for it to be a useful addition to my
> searching features, but so far it seems like I'd have to customize it
> so much that I might as well adapt the ideas to my own code rather than
> use it directly.
>
> Thanks,
> Erik
>
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>