lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Erick Erickson <erickerick...@gmail.com>
Subject Re: Index searcher can't find the doc of any field value
Date Mon, 02 May 2011 12:04:51 GMT
First, this kind of question is better suited for the Lucene User's list,
this list is intended for people actively developing the lucene code
itself.

That said, your problem most likely is that you are indexing your
fields "UN_TOKENIZED", which means that the information isn't
split into words. Try using "TOKENIZED".

By the way, what version are you using? UN_TOKENIZED has been
deprecated for quite some time.
You would probably get a lot of value from Luke..

Best
Erick

On Fri, Apr 29, 2011 at 10:44 PM, soheila dehghanzadeh
<sally.de@gmail.com> wrote:
> Hi Friends,
>
> i'm using lucene to index a file with this format, each lines contains 4
> elements which separated by space. because I want to retrieve any line with
> special text in a special part, so I try to add each line to index in a
> seprate document with 4 fields. for example I named fields A,B,C,D
>
> so i use this code to index my file:
>
> File file = new File("e://data3");
>
>             BufferedReader reader = new BufferedReader(new
> FileReader(file));
>
>             IndexWriter writer = new IndexWriter(indexDirectory, new
> SimpleAnalyzer(),true);
>
>             writer.setUseCompoundFile(true);
>
>             String line;
>
>             while ((line = reader.readLine()) != null) {
>
>                 string[] index = line.split(" ");
>
>                 Document document = new Document();
>
>                 document.add(new Field("A", index[0], Field.Store.YES,
> Field.Index.UN_TOKENIZED));
>
>                 document.add(new Field("B", index[1], Field.Store.YES,
> Field.Index.UN_TOKENIZED));
>
>                 document.add(new Field("C", index[2], Field.Store.YES,
> Field.Index.UN_TOKENIZED));
>
>                 document.add(new Field("D", index[3], Field.Store.YES,
> Field.Index.UN_TOKENIZED));
>
>                 writer.addDocument(document);
>
>                 System.out.println(writer.docCount());
>
>             }
>
>         } catch (Exception e) {
>
>             e.printStackTrace();
>
>         }
>
> but when i try to search this index with some letters which exist in for
> example field A it fails to find the document(line) :( my search code is as
> follows:
>
> try {
>
>             IndexSearcher is = new
> IndexSearcher(FSDirectory.getDirectory(indexDirectory, false));
>
>             Query q = new TermQuery(new Term("A", "hello"));
>
>             Hits hits = is.search(q);
>
>             for (int i = 0; i < hits.length(); i++) {
>
>                 Document doc = hits.doc(i);
>
>                 System.out.println("A: "+doc.get("A")+" B:"+doc.get("B")+"
> C:"+doc.get("C")+" D:"+doc.get("D"));
>
>             }
>
>         } catch (Exception e) {
>
>             e.printStackTrace();
>
>         }
>
>
>
> kindly let me know if there is any error in my code . thanks in advance.

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


Mime
View raw message