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 Patrick Diviacco <pa...@gmail.com> on 2011/04/01 12:08:28 UTC

indexing data without writing to disk ?

Is there a way to index data into memory without writing to disk in Lucene ?

This is my current code storing it on disk

writer = new IndexWriter(FSDirectory.open(index_dir), new
IndexWriterConfig(org.apache.lucene.util.Version.LUCENE_40, new
WhitespaceAnalyzer(org.apache.lucene.util.Version.LUCENE_40)));

//store sorted content to contents
Iterator<Map.Entry<String,Cluster>> it = clusters.entrySet().iterator();

while (it.hasNext()) {

...
Document document  = new Document();
                document.add(new Field("id", id, Field.Store.YES,
Field.Index.ANALYZED));
               writer.addDocument(document);
}
writer.optimize();
writer.close();


thanks

Re: indexing data without writing to disk ?

Posted by Patrick Diviacco <pa...@gmail.com>.
Ok, I've now seen RAMDirectory class instead and I'm using it together what
the IndexWriter... it should be ok now thanks

On 4 April 2011 13:10, Patrick Diviacco <pa...@gmail.com> wrote:

> ok Thanks,
>
> When I use IndexWriter, I call addDocument method to add a new instance to
> the index.
>
> addDocument takes
> Document doc, Analyzer analyzer
>
> In MemoryIndex, I have addField which wants:
> String fieldName, String text, Analyzer analyzer
>
> Not sure how should I pass the doc, should I get the fields and pass each
> field instead? And how do I group them as unique document ? It is not clear
> how it works.
>
> thanks
>
>
> On 1 April 2011 13:33, jm <jm...@gmail.com> wrote:
>
>> or maybe MemoryIndex  (in contrib) is more suited to what he wants
>>
>> On Fri, Apr 1, 2011 at 1:10 PM, Ian Lea <ia...@gmail.com> wrote:
>>
>> > RAMDirectory.  The clue is in the name ...
>> >
>> >
>> > --
>> > Ian.
>> >
>> >
>> > On Fri, Apr 1, 2011 at 11:08 AM, Patrick Diviacco
>> > <pa...@gmail.com> wrote:
>> > > Is there a way to index data into memory without writing to disk in
>> > Lucene ?
>> > >
>> > > This is my current code storing it on disk
>> > >
>> > > writer = new IndexWriter(FSDirectory.open(index_dir), new
>> > > IndexWriterConfig(org.apache.lucene.util.Version.LUCENE_40, new
>> > > WhitespaceAnalyzer(org.apache.lucene.util.Version.LUCENE_40)));
>> > >
>> > > //store sorted content to contents
>> > > Iterator<Map.Entry<String,Cluster>> it =
>> clusters.entrySet().iterator();
>> > >
>> > > while (it.hasNext()) {
>> > >
>> > > ...
>> > > Document document  = new Document();
>> > >                document.add(new Field("id", id, Field.Store.YES,
>> > > Field.Index.ANALYZED));
>> > >               writer.addDocument(document);
>> > > }
>> > > writer.optimize();
>> > > writer.close();
>> > >
>> > >
>> > > thanks
>> > >
>> >
>> > ---------------------------------------------------------------------
>> > To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
>> > For additional commands, e-mail: java-user-help@lucene.apache.org
>> >
>> >
>>
>
>

Re: indexing data without writing to disk ?

Posted by Patrick Diviacco <pa...@gmail.com>.
ok Thanks,

When I use IndexWriter, I call addDocument method to add a new instance to
the index.

addDocument takes
Document doc, Analyzer analyzer

In MemoryIndex, I have addField which wants:
String fieldName, String text, Analyzer analyzer

Not sure how should I pass the doc, should I get the fields and pass each
field instead? And how do I group them as unique document ? It is not clear
how it works.

thanks

On 1 April 2011 13:33, jm <jm...@gmail.com> wrote:

> or maybe MemoryIndex  (in contrib) is more suited to what he wants
>
> On Fri, Apr 1, 2011 at 1:10 PM, Ian Lea <ia...@gmail.com> wrote:
>
> > RAMDirectory.  The clue is in the name ...
> >
> >
> > --
> > Ian.
> >
> >
> > On Fri, Apr 1, 2011 at 11:08 AM, Patrick Diviacco
> > <pa...@gmail.com> wrote:
> > > Is there a way to index data into memory without writing to disk in
> > Lucene ?
> > >
> > > This is my current code storing it on disk
> > >
> > > writer = new IndexWriter(FSDirectory.open(index_dir), new
> > > IndexWriterConfig(org.apache.lucene.util.Version.LUCENE_40, new
> > > WhitespaceAnalyzer(org.apache.lucene.util.Version.LUCENE_40)));
> > >
> > > //store sorted content to contents
> > > Iterator<Map.Entry<String,Cluster>> it =
> clusters.entrySet().iterator();
> > >
> > > while (it.hasNext()) {
> > >
> > > ...
> > > Document document  = new Document();
> > >                document.add(new Field("id", id, Field.Store.YES,
> > > Field.Index.ANALYZED));
> > >               writer.addDocument(document);
> > > }
> > > writer.optimize();
> > > writer.close();
> > >
> > >
> > > thanks
> > >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> > For additional commands, e-mail: java-user-help@lucene.apache.org
> >
> >
>

Re: indexing data without writing to disk ?

Posted by jm <jm...@gmail.com>.
or maybe MemoryIndex  (in contrib) is more suited to what he wants

On Fri, Apr 1, 2011 at 1:10 PM, Ian Lea <ia...@gmail.com> wrote:

> RAMDirectory.  The clue is in the name ...
>
>
> --
> Ian.
>
>
> On Fri, Apr 1, 2011 at 11:08 AM, Patrick Diviacco
> <pa...@gmail.com> wrote:
> > Is there a way to index data into memory without writing to disk in
> Lucene ?
> >
> > This is my current code storing it on disk
> >
> > writer = new IndexWriter(FSDirectory.open(index_dir), new
> > IndexWriterConfig(org.apache.lucene.util.Version.LUCENE_40, new
> > WhitespaceAnalyzer(org.apache.lucene.util.Version.LUCENE_40)));
> >
> > //store sorted content to contents
> > Iterator<Map.Entry<String,Cluster>> it = clusters.entrySet().iterator();
> >
> > while (it.hasNext()) {
> >
> > ...
> > Document document  = new Document();
> >                document.add(new Field("id", id, Field.Store.YES,
> > Field.Index.ANALYZED));
> >               writer.addDocument(document);
> > }
> > writer.optimize();
> > writer.close();
> >
> >
> > thanks
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>
>

Re: indexing data without writing to disk ?

Posted by Ian Lea <ia...@gmail.com>.
RAMDirectory.  The clue is in the name ...


--
Ian.


On Fri, Apr 1, 2011 at 11:08 AM, Patrick Diviacco
<pa...@gmail.com> wrote:
> Is there a way to index data into memory without writing to disk in Lucene ?
>
> This is my current code storing it on disk
>
> writer = new IndexWriter(FSDirectory.open(index_dir), new
> IndexWriterConfig(org.apache.lucene.util.Version.LUCENE_40, new
> WhitespaceAnalyzer(org.apache.lucene.util.Version.LUCENE_40)));
>
> //store sorted content to contents
> Iterator<Map.Entry<String,Cluster>> it = clusters.entrySet().iterator();
>
> while (it.hasNext()) {
>
> ...
> Document document  = new Document();
>                document.add(new Field("id", id, Field.Store.YES,
> Field.Index.ANALYZED));
>               writer.addDocument(document);
> }
> writer.optimize();
> writer.close();
>
>
> thanks
>

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