DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=30977>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=30977

"and" should be used in query syntax, not "AND"

[EMAIL PROTECTED] changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|WORKSFORME                  |



------- Additional Comments From [EMAIL PROTECTED]  2004-09-01 21:12 -------
Attached is three methods in several Java classes, getDocument, getQueryString 
and getHits.

Please refer method getDocument for document format I used to save Lucene 
documet.

I used getQueryString() to produce Lucene search query string, and use getHits 
to get search result.

In the following code, it will return none if I use "AND" but return what I 
expected if I use "and".


  public Document getDocument(HttpServletRequest request) {
    Document document=new Document();
    document.add(Field.Keyword("type", LuceneDoc.STOCK_ITEM));
    document.add(Field.Keyword("stockItemCode", getStockItemCode()));
    document.add(Field.Text("shortDesc", shortDesc));
    document.add(Field.Text("longDesc", longDesc));

    return document;
  }


  /**
   * LuceneDoc.STOCK_ITEM=stockItem
   * default field=shortDesc
   */
  public String getQueryString() {
    String quotedSearchQuery="("+searchString+")";
    return "type:"+LuceneDoc.STOCK_ITEM+" and ("+
        quotedSearchQuery+" or longDesc:"+quotedSearchQuery+")";
  }

  //queryField has been set to "shortDesc"  
  protected Page getHits(int start, int count) {
    try {
      QueryParser qp=new QueryParser(queryField, new StandardAnalyzer());
      qp.setOperator(QueryParser.DEFAULT_OPERATOR_OR);
      Query q=qp.parse(queryString);

      Searcher searcher=getSearcher(indexPath);
      Hits hits=searcher.search(q);

      Collection documents=new ArrayList();
      for (int i=start; i<hits.length() && i<(start+count); i++) {
        documents.add(hits.doc(i));
      }

      searcher.close();

      return new Page(documents, start, count, hits.length());
    } catch (ParseException ex) {
      throw new IndexException(ex.getMessage());
    } catch (IOException ex) {
      throw new IndexException(ex.getMessage());
    }
  }

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to