This looks pretty good, the search is always looking in
your "basketName" field unless the searchBox.getText() returns
something like "field:value".

What behavior are you seeing (or not seeing that you expect)?

You might try creating your index as an FSDirectory
then getting a copy of Luke to examine it and run some
test queries through, that often helps a lot. Query
lucene luke

Best
Erick

On Thu, Feb 26, 2009 at 12:15 PM, Ambati, Ravi BGI SF <
ravi.amb...@barclaysglobal.com> wrote:

>
> Hi,
>
> Getting started shows how to index files. It does not have an example of
> how to index how to index a list of objects. I was able to create an
> index for the list of objects.
>
> How do I retrieve a list of objects that match the query ?
>
>
>                // Create Index
>            Directory directory = new RAMDirectory();
>            Analyzer analyzer = new StandardAnalyzer();
>            IndexWriter iwriter = null;
>            try {
>                iwriter = new IndexWriter(directory, analyzer, true);
>
>                iwriter.setMaxFieldLength(250000);
>
>                EventList<TestObject> list = getAllBaskets(basketCache);
>                for (TestObject obj : list) {
>                    Document document = new Document();
>                    document.add(new Field("basketName",
> basket.getName(), Field.Store.YES, Field.Index.TOKENIZED));
>                    document
>                            .add(new Field("borrower",
> basket.getBorrowerCode(), Field.Store.YES, Field.Index.TOKENIZED));
>                    document.add(new Field("description",
> basket.getDescription(), Field.Store.YES,
>                            Field.Index.TOKENIZED));
>                    document.add(new Field("id", new
> Long(basket.getId()).toString(), Field.Store.YES,
>                            Field.Index.TOKENIZED));
>                    iwriter.addDocument(document);
>                }
>                iwriter.optimize();
>                iwriter.close();
>
>                // Now search the index:
>                IndexSearcher isearcher = new IndexSearcher(directory);
>                // Parse a simple query that searches for "text":
>                QueryParser parser = new QueryParser("basketName",
> analyzer);
>                Query query = parser.parse(searchBox.getText());
>                Hits hits = isearcher.search(query);
>                // Iterate through the results:
>                List<Long> basketIds = new ArrayList<Long>();
>                for (int i = 0; i < hits.length(); i++) {
>                    Document hitDoc = hits.doc(i);
>                }
>
>
>                isearcher.close();
>                directory.close();
>
> -----Original Message-----
> From: Garth Patil [mailto:garthpa...@gmail.com]
> Sent: Thursday, February 26, 2009 9:11 AM
> To: java-user@lucene.apache.org
> Subject: Re: Simple Java Object Search
>
> Sure:
> http://lucene.apache.org/java/2_4_0/gettingstarted.html
>
> On Thu, Feb 26, 2009 at 9:06 AM, Ambati, Ravi BGI SF
> <ravi.amb...@barclaysglobal.com> wrote:
> >
> > All,
> >
> > I have a list of java objects and would like to index the contents of
> > those objects. And would like to update the index whenever list of
> > objects is changed.
> >
> > The big question is when users searches for something in index, I
> > would like to get all the objects that matached that search string.
> >
> > Would somebody help me in this?
> >
> > Thanks,
> > Ravi Ambati
> >
> >
> > --
> >
> > This message and any attachments are confidential, proprietary, and
> may be privileged. If this message was misdirected, Barclays Global
> Investors (BGI) does not waive any confidentiality or privilege. If you
> are not the intended recipient, please notify us immediately and destroy
> the message without disclosing its contents to anyone. Any distribution,
> use or copying of this e-mail or the information it contains by other
> than an intended recipient is unauthorized. The views and opinions
> expressed in this e-mail message are the author's own and may not
> reflect the views and opinions of BGI, unless the author is authorized
> by BGI to express such views or opinions on its behalf. All email sent
> to or from this address is subject to electronic storage and review by
> BGI. Although BGI operates anti-virus programs, it does not accept
> responsibility for any damage whatsoever caused by viruses being passed.
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: java-user-unsubscr...@lucene.apache.org
> > For additional commands, e-mail: java-user-h...@lucene.apache.org
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscr...@lucene.apache.org
> For additional commands, e-mail: java-user-h...@lucene.apache.org
>
>
>
> --
>
> This message and any attachments are confidential, proprietary, and may be
> privileged. If this message was misdirected, Barclays Global Investors (BGI)
> does not waive any confidentiality or privilege. If you are not the intended
> recipient, please notify us immediately and destroy the message without
> disclosing its contents to anyone. Any distribution, use or copying of this
> e-mail or the information it contains by other than an intended recipient is
> unauthorized. The views and opinions expressed in this e-mail message are
> the author's own and may not reflect the views and opinions of BGI, unless
> the author is authorized by BGI to express such views or opinions on its
> behalf. All email sent to or from this address is subject to electronic
> storage and review by BGI. Although BGI operates anti-virus programs, it
> does not accept responsibility for any damage whatsoever caused by viruses
> being passed.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscr...@lucene.apache.org
> For additional commands, e-mail: java-user-h...@lucene.apache.org
>
>

Reply via email to