Lucene search example

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • amitbagaria
    New Member
    • Feb 2008
    • 4

    Lucene search example

    Hello,

    i'm trying to compile "InMemoryExampl e.java" of lucene search
    but i'm getting these errors!!

    "C:\Java\ant_ho me>javac InMemoryExample .java
    InMemoryExample .java:82: cannot find symbol
    symbol : method UnIndexed(java. lang.String,jav a.lang.String)
    location: class org.apache.luce ne.document.Fie ld
    doc.add(Field.U nIndexed("title ", title));
    ^
    InMemoryExample .java:89: cannot find symbol
    symbol : method Text(java.lang. String,java.io. StringReader)
    location: class org.apache.luce ne.document.Fie ld
    doc.add(Field.T ext("content", new StringReader(co ntent)));
    ^
    InMemoryExample .java:101: parse(java.lang .String) in org.apache.luce ne.queryPars
    er.QueryParser cannot be applied to (java.lang.Stri ng,java.lang.St ring,org.apach
    e.lucene.analys is.standard.Sta ndardAnalyzer)
    Query query = QueryParser.par se(queryString, "content", new StandardAnal
    yzer());"


    i have set related classpath for lucene packages, but still i'm getting these errors!

    can any one help me?

    Thanks,
    Amit B.
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by amitbagaria
    Hello,

    i'm trying to compile "InMemoryExampl e.java" of lucene search
    but i'm getting these errors!!

    "C:\Java\ant_ho me>javac InMemoryExample .java
    InMemoryExample .java:82: cannot find symbol
    symbol : method UnIndexed(java. lang.String,jav a.lang.String)
    location: class org.apache.luce ne.document.Fie ld
    doc.add(Field.U nIndexed("title ", title));
    ^
    InMemoryExample .java:89: cannot find symbol
    symbol : method Text(java.lang. String,java.io. StringReader)
    location: class org.apache.luce ne.document.Fie ld
    doc.add(Field.T ext("content", new StringReader(co ntent)));
    ^
    InMemoryExample .java:101: parse(java.lang .String) in org.apache.luce ne.queryPars
    er.QueryParser cannot be applied to (java.lang.Stri ng,java.lang.St ring,org.apach
    e.lucene.analys is.standard.Sta ndardAnalyzer)
    Query query = QueryParser.par se(queryString, "content", new StandardAnal
    yzer());"


    i have set related classpath for lucene packages, but still i'm getting these errors!

    can any one help me?

    Thanks,
    Amit B.
    It's not a classpath issue(It would have reported that it cannot find symbol class).
    For the first two errors, well, here's the spec for the Field class. As you can see those two methods are not there.
    The last error message is trying hard to explain itself. Read it again.

    Comment

    • cordeo
      New Member
      • Jul 2008
      • 16

      #3
      Originally posted by r035198x
      For the first two errors, ... As you can see those two methods are not there.
      The last error message is trying hard to explain itself. Read it again.
      That's a nice analysis of the problems, but not very helpful to a beginner. The real answer:
      Your lucene jar library is newer than the one InMemoryExample was written for. Lucene changed its API. InMemoryExample is based on an older version of the API of Lucene. Changes:
      1. doc.add(Field.U nIndexed("title ", title));
      New code:
      doc.add(new Field("title", title, Field.Store.COM PRESS, Field.Index.NO) );
      or:
      doc.add(new Field("title", title, Field.Store.YES , Field.Index.NO) );

      Changes: static method UnIndexed is removed and Storage Indexing options are more explicit.

      2. doc.add(Field.T ext("content", new StringReader(co ntent)));
      New code:
      doc.add(new Field("content" , content, Field.Store.NO, Field.Index.TOK ENIZED));

      and

      3. Query query = QueryParser.par se(queryString, "content", new StandardAnalyze r());"
      New code:
      Query query = new QueryParser("co ntent", new StandardAnalyze r()).parse(quer yString);
      or:
      QueryParser queryParser = new QueryParser("co ntent", new StandardAnalyze r());
      Query query = queryParser.par se(queryString) ;

      Change: parse is no longer static and 2 of the 3 parameters are moved to the constructor (allows for reuse).

      Some backgrounds:
      http://darksleep.com/lucene/ tells some things about the old API:
      Field.UnIndexed (String name, String value) = Don't index, Only store
      Field.Text(Stri ng name, Reader value) = Tokenized index, don't store

      In general, too excessive use of the factory pattern has been removed from the API.
      Last edited by cordeo; Jul 22 '08, 07:31 PM. Reason: More backgrounds

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Originally posted by cordeo
        That's a nice analysis of the problems, but not very helpful to a beginner. The real answer:
        ...
        You've certainly given more detailed and yes, more helpful information.
        Thanks. Teamwork in responding to threads is the key to providing complete solutions. Hope to see you around more often.

        Comment

        Working...