lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From soheila dehghanzadeh <sally...@gmail.com>
Subject Index searcher can't find the doc of any field value
Date Sat, 30 Apr 2011 02:44:35 GMT
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.

Mime
View raw message