lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Martin Grigorov <mgrigo...@apache.org>
Subject Re: How groupingSearch specifies SortedNumericDocValuesField
Date Wed, 15 May 2019 05:51:11 GMT
Hi,

On Tue, May 14, 2019 at 8:28 PM 顿顿 <liboemc@gmail.com> wrote:

> When I use groupingSearch specified as SortedNumericDocValuesField,
> I got an "unexpected docvalues type NUMERIC for field 'id'
> (expected=SORTED)" Exception.
>
> My code is as follows:
>  String indexPath = "tmp/grouping";
>         Analyzer standardAnalyzer = new StandardAnalyzer();
>         Directory indexDir = FSDirectory.open(Paths.get(indexPath));
>         IndexWriterConfig indexWriterConfig = new
> IndexWriterConfig(standardAnalyzer);
>         indexWriterConfig.setOpenMode(IndexWriterConfig.OpenMode.CREATE);
>         IndexWriter masterIndex = new IndexWriter(indexDir,
> indexWriterConfig);
>
>         String name = "Tom";
>         for (int i = 1; i < 5; i++) {
>             Document doc = new Document();
>             doc.add(new StringField("name", name + "_" + i,
> Field.Store.YES));
>             doc.add(new SortedNumericDocValuesField("id", i));
>             doc.add(new StoredField("id", i));
>

are you sure both fields should have the same name ("id") ?


>             masterIndex.addDocument(doc);
>
>         }
>         masterIndex.commit();
>         masterIndex.commit();
>
>         IndexReader reader =
> DirectoryReader.open(FSDirectory.open(Paths.get(indexPath)));
>         IndexSearcher searcher = new IndexSearcher(reader);
>
>         GroupingSearch groupingSearch = new GroupingSearch("id");
>         TopGroups topGroups = groupingSearch.search(searcher, new
> MatchAllDocsQuery(), 0, 100);
>
>         System.out.println(topGroups.totalHitCount);
>         reader.close();
>
>
> The exception is as follows:
> Exception in thread "main" java.lang.IllegalStateException: unexpected
> docvalues type SORTED_NUMERIC for field 'id' (expected=SORTED). Re-index
> with correct docvalues type.
> at org.apache.lucene.index.DocValues.checkField(DocValues.java:317)
> at org.apache.lucene.index.DocValues.getSorted(DocValues.java:369)
> at
>
> org.apache.lucene.search.grouping.TermGroupSelector.setNextReader(TermGroupSelector.java:56)
> at
>
> org.apache.lucene.search.grouping.FirstPassGroupingCollector.doSetNextReader(FirstPassGroupingCollector.java:348)
> at
>
> org.apache.lucene.search.SimpleCollector.getLeafCollector(SimpleCollector.java:33)
> at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:643)
> at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:443)
> at
>
> org.apache.lucene.search.grouping.GroupingSearch.groupByFieldOrFunction(GroupingSearch.java:141)
> at
>
> org.apache.lucene.search.grouping.GroupingSearch.search(GroupingSearch.java:113)
>
>
> The version of Lucene I am using is 8.0.0.
>
>
> Finally, I want to know how groupingSearch specifies three fields:
> NumericDocValuesField, SortedNumericDocValuesField,
> SortedSetDocValuesField?
>
>
>
>
> Thank you for your attention  to this  matter!
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message