Results 1 to 3 of 3
  1. #1
    peliukasss is offline Member
    Join Date
    Feb 2010
    Rep Power

    Default Query search for exact word


    Can anyone tell me this:
    How can I search a word and only specified word.
    For e.g: I have a word house. And I need to search only for it, not for for e.g houses.

    My search looks like this:

    Java Code:
                analyzer = new StandardAnalyzer(Version.LUCENE_30);
                File file = new File(indexDirectory);
                directory =;
                Searcher isearcher = new IndexSearcher(directory, true);
                QueryParser parser = new QueryParser(Version.LUCENE_30, "fieldname", analyzer);
                Query query = parser.parse(word);
                TopScoreDocCollector collector = TopScoreDocCollector.create(500, true);
      , collector);
                System.out.println("Hits = " + collector.getTotalHits());
                ScoreDoc[] hits = collector.topDocs().scoreDocs;
                Document hitDoc = null;
                for (int i = 0; i < hits.length; i++) {
                    hitDoc = isearcher.doc(hits[i].doc);
                    //  System.out.println(hitDoc.get("fieldname"));
    How can I make this happen?

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Eastern Florida
    Rep Power


    Is the word/string you are looking for in another string?
    Do you have a definition for what characters delimit a word?
    Regular expressions may do the job.

    No idea if this makes any sense in the Lucene thread, which I just noticed.

  3. #3
    peliukasss is offline Member
    Join Date
    Feb 2010
    Rep Power


    Yes the word is in a String line which is indexed as Lucene Field.

    So when I search the word for e.g house the results display me other fields where the word for e.g houses is. But I need only those fields where word house is.

Similar Threads

  1. Replies: 1
    Last Post: 01-21-2010, 12:40 PM
  2. Java Search Query Question
    By tek0011 in forum New To Java
    Replies: 2
    Last Post: 12-01-2009, 11:37 PM
  3. Replies: 2
    Last Post: 11-11-2009, 05:56 AM
  4. minimum word length in search problematic
    By jocassid in forum Suggestions & Feedback
    Replies: 3
    Last Post: 07-01-2008, 04:24 AM
  5. Replies: 1
    Last Post: 05-19-2007, 12:03 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts