You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by "Maddy.Jsh" <ma...@gmail.com> on 2010/10/05 08:39:54 UTC

Begins with and ends with word

Hi,

I have 2 documents with following values.
Doc1
Subject: Weekly transport

Doc2
Subject: Week report on transportation

I need to search documents in 4 formats

1. Begins with “week”
     It should return documents which has "week" as first word, i.e. doc1

2. Begins with “week*”
     It should return documents which has "week" or its derivatives(weekly,
weeks) as first word, i.e. doc1 and doc2

3. Ends with “transport”
     It should return documents which end with word "transport", i.e. doc1

4. Ends with “transport*”
     It should return documents which end with word "transport" or its
derivatives(transportation, transporter, etc), i.e. doc1 and doc2 


Please let me know if there are any solutions.

Thanks.






-- 
View this message in context: http://lucene.472066.n3.nabble.com/Begins-with-and-ends-with-word-tp1634376p1634376.html
Sent from the Solr - User mailing list archive at Nabble.com.

Re: Begins with and ends with word

Posted by Michael McCandless <lu...@mikemccandless.com>.
I think this is possible, at the Lucene level.

You want a mix of PrefixQuery and SpanFirstQuery (hmm we don't have a
SpanLastQuery...).

I believe you can do this by creating a PrefixQuery, and then
customizing the rewrite method to create a BQ (SHOULD clauses) of
SpanFirstQuery, instead of TermQuery that's used by default.
Alternatively, you could enum all matching terms and then build the BQ
yourself... but you'll have to be careful when too many terms match
the prefix.

Mike

On Tue, Oct 5, 2010 at 2:39 AM, Maddy.Jsh <ma...@gmail.com> wrote:
>
> Hi,
>
> I have 2 documents with following values.
> Doc1
> Subject: Weekly transport
>
> Doc2
> Subject: Week report on transportation
>
> I need to search documents in 4 formats
>
> 1. Begins with “week”
>     It should return documents which has "week" as first word, i.e. doc1
>
> 2. Begins with “week*”
>     It should return documents which has "week" or its derivatives(weekly,
> weeks) as first word, i.e. doc1 and doc2
>
> 3. Ends with “transport”
>     It should return documents which end with word "transport", i.e. doc1
>
> 4. Ends with “transport*”
>     It should return documents which end with word "transport" or its
> derivatives(transportation, transporter, etc), i.e. doc1 and doc2
>
>
> Please let me know if there are any solutions.
>
> Thanks.
>
>
>
>
>
>
> --
> View this message in context: http://lucene.472066.n3.nabble.com/Begins-with-and-ends-with-word-tp1634376p1634376.html
> Sent from the Solr - User mailing list archive at Nabble.com.
>

Re: Begins with and ends with word

Posted by Jan Høydahl / Cominvent <ja...@cominvent.com>.
There is a ticket for this request: https://issues.apache.org/jira/browse/SOLR-1980

--
Jan Høydahl, search solution architect
Cominvent AS - www.cominvent.com

On 5. okt. 2010, at 08.39, Maddy.Jsh wrote:

> 
> Hi,
> 
> I have 2 documents with following values.
> Doc1
> Subject: Weekly transport
> 
> Doc2
> Subject: Week report on transportation
> 
> I need to search documents in 4 formats
> 
> 1. Begins with “week”
>     It should return documents which has "week" as first word, i.e. doc1
> 
> 2. Begins with “week*”
>     It should return documents which has "week" or its derivatives(weekly,
> weeks) as first word, i.e. doc1 and doc2
> 
> 3. Ends with “transport”
>     It should return documents which end with word "transport", i.e. doc1
> 
> 4. Ends with “transport*”
>     It should return documents which end with word "transport" or its
> derivatives(transportation, transporter, etc), i.e. doc1 and doc2 
> 
> 
> Please let me know if there are any solutions.
> 
> Thanks.
> 
> 
> 
> 
> 
> 
> -- 
> View this message in context: http://lucene.472066.n3.nabble.com/Begins-with-and-ends-with-word-tp1634376p1634376.html
> Sent from the Solr - User mailing list archive at Nabble.com.