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 Peyman Faratin <pe...@gmail.com> on 2013/06/18 04:37:58 UTC

Upgrading from 3.6.1 to 4.3.0 and Custom collector

Hi 

I am migrating from Lucene 3.6.1 to 4.3.0. I am however not sure how to migrate my custom collector below to 4.3.0 (this page http://lucene.apache.org/core/4_3_0/MIGRATE.html gives some hints but is the instructions are incomplete and looking at the source examples of custom collectors make me dizzy!!!) 

Any advise would be very much appreciated 

thank you


	public class AllInLinks extends Collector {
		  private Scorer scorer;
		  private int docBase;
		  private String[] store;
		  private HashSet<String> outLinks = new HashSet<String>();

		  public boolean acceptsDocsOutOfOrder() {
		    return true;
		  }
		  public void setScorer(Scorer scorer) {
		    this.scorer = scorer;
		  }
		  public void setNextReader(IndexReader reader, int docBase) throws IOException{
			this.docBase = docBase;
			store = FieldCache.DEFAULT.getStrings(reader,"title");
		  }
		  public void collect(int doc) throws IOException {
			  String page = store[doc];    
			  outLinks.add(page);
		  }
		  public void reset() {
			  outLinks.clear();
			  store = null;
		  }
		  public int getOutLinks() {
		    return outLinks.size();
		  }
	}

Re: Upgrading from 3.6.1 to 4.3.0 and Custom collector

Posted by Peyman Faratin <pe...@robustlinks.com>.
Hi Adrien

thank you very much. It worked. 

have a good day

On Jun 18, 2013, at 5:35 AM, Adrien Grand <jp...@gmail.com> wrote:

> Hi,
> 
> You didn't say specifically what your problem is so I assume it is
> with the following method:
> 
> On Tue, Jun 18, 2013 at 4:37 AM, Peyman Faratin <pe...@gmail.com> wrote:
>>                  public void setNextReader(IndexReader reader, int docBase) throws IOException{
>>                        this.docBase = docBase;
>>                        store = FieldCache.DEFAULT.getStrings(reader,"title");
>>                  }
> 
> setNextReader now takes an AtomicReaderContext as an argument and
> FieldCache.getStrings is now FieldCache.getTerms, so this would give
> something like
> 
> private BinaryDocValues store;
> 
> public void setNextReader(AtomicReaderContext ctx) throws IOException{
>    this.docBase = ctx.docBase;
>    this.store = FieldCache.DEFAULT.getTerms(ctx.reader(), "title");
> }
> 
> public void collect(int doc) throws IOException {
>    BytesRef page = new BytesRef();
>    store.get(doc, page);
>    if (page.bytes != BinaryDocValues.MISSING) {
>        outLinks.add(page.utf8ToString());
>    }
> }
> 
> --
> Adrien
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Re: Upgrading from 3.6.1 to 4.3.0 and Custom collector

Posted by Adrien Grand <jp...@gmail.com>.
Hi,

You didn't say specifically what your problem is so I assume it is
with the following method:

On Tue, Jun 18, 2013 at 4:37 AM, Peyman Faratin <pe...@gmail.com> wrote:
>                   public void setNextReader(IndexReader reader, int docBase) throws IOException{
>                         this.docBase = docBase;
>                         store = FieldCache.DEFAULT.getStrings(reader,"title");
>                   }

setNextReader now takes an AtomicReaderContext as an argument and
FieldCache.getStrings is now FieldCache.getTerms, so this would give
something like

private BinaryDocValues store;

public void setNextReader(AtomicReaderContext ctx) throws IOException{
    this.docBase = ctx.docBase;
    this.store = FieldCache.DEFAULT.getTerms(ctx.reader(), "title");
}

public void collect(int doc) throws IOException {
    BytesRef page = new BytesRef();
    store.get(doc, page);
    if (page.bytes != BinaryDocValues.MISSING) {
        outLinks.add(page.utf8ToString());
    }
}

--
Adrien

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org