`
mxsfengg
  • 浏览: 206052 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

solr 排序的限制。

    博客分类:
  • java
阅读更多

 

 

there are more terms than documents in field "attr_quotes", but it's impossible to sort on tokenized fields
 2010-06-10 16:01:43 [main] [org.apache.solr.core.SolrCore]-[ERROR] java.lang.RuntimeException: there are more terms than documents in field "attr_quotes", but it's impossible to sort on tokenized fields
 at org.apache.lucene.search.FieldCacheImpl$StringIndexCache.createValue(FieldCacheImpl.java:706)
 at org.apache.lucene.search.FieldCacheImpl$Cache.get(FieldCacheImpl.java:208)
 at org.apache.lucen
 attr_quotes asc

  贴下引发异常的代码。由此证明  分词的field和 多值的field不能排序的。

 

  protected Object createValue(IndexReader reader, Entry entryKey)
        throws IOException {
      String field = StringHelper.intern(entryKey.field);
      final int[] retArray = new int[reader.maxDoc()];
      String[] mterms = new String[reader.maxDoc()+1];
      TermDocs termDocs = reader.termDocs();
      TermEnum termEnum = reader.terms (new Term (field));
      int t = 0;  // current term number

      // an entry for documents that have no terms in this field
      // should a document with no terms be at top or bottom?
      // this puts them at the top - if it is changed, FieldDocSortedHitQueue
      // needs to change as well.
      mterms[t++] = null;

      try {
        do {
          Term term = termEnum.term();
          if (term==null || term.field() != field) break;

          // store term text
          // we expect that there is at most one term per document
          if (t >= mterms.length) throw new RuntimeException ("there are more terms than " +
                  "documents in field \"" + field + "\", but it's impossible to sort on " +
                  "tokenized fields");
          mterms[t] = term.text();

          termDocs.seek (termEnum);
          while (termDocs.next()) {
            retArray[termDocs.doc()] = t;
          }

          t++;
        } while (termEnum.next());
      } finally {
        termDocs.close();
        termEnum.close();
      }

      if (t == 0) {
        // if there are no terms, make the term array
        // have a single null entry
        mterms = new String[1];
      } else if (t < mterms.length) {
        // if there are less terms than documents,
        // trim off the dead array space
        String[] terms = new String[t];
        System.arraycopy (mterms, 0, terms, 0, t);
        mterms = terms;
      }

      StringIndex value = new StringIndex (retArray, mterms);
      return value;
    }
  };

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics