lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mike Miller" <Mike.Mil...@jda.com>
Subject Problem searching Field.Keyword field
Date Tue, 08 Feb 2005 13:54:57 GMT
First let me say - Awesome tool!  Almost too easy to be true, but with
that being said....
 
Hi,  I have read several articles and postings that indicate that the
Field.Keyword field should be searchable but it's not working for me,
until I change to Field.Text.  Parts of the index and search code are
included below - mostly lifted from articles,etc, including Erik Hatches
article on java.net.   I created a small KnowledgeBase web application
that contains a category field, which I want to be searchable.
Searching using a query string of category:Doc* or
category:Documentation does not find a hit unless I change the code to
add the category to the index as a Field.Text instead of Field.Keyword.
The field value is out there:   I have verified this using the TermEnum
to list the term values for field category and Documentation is in the
list of values.  
 
The intention is to provide a 'Advanced Search' page that allows the
user to search specific fields, like category, title and author instead
of always using the 'all' field.  
 
What am I doing wrong???     Thanks in advance.
 
Index code:
 
public boolean index(ArticleFormBean article) throws IOException {
  IndexWriter writer = new IndexWriter(indexDir, new StandardAnalyzer(),
false);
 
         Document doc = new Document();
         doc.add(Field.UnStored("content", article.getContent()));
        doc.add(Field.Text("title", article.getTitle()));
        doc.add(Field.Text("author", article.getAuthor()));
        doc.add(Field.UnIndexed("articleId",
String.valueOf(article.getArticleId())));
        doc.add(Field.Keyword("createdDate", article.getCreateDate()));
        doc.add(Field.Keyword("modDate", article.getModDate()));
        doc.add(Field.Keyword("category", article.getCategory()));

        // create an 'all' field
        StringBuffer sb = new StringBuffer(4000);
        sb.append(article.getTitle()).append("
").append(article.getAuthor()).append(" ");
        sb.append(article.getContent()).append("
").append(article.getCategory());
        doc.add(Field.UnStored("all", sb.toString()));
        
        writer.addDocument(doc);
        writer.optimize();
        writer.close();
        
        return false;
 }
 
Search code:
            File indexDir = new File("c:/dev/java/kb/index");
            Directory fsDir = FSDirectory.getDirectory(indexDir, false);
            IndexSearcher is = new IndexSearcher(fsDir);
            Query query = QueryParser.parse(q, "all", new
StandardAnalyzer());
            Hits hits = is.search(query);
            

 
Mike Miller
JDA Software Group, Inc.
7501 Ester's Blvd, Suite 100
Irving, Texas 75063
 

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message