FAQ
Hi,

I have a query regarding the sorting techniques in the lucene i.e
if i apply the sort method to the search results, lucene is sorting the
results by, without ignoring case, so, how to apply the sort technique that
it should sort by ignoring case

i.e :
if the results value are : {ACB, abc, adc, Aad},
After sorting the results by lucene : {Aad, ACB, abc, adc} [here the lucene
is taking uppercase words first to sort the results then lowercase],
but i need to get the results in this order : {Aad, abc, ACB, adc}

so how to sort the results by ignoring case

here is my code :
String queryComplex = "110_a_t:a* 110_a_t:A*";
SortField sortField = new SortField("110_a_t", SortField.STRING);
Sort sort = new Sort(sortField);
QueryParser queryParser=new QueryParser("",new StandardAnalyzer());
queryParser.setLowercaseExpandedTerms(false);
Query query = queryParser.parse(queryComplex);
org.apache.lucene.search.Hits
catalogueHits=search.indexSearcher.search(query, sort);
--
View this message in context: http://www.nabble.com/how-to-sort-the-result-by-ignoring-case-in-lucene-tp20615647p20615647.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

Search Discussions

  • Ganesh at Nov 21, 2008 at 6:07 am
    You need to write your own sort comparator
    SortField(String field, SortComparatorSource comparator)

    Regards
    Ganesh

    ----- Original Message -----
    From: "naveen.quill" <naveen.verus@gmail.com>
    To: <java-user@lucene.apache.org>
    Sent: Friday, November 21, 2008 11:27 AM
    Subject: how to sort the result by ignoring case in lucene

    Hi,

    I have a query regarding the sorting techniques in the lucene i.e
    if i apply the sort method to the search results, lucene is sorting the
    results by, without ignoring case, so, how to apply the sort technique
    that
    it should sort by ignoring case

    i.e :
    if the results value are : {ACB, abc, adc, Aad},
    After sorting the results by lucene : {Aad, ACB, abc, adc} [here the
    lucene
    is taking uppercase words first to sort the results then lowercase],
    but i need to get the results in this order : {Aad, abc, ACB, adc}

    so how to sort the results by ignoring case

    here is my code :
    String queryComplex = "110_a_t:a* 110_a_t:A*";
    SortField sortField = new SortField("110_a_t", SortField.STRING);
    Sort sort = new Sort(sortField);
    QueryParser queryParser=new QueryParser("",new StandardAnalyzer());
    queryParser.setLowercaseExpandedTerms(false);
    Query query = queryParser.parse(queryComplex);
    org.apache.lucene.search.Hits
    catalogueHits=search.indexSearcher.search(query, sort);
    --
    View this message in context:
    http://www.nabble.com/how-to-sort-the-result-by-ignoring-case-in-lucene-tp20615647p20615647.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
    Send instant messages to your online friends http://in.messenger.yahoo.com

    ---------------------------------------------------------------------
    To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
    For additional commands, e-mail: java-user-help@lucene.apache.org
  • Naveen.a at Nov 21, 2008 at 6:31 am
    Hi Ganesh,

    I have already tried my own comparator, below is my code :

    SortComparator comparator = new SortComparator() {
    @Override
    protected Comparable getComparable(String arg0) {
    final String str = arg0;
    Comparable comparable = new Comparable() {
    @Override
    public int compareTo(Object o) {
    System.out.println("obj = "+o.getClass()+",
    str = "+str);
    return
    o.toString().compareToIgnoreCase(str);
    }
    };
    return comparable;
    }
    };
    SortField sortField = new SortField("110_a_t", comparator);
    Sort sort = new Sort(sortField);
    org.apache.lucene.search.Hits
    catalogueHits=search.indexSearcher.search(query, sort);
    -------------------------------------------------
    here the lucene is passing the present class
    (org.verus.ngl.lucene.search.NGLSearch$1$1) object to compareTo method, but
    it is not a term to compare with anather term
    so, how to implement the SortComparator, where should i change the code for
    my comparator

    Output :
    obj = class org.verus.ngl.lucene.search.NGLSearch$1$1, str = Adalf Hitler
    obj = class org.verus.ngl.lucene.search.NGLSearch$1$1, str = Adalf Hitler
    obj = class org.verus.ngl.lucene.search.NGLSearch$1$1, str = agdfgdgdfg
    obj = class org.verus.ngl.lucene.search.NGLSearch$1$1, str = agdfgdgdfg
    obj = class org.verus.ngl.lucene.search.NGLSearch$1$1, str = afhuhruhgjr
    obj = class org.verus.ngl.lucene.search.NGLSearch$1$1, str = afhuhruhgjr
    obj = class org.verus.ngl.lucene.search.NGLSearch$1$1, str = afsfdsgsd
    obj = class org.verus.ngl.lucene.search.NGLSearch$1$1, str = afsfdsgsd
    obj = class org.verus.ngl.lucene.search.NGLSearch$1$1, str = adsadsd
    Results are :
    id = 134, docId = 105
    id = 135, docId = 106
    id = 102, docId = 73
    id = 100, docId = 71
    id = 101, docId = 72
    id = 122, docId = 93
    id = 127, docId = 98
    id = 132, docId = 103
    id = 143, docId = 114



    Ganesh - yahoo wrote:
    You need to write your own sort comparator
    SortField(String field, SortComparatorSource comparator)

    Regards
    Ganesh

    ----- Original Message -----
    From: "naveen.quill" <naveen.verus@gmail.com>
    To: <java-user@lucene.apache.org>
    Sent: Friday, November 21, 2008 11:27 AM
    Subject: how to sort the result by ignoring case in lucene

    Hi,

    I have a query regarding the sorting techniques in the lucene i.e
    if i apply the sort method to the search results, lucene is sorting the
    results by, without ignoring case, so, how to apply the sort technique
    that
    it should sort by ignoring case

    i.e :
    if the results value are : {ACB, abc, adc, Aad},
    After sorting the results by lucene : {Aad, ACB, abc, adc} [here the
    lucene
    is taking uppercase words first to sort the results then lowercase],
    but i need to get the results in this order : {Aad, abc, ACB, adc}

    so how to sort the results by ignoring case

    here is my code :
    String queryComplex = "110_a_t:a* 110_a_t:A*";
    SortField sortField = new SortField("110_a_t", SortField.STRING);
    Sort sort = new Sort(sortField);
    QueryParser queryParser=new QueryParser("",new StandardAnalyzer());
    queryParser.setLowercaseExpandedTerms(false);
    Query query = queryParser.parse(queryComplex);
    org.apache.lucene.search.Hits
    catalogueHits=search.indexSearcher.search(query, sort);
    --
    View this message in context:
    http://www.nabble.com/how-to-sort-the-result-by-ignoring-case-in-lucene-tp20615647p20615647.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
    Send instant messages to your online friends http://in.messenger.yahoo.com

    ---------------------------------------------------------------------
    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/how-to-sort-the-result-by-ignoring-case-in-lucene-tp20615647p20615846.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
  • Chris Hostetter at Nov 25, 2008 at 12:40 am
    : You need to write your own sort comparator
    : SortField(String field, SortComparatorSource comparator)

    A much simpler approach is to index a lowercase version of the field.
    since fields used for sorting are typically copies of other existing
    fields anyway because they can't be tokenized, there's not much additional
    overhead.



    -Hoss


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

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupjava-user @
categorieslucene
postedNov 21, '08 at 5:57a
activeNov 25, '08 at 12:40a
posts4
users3
websitelucene.apache.org

People

Translate

site design / logo © 2022 Grokbase