SourceForge.net Logo
Main Overview Wiki Issues Forum Build Fisheye

Welcome, Guest
Guest Settings
Help

Compass Support Forums » Compass » Compass Users

Thread: Compass 1.2.1 Sorting

This question is answered.


Permlink Replies: 28 - Pages: 2 [ 1 2 | Next ] - Last Post: Dec 14, 2011 7:25 PM Last Post By: anitas
vam

Posts: 259
Registered: 1/2/07
Compass 1.2.1 Sorting
Posted: Mar 17, 2008 3:16 PM
 
  Click to reply to this thread Reply
I have the following mapping on the title field:


    @SearchableProperty(name="title",index=Index.UN_TOKENIZED)
    public String getTitle() {
        return title;
    }
 
    public void setTitle(String title) {
        this.title = title;
    }


and I get the following exception:
java.lang.RuntimeException: there are more terms than documents in field "title", but it's impossible to sort on tokenized fields
        at org.apache.lucene.search.FieldCacheImpl$10.createValue(FieldCacheImpl.java:377)
        at org.apache.lucene.search.FieldCacheImpl$Cache.get(FieldCacheImpl.java:72)
        at org.apache.lucene.search.FieldCacheImpl.getStringIndex(FieldCacheImpl.java:350)
        at org.apache.lucene.search.FieldSortedHitQueue.comparatorString(FieldSortedHitQueue.java:266)
        at org.apache.lucene.search.FieldSortedHitQueue$1.createValue(FieldSortedHitQueue.java:182)
        at org.apache.lucene.search.FieldCacheImpl$Cache.get(FieldCacheImpl.java:72)
        at org.apache.lucene.search.FieldSortedHitQueue.getCachedComparator(FieldSortedHitQueue.java:155)
        at org.apache.lucene.search.FieldSortedHitQueue.<init>(FieldSortedHitQueue.java:56)
        at org.apache.lucene.search.TopFieldDocCollector.<init>(TopFieldDocCollector.java:41)
        at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:122)
        at org.apache.lucene.search.MultiSearcher.search(MultiSearcher.java:232)
        at org.apache.lucene.search.Hits.getMoreDocs(Hits.java:74)
        at org.apache.lucene.search.Hits.<init>(Hits.java:61)
        at org.apache.lucene.search.Searcher.search(Searcher.java:55)
        at org.compass.core.lucene.engine.transaction.ReadCommittedTransaction.findByQuery(ReadCommittedTransaction.java:432)
        at org.compass.core.lucene.engine.transaction.ReadCommittedTransaction.doFind(ReadCommittedTransaction.java:405)
        at org.compass.core.lucene.engine.transaction.AbstractTransaction.find(AbstractTransaction.java:91)
        at org.compass.core.lucene.engine.LuceneSearchEngine.find(LuceneSearchEngine.java:392)
        at org.compass.core.lucene.engine.LuceneSearchEngineQuery.hits(LuceneSearchEngineQuery.java:151)
        at org.compass.core.impl.DefaultCompassQuery.hits(DefaultCompassQuery.java:133)
        at com.sermo.foley.search.searcher.SearchServiceImpl.doPaging(SearchServiceImpl.java:184)
        at com.sermo.foley.search.searcher.SearchServiceImpl.search(SearchServiceImpl.java:86)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)


It looks like the field is TOKENIZED even when compass is told not to do it.
Shay Banon

Posts: 4,028
Registered: 9/6/05
Re: Compass 1.2.1 Sorting
Posted: Mar 17, 2008 4:23 PM   in response to: vam in response to: vam
 
  Click to reply to this thread Reply
Two questions: Can you post your search code with sorting, and do you have another field that is mapped to title?
vam

Posts: 259
Registered: 1/2/07
Re: Compass 1.2.1 Sorting
Posted: Mar 17, 2008 10:34 PM   in response to: Shay Banon in response to: Shay Banon
 
  Click to reply to this thread Reply
Shay,

The class is just Bean with Lucene annotations and no cascading and no references to other objects. The name of the field is not repeated. The only thing I can think of is that the title appears in two ROOT entities.

here is the search code:
@Entity
@Table(name = "article")
@DiscriminatorValue("NewsArticle")
@DiscriminatorColumn(name = "type", discriminatorType = DiscriminatorType.STRING)
@XmlAccessorType(XmlAccessType.PUBLIC_MEMBER)
@XmlType(name = "ArticleDoc")
@XmlRootElement(name="ArticleDoc")
@Searchable(alias="article")
public class NewsArticleDoc extends BaseEntity{
    private String title;        
    private String content;        
    private String body;    
    private String authors;
    private Date created; 
    private Date published;
    private String pubName;
 
    @SearchableId(name="articleId", excludeFromAll = true)
    public int getArticleId() {
        return super.getId();
    }
 
    public void setArticleId(int articleId) {
        super.setId(articleId);
    }
 
    @SearchableProperty(name="title",index=Index.UN_TOKENIZED)
    public String getTitle() {
        return title;
    }
 
    public void setTitle(String title) {
        this.title = title;
    }
 
    @SearchableProperty(name="abstract")
    public String getContent() {
        return content;
    }
 
    public void setContent(String content) {
        this.content = content;
    }
 
    @SearchableProperty(name="body")
    public String getBody() {
        return body;
    }
 
    public void setBody(String body) {
        this.body = body;
    }
 
    @SearchableProperty(name="authors")    
    public String getAuthors() {
        return authors;
    }
 
    public void setAuthors(String authors) {
        this.authors = authors;
    }
 
    @SearchableProperty(name="created",format="yyyyMMddHHmmss", excludeFromAll=true,index=Index.UN_TOKENIZED)
    public Date getCreated() {
        return created;
    }
 
    public void setCreated(Date created) {
        this.created = created;
    }
    
    @SearchableProperty(name="published",format="yyyyMMddHHmmss", excludeFromAll=true, index=Index.UN_TOKENIZED)
    public Date getPublished() {
        return published;
    }
 
    public void setPublished(Date published) {
        this.published = published;
    }
    
 
    @SearchableProperty(name="pubName",index=Index.UN_TOKENIZED)     
    public String getPubName() {
        return pubName;
    }
 
    public void setPubName(String pubName) {
        this.pubName = pubName;
    }
}
 


 private CompassQuery buildSearchQuery(CompassQueryBuilder queryBuilder, SearchParams params) {
        //add query string
        CompassQueryBuilder.CompassBooleanQueryBuilder query = queryBuilder.bool();
        String queryString = SearchHelper.parseQueryForSearch(params.getQuery());
        CompassQuery q = queryBuilder.queryString(queryString).toQuery();
 
        query.addMust(queryBuilder.alias(params.getAlias()));
        query.addMust(q);
 
        query.addShould(queryBuilder.term("dateBoost", SearchHelper.BOOST_VALUE));
        q = query.toQuery();
 
        //add sorting
        
        CompassQuery.SortDirection order;       
        if (params.getSortField()==null || params.getSortField().equals("relevance")) {
            order = (params.isAsc())?CompassQuery.SortDirection.REVERSE:CompassQuery.SortDirection.AUTO;
            q.addSort(CompassQuery.SortImplicitType.SCORE, order);
        }
        else {
            order = (params.isAsc())?CompassQuery.SortDirection.AUTO:CompassQuery.SortDirection.REVERSE;
            q.addSort(params.getSortField(), CompassQuery.SortPropertyType.STRING, order);
            //q.addSort(CompassQuery.SortImplicitType.SCORE);
        }
        return q;
    }
 
 private void doPaging(CompassQuery q, SearchParams params, SearchResult result) {        
        //execute the query
        CompassHits hits = q.hits();
        result.setCount(hits.getLength());
        logger.info("query results: " + hits.length());
       
        //do results paging
        int len = Math.min(hits.length(), (params.getStart()+params.getLength()));
        int start = params.getStart();
        
        for (int i = start; i < len; i++) {
            CompassHit hit = hits.hit(i);
            Integer id = Integer.decode(hit.getResource().getId());
 
            //create a result entry with the meta-data
            ResultEntry e = new ResultEntry(id, hit.getScore());
            if (params.isHighlight()) {
                CompassHighlighter ch = hits.highlighter(i);
                ch.setHighlighter("default");
 
                e.setContent(ch.fragment("content"));
                e.setCategory(ch.fragment("category"));
                e.setTitle(ch.fragment("title"));
                e.setUsername(ch.fragment("userName"));
                
                //we need to respect comment separators while highlighting
                e.setComment(getFragment(ch.fragment("comments")));                
            }
            result.addEntry(e);
        }
    }
vam

Posts: 259
Registered: 1/2/07
Re: Compass 1.2.1 Sorting
Posted: Mar 18, 2008 9:57 AM   in response to: vam in response to: vam
 
  Click to reply to this thread Reply
Shay,

This seems to be a problem with compass and it might be do to caching. The field appears int two root searchable classes. Indexing is fine, the entry is untokenized but during search the problem appears.

For now, I've change the name of the property which fixed the issue for this particular case.
Shay Banon

Posts: 4,028
Registered: 9/6/05
Re: Compass 1.2.1 Sorting
Posted: Mar 18, 2008 10:06 AM   in response to: vam in response to: vam
 
  Click to reply to this thread Reply
Do you mean you have another mapping for title? Did I understand it correctly.
vam

Posts: 259
Registered: 1/2/07
Re: Compass 1.2.1 Sorting
Posted: Mar 18, 2008 10:30 AM   in response to: Shay Banon in response to: Shay Banon
 
  Click to reply to this thread Reply
There is only one mapping for title on ArticleNews, so definitely something is wrong here. I have another title field on a unralated object, PostingDoc and I believe compass is getting mix-up.
Shay Banon

Posts: 4,028
Registered: 9/6/05
Re: Compass 1.2.1 Sorting
Posted: Mar 18, 2008 10:48 AM   in response to: vam in response to: vam
 
  Click to reply to this thread Reply
And in PostingDoc, is it untokenized there?
vam

Posts: 259
Registered: 1/2/07
Re: Compass 1.2.1 Sorting
Posted: Mar 18, 2008 11:23 AM   in response to: Shay Banon in response to: Shay Banon
 
  Click to reply to this thread Reply
This is "title" on my PostingDoc

code
@SearchableProperty(name="title", termVector=TermVector.WITH_POSITIONS_OFFSETS)
public String getTitle() {
return title;
}

public void setTitle(String title) {
this.title = title;
}
[/code/
Shay Banon

Posts: 4,028
Registered: 9/6/05
Re: Compass 1.2.1 Sorting
Posted: Mar 18, 2008 11:40 AM   in response to: vam in response to: vam
Correct
  Click to reply to this thread Reply
So basically, that is the problem. Lucene won't distinguish between the two. But, if you know that you only search on certain type, you can constrain your search to that type, then it should work (see CompassQuery#setTypes, or setAliases)
vam

Posts: 259
Registered: 1/2/07
Re: Compass 1.2.1 Sorting
Posted: Mar 18, 2008 1:18 PM   in response to: Shay Banon in response to: Shay Banon
 
  Click to reply to this thread Reply
Shay, that worked like magic. Basically I changed:

q.addMust(queryBuilder.alias(params.getAlias()));

with

q.setAliases(new String[]{params.getAlias()});

and it worked.

Thanks for your help
louisvuittonbox

Posts: 411
Registered: 8/23/11
Re: Compass 1.2.1 Sorting
Posted: Aug 23, 2011 10:05 PM   in response to: vam in response to: vam
 
  Click to reply to this thread Reply
Sports brand Nike (Nike) has announced the new 2010 summer footwear, including the nike air max, Tennis Classic, and Air Max 90 Current Torch three groups. nike shox which are yellow, orange, and blue color, with some bright colors there is a refreshing feeling. Tennis Classic with a white and green color, low-cut shoes suitable for summer wear. And with the nike air jordan of the latest technology Torch nike shoes uk Current Torch shoes are hit with the classic black and white color with the toe position with the Torch materials, mining forefoot nike air max 2011 Free technology coupled with the classic appearance , reflecting the retro and technology integration.
guge

Posts: 6
Registered: 9/7/11
Re: Compass 1.2.1 Sorting
Posted: Sep 7, 2011 9:30 PM   in response to: vam in response to: vam
 
  Click to reply to this thread Reply
helloyajun

Posts: 38
Registered: 9/22/11
UGG
Posted: Sep 22, 2011 1:43 AM   in response to: vam in response to: vam
 
  Click to reply to this thread Reply
Russian aerospace Coach Outlet soldier troops the spokesman says on 21th, a for use by the military satellite carries"the proton - M" carrier rocket to inshorely do obeisance the Coach Outlet section launch site to smoothly go up the sky in Kazakhstan before down on that day in the Moscow time. This spokesman says that the Coach Bags aerospace soldier's troops made use of the ground automation control equipments to carry on solid hour's monitor to this satellite that belongs to the Ministry of National Defense.According to the Coach Factory Outlet plan, the satellite separates with the rocket propeller after go up the sky more than 9 hours, entering the orbit of schedule to.The square of the Coach Purses did not explain the concrete use of this satellite. This time satellite goes up the sky to mean Russia starts recover the Coach Store blast-off of"proton" series carrier rocket.
fangcao

Posts: 92
Registered: 8/14/11
Re: Compass 1.2.1 Sorting
Posted: Sep 26, 2011 10:00 PM   in response to: vam in response to: vam
 
  Click to reply to this thread Reply
Wow!!!!! runescape powerleveling improves so quickly. I can’t believe!!!! Oh, Shit! Runescape Gold is so cheap. So easy get rs accounts and rs character .Hey, friend, this is not a scam. I have had a try. Really great!
sweet123

Posts: 211
Registered: 10/31/11
Re: Compass 1.2.1 Sorting
Posted: Oct 31, 2011 3:22 AM   in response to: vam in response to: vam
 
  Click to reply to this thread Reply
As one of the most famous brands Coach Factory Outlet and the representatives of fashion, Coach Outlet Store Online always goes in the top of fashion, never fall behind Coach Outlet Online Store. Look into the fashion world, you will find Coach Outlet Factory that there are so many newest products pushed out by Coach Handbags Outlet. Coach Store, the most support of Coach Factory Outlet Online once appeared had earned a lot of women's heart, even the famous actresses. All of these, they are our Prada Store, and I will cherish them in lifetime. Perhaps you don't know, in my heart, Air Yeezy Shoes are my sisters, in the daily life, I call Gucci Bags sisters, that is because Coach Oulet USA really are my sisters, when I have trouble, Coach Outlet Store Online always help me to deal with it, when I am wronged, Louis Vuitton Outlet Factory will more angry than me to condemn others, Yes, Louis Vuitton Outlet Store Online are my sisters, we are envy Coach Handbags.Because I have Nike Dunk Shoes, my dear sisters!
Legend
Guru: 2001 + pts
Expert: 501 - 2000 pts
Super-star: 101 - 500 pts
Assistant: 51 - 100 pts
Participant: 0 - 50 pts
Helpful Answer (5 pts)
Correct Answer (10 pts)

Point your RSS reader here for a feed of the latest messages in all forums