You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@lucene.apache.org by Jan Peter Stotz <jp...@gmx.de> on 2008/01/19 12:52:34 UTC
Creating an alias for a field name?
Hi,
I would like to provide multiple field-names that are all mapped to the
same field in background (e.g. a long field-name and a short
field-name). Is there any mechanism for creating such field-aliases, may
be in the IndexWriter or an QueryParser?
Jan
---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org
Re: Creating an alias for a field name?
Posted by Jan Peter Stotz <jp...@gmx.de>.
Hi Erick,
thanks for your response.
> Not that I know of. I presume that you want this to reduct typing
> or some such. Your app could simply massage the query
> that was typed, doing the appropriate substitutions before
> parsing the query....
Well I found a much better solution which avoids "double parsing". I
created my own QueryParser by extending the existing. Then I identified
five methods to override:
getFieldQuery(String field,String queryText)
getFuzzyQuery(String field,String termStr, float minSimilarity)
getPrefixQuery(String field,String termStr)
getRangeQuery(String field,String part1, String part2, boolean inclusive)
getWildcardQuery(String field,String termStr)
In each of this methods I call my own method:
field = translateField(field);
before passing the values to it's super implementation.
And my translateField method uses a Hashtable for looking up field
aliases. It it finds an alias it returns it, otherwise the field is
returned without modification. Therefore I have my field aliases without
having to implement an own parser - thanks to the good OO-design of the
QueryParser class.
BTW: If someone wants to took onto the complete source just ask. I did
not want to attach/include them because of its size (most of the code
has been generated by Eclipse...)
Jan
---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org
Re: Creating an alias for a field name?
Posted by Erick Erickson <er...@gmail.com>.
Not that I know of. I presume that you want this to reduct typing
or some such. Your app could simply massage the query
that was typed, doing the appropriate substitutions before
parsing the query....
Erick
On Jan 19, 2008 6:52 AM, Jan Peter Stotz <jp...@gmx.de> wrote:
> Hi,
>
> I would like to provide multiple field-names that are all mapped to the
> same field in background (e.g. a long field-name and a short
> field-name). Is there any mechanism for creating such field-aliases, may
> be in the IndexWriter or an QueryParser?
>
> Jan
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>
>