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

    Default Query search for exact word

    Hello,

    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 =  SimpleFSDirectory.open(file);
                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);
                isearcher.search(query, 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"));
                    listOfSentences.add(hitDoc);
                }
    How can I make this happen?

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,332
    Rep Power
    25

    Default

    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
    Posts
    21
    Rep Power
    0

    Default

    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
  •