lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Huntsman84 <tpgarci...@gmail.com>
Subject Re: Searching for partial matches
Date Mon, 04 May 2009 15:21:37 GMT

Hi

I've tryed this with MultiPhraseQuery, but it always returns me all
documents of the index, no matter what expression I use. 

I've read that adding a set of terms wich their values are all the entered
query (e.g. "str"), the search works as the symbol "*" (e.g. "str*"), so I
tryed that.

My code is like this:

// prompt the user
System.out.println("Enter query: ");

String line = in.readLine(); //if I put "str", I want all matches like
"string", "strong", "astray"....

line = line.trim();
	      
//I thought this would be ok...
MultiPhraseQuery mpquery = new MultiPhraseQuery();
TermEnum te = reader.terms(new Term("contents",line));

/*Home-made conversion from TermEnum to Term[]... I get just 200 matches, I
don't want my
   machine busy...*/
Term[] terms = new Term[200];
int j=0;
	      
while(te.next() && j<200){
    terms[j] = te.term();
    j++;
}
	      
mpquery.add(terms);
	      
Query query = parser.parse(line);
System.out.println("Searching for: " + query.toString(field));

Date start = new Date();

Hits hits = searcher.search(mpquery);
for(int k = 0; k<100; k++){
    //when I print the results of the search, none of the values match with
the query...
    System.out.println(hits.doc(k).getField("contents").stringValue());
}



Ian Lea wrote:
> 
> Hi
> 
> 
> This is possible.  There is an entry on wildcards in the FAQ.  See
> also RegexQuery and search the mailing lists for ngrams.
> 
> Depending on your setup and requirements you may need to be aware of
> the performance implications of wild card searching, particularly
> leading wildcards as will be required for the example you give.  See
> the FAQ and javadocs for WildcardQuery.
> 
> 
> --
> Ian.
> 
> On Thu, Apr 30, 2009 at 11:46 AM, Huntsman84 <tpgarcia84@gmail.com> wrote:
>>
>> Hello,
>>
>>
>>
>> I am new to Lucene, and I don't know if it is possible to obtain results
>> providing part of the keyword.
>>
>>
>>
>> For example, if I try to search "in", it should return all matches with
>> "string", "meaning", "trinity"...
>>
>>
>>
>> Am I expecting too much?
>>
>>
>>
>> Thank you so much!
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Searching-for-partial-matches-tp23313810p23370618.html
Sent from the Lucene - Java Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Mime
View raw message