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 "Cecil, Paula New" <cn...@fuse.net> on 2001/11/19 03:12:03 UTC

Can't locate field

This is my first message to this list.  I have successfully created several little tests of the Lucene api.  In my last test, I am trying to index "data records".  Only the "primary key" needs to be stored (and I did not even index this field).  For the others I want to index, but neither store or tokenize (I want the the entire text string to be the "term").

So my index code looks like:
    doc.add(Field.UnIndexed("userid", dtable[i][iuserid]));
    doc.add(new Field("charge",dtable[i][icharge],false,true,false));
    doc.add(new Field("fname", dtable[i][ifname],false,true,false));
    doc.add(new Field("lname", dtable[i][ilname],false,true,false));
    doc.add(new Field("email", dtable[i][iemail],false,true,false));
    doc.add(new Field("hiredt",dtable[i][ihiredt],false,true,false));
    doc.add(new Field("title",  dtable[i][ititle],false,true,true));

The last field I tokenize and it seems to work ok.  The others never return hits.

My search code is below.  Essentially I am trying to search like this:
java ./index lname smith

Which should find everyone with a last name of "smith".  But no hits are returned.
What am I doing wrong?

Thanks


public class Search {
  public static void main(String[] args) throws Exception {
 Date start = new Date();
    String indexPath = args[0], qfield = args[1], queryString = args[2];

    Searcher searcher = new IndexSearcher(indexPath);
    Query query = QueryParser.parse(queryString, qfield,
                              new SimpleAnalyzer());
    Hits hits = searcher.search(query);

 Date stop = new Date();
 if ( args.length > 2 ) {
  for (int i=0; i<hits.length(); i++) {
    System.out.println(
     "Userid "+hits.doc(i).get("userid") +
     "; Score: " +
     hits.score(i));
  };
 }
    System.out.println("\nNumber of hits: "+ hits.length());
    long totalms = stop.getTime() - start.getTime();
 System.out.println(totalms + " total milliseconds");
  }
}

Re: Can't locate field

Posted by "Cecil, Paula New" <cn...@fuse.net>.
here is the full indexing code.  and it does use the SimpleAnalyzer.
thanks for your help!

import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.util.*;

import org.apache.lucene.analysis.SimpleAnalyzer;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.document.*;

public class Indexer {
    public static void main(String[] args) {
  String indexLoc = "./index";
  int iuserid = 0;
  int icharge = 1;
  int ifname  = 2;
  int ilname  = 3;
  int iemail  = 4;
  int ihiredt = 5;
  int ititle  = 6;
  // store index token

  IndexWriter writer;

  Date start = new Date();

        try {
   writer = new IndexWriter(indexLoc, new SimpleAnalyzer(), false);
   String data   = StringHelper.fileToString("u2info.txt");
   String[][] dtable = StringHelper.toTable(data,"\n","|");
            for ( int i=0; i < dtable.length; i++ ) {

    org.apache.lucene.document.Document doc =
     new org.apache.lucene.document.Document();
    // add userid as unindexed - can't search, but it is stored
    // so this is like an oid.
    doc.add(Field.UnIndexed("userid", dtable[i][iuserid]));
    // add others as follows:
    // a. don't store (can't retrieve value)
    // b. do index (ie, can search on the value)
    // c. don't tokenize, just use whole field as-is
    doc.add(new Field("charge",dtable[i][icharge],false,true,false));
    doc.add(new Field("fname", dtable[i][ifname],false,true,false));
    doc.add(new Field("lname", dtable[i][ilname],false,true,false));
    doc.add(new Field("email", dtable[i][iemail],false,true,false));
    doc.add(new Field("hiredt",dtable[i][ihiredt],false,true,false));
    // on this one, tokenize the title so that it can be
    // text content searched.
    doc.add(new Field("title",  dtable[i][ititle],false,true,true));
    writer.addDocument(doc);
   }
   writer.close();

        } catch (Exception e) {
            e.printStackTrace();
        }

  System.out.println("Started at "+start.toString());
        Date stop = new Date();
  System.out.println("Stopped at "+stop.toString());
    }
}

----- Original Message -----
From: Ian Lea <ia...@blackwell.co.uk>
To: Lucene Users List <lu...@jakarta.apache.org>
Sent: Monday, November 19, 2001 2:40 AM
Subject: Re: Can't locate field


> Are you using the same Analyzer (SimpleAnalyzer) when adding
> data to the index?  You don't show us the full indexing code.
>
>
>
> --
> Ian.
> ian.lea@blackwell.co.uk
>
>
> "Cecil, Paula New" wrote:
> >
> > This is my first message to this list.  I have successfully created
several little tests of the Lucene api.  In my last test, I am trying to
index "data records".  Only the "primary key" needs to be stored (and I did
not even index this field).  For the others I want to index, but neither
store or tokenize (I want the the entire text string to be the "term").
> >
> > So my index code looks like:
> >     doc.add(Field.UnIndexed("userid", dtable[i][iuserid]));
> >     doc.add(new Field("charge",dtable[i][icharge],false,true,false));
> >     doc.add(new Field("fname", dtable[i][ifname],false,true,false));
> >     doc.add(new Field("lname", dtable[i][ilname],false,true,false));
> >     doc.add(new Field("email", dtable[i][iemail],false,true,false));
> >     doc.add(new Field("hiredt",dtable[i][ihiredt],false,true,false));
> >     doc.add(new Field("title",  dtable[i][ititle],false,true,true));
> >
> > The last field I tokenize and it seems to work ok.  The others never
return hits.
> >
> > My search code is below.  Essentially I am trying to search like this:
> > java ./index lname smith
> >
> > Which should find everyone with a last name of "smith".  But no hits are
returned.
> > What am I doing wrong?
> >
> > Thanks
> >
> > public class Search {
> >   public static void main(String[] args) throws Exception {
> >  Date start = new Date();
> >     String indexPath = args[0], qfield = args[1], queryString = args[2];
> >
> >     Searcher searcher = new IndexSearcher(indexPath);
> >     Query query = QueryParser.parse(queryString, qfield,
> >                               new SimpleAnalyzer());
> >     Hits hits = searcher.search(query);
> >
> >  Date stop = new Date();
> >  if ( args.length > 2 ) {
> >   for (int i=0; i<hits.length(); i++) {
> >     System.out.println(
> >      "Userid "+hits.doc(i).get("userid") +
> >      "; Score: " +
> >      hits.score(i));
> >   };
> >  }
> >     System.out.println("\nNumber of hits: "+ hits.length());
> >     long totalms = stop.getTime() - start.getTime();
> >  System.out.println(totalms + " total milliseconds");
> >   }
> > }
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>
>



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Can't locate field

Posted by Ian Lea <ia...@blackwell.co.uk>.
Are you using the same Analyzer (SimpleAnalyzer) when adding
data to the index?  You don't show us the full indexing code.



--
Ian.
ian.lea@blackwell.co.uk


"Cecil, Paula New" wrote:
> 
> This is my first message to this list.  I have successfully created several little tests of the Lucene api.  In my last test, I am trying to index "data records".  Only the "primary key" needs to be stored (and I did not even index this field).  For the others I want to index, but neither store or tokenize (I want the the entire text string to be the "term").
> 
> So my index code looks like:
>     doc.add(Field.UnIndexed("userid", dtable[i][iuserid]));
>     doc.add(new Field("charge",dtable[i][icharge],false,true,false));
>     doc.add(new Field("fname", dtable[i][ifname],false,true,false));
>     doc.add(new Field("lname", dtable[i][ilname],false,true,false));
>     doc.add(new Field("email", dtable[i][iemail],false,true,false));
>     doc.add(new Field("hiredt",dtable[i][ihiredt],false,true,false));
>     doc.add(new Field("title",  dtable[i][ititle],false,true,true));
> 
> The last field I tokenize and it seems to work ok.  The others never return hits.
> 
> My search code is below.  Essentially I am trying to search like this:
> java ./index lname smith
> 
> Which should find everyone with a last name of "smith".  But no hits are returned.
> What am I doing wrong?
> 
> Thanks
> 
> public class Search {
>   public static void main(String[] args) throws Exception {
>  Date start = new Date();
>     String indexPath = args[0], qfield = args[1], queryString = args[2];
> 
>     Searcher searcher = new IndexSearcher(indexPath);
>     Query query = QueryParser.parse(queryString, qfield,
>                               new SimpleAnalyzer());
>     Hits hits = searcher.search(query);
> 
>  Date stop = new Date();
>  if ( args.length > 2 ) {
>   for (int i=0; i<hits.length(); i++) {
>     System.out.println(
>      "Userid "+hits.doc(i).get("userid") +
>      "; Score: " +
>      hits.score(i));
>   };
>  }
>     System.out.println("\nNumber of hits: "+ hits.length());
>     long totalms = stop.getTime() - start.getTime();
>  System.out.println(totalms + " total milliseconds");
>   }
> }

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>