You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by SOLR4189 <Kl...@yandex.ru> on 2017/06/13 17:49:53 UTC

Solr 6: how to get SortedSetDocValues from index by field name

How do I get SortedSetDocValues from index by field name?

I try it and it works for me but I didn't understand why to use
leaves.get(0)? What does it mean? (I saw such using in
TestUninvertedReader.java of SOLR-6.5.1):

*Map<String, UninvertingReader.Type> mapping = new HashMap<>();
mapping.put(fieldName, UninvertingReader.Type.SORTED);

SolrIndexSearcher searcher = req.getSearcher();

DirectoryReader dReader = searcher.getIndexReader();
LeafReader reader = null;

if (!dReader.leaves.isEmpty()) {
  reader = dReader.leaves().get(0).reader;
  return null;
}

SortedSetDocValues sourceIndex = reader.getSortedSetDocValues(fieldName);*

Maybe do I need to use SlowAtomicReader, like it:

*
UninvertingReader reader = new
UninvertingReader(searcher.getSlowAtomicReader(), mapping)*;

What is right way to get SortedSetDocValues and why?



--
View this message in context: http://lucene.472066.n3.nabble.com/Solr-6-how-to-get-SortedSetDocValues-from-index-by-field-name-tp4340388.html
Sent from the Solr - User mailing list archive at Nabble.com.

Re: Solr 6: how to get SortedSetDocValues from index by field name

Posted by Chris Hostetter <ho...@fucit.org>.
https://people.apache.org/~hossman/#xyproblem
XY Problem

Your question appears to be an "XY Problem" ... that is: you are dealing
with "X", you are assuming "Y" will help you, and you are asking about "Y"
without giving more details about the "X" so that we can understand the
full issue.  Perhaps the best solution doesn't involve "Y" at all?
See Also: http://www.perlmonks.org/index.pl?node_id=542341




: How do I get SortedSetDocValues from index by field name?
: 
: I try it and it works for me but I didn't understand why to use
: leaves.get(0)? What does it mean? (I saw such using in
: TestUninvertedReader.java of SOLR-6.5.1):
: 
: *Map<String, UninvertingReader.Type> mapping = new HashMap<>();
: mapping.put(fieldName, UninvertingReader.Type.SORTED);
: 
: SolrIndexSearcher searcher = req.getSearcher();
: 
: DirectoryReader dReader = searcher.getIndexReader();
: LeafReader reader = null;
: 
: if (!dReader.leaves.isEmpty()) {
:   reader = dReader.leaves().get(0).reader;
:   return null;
: }
: 
: SortedSetDocValues sourceIndex = reader.getSortedSetDocValues(fieldName);*
: 
: Maybe do I need to use SlowAtomicReader, like it:
: 
: *
: UninvertingReader reader = new
: UninvertingReader(searcher.getSlowAtomicReader(), mapping)*;
: 
: What is right way to get SortedSetDocValues and why?
: 
: 
: 
: --
: View this message in context: http://lucene.472066.n3.nabble.com/Solr-6-how-to-get-SortedSetDocValues-from-index-by-field-name-tp4340388.html
: Sent from the Solr - User mailing list archive at Nabble.com.
: 

-Hoss
http://www.lucidworks.com/

Re: Solr 6: how to get SortedSetDocValues from index by field name

Posted by SOLR4189 <Kl...@yandex.ru>.
Hi, Tomas. It helped. Thank you.





--
View this message in context: http://lucene.472066.n3.nabble.com/Solr-6-how-to-get-SortedSetDocValues-from-index-by-field-name-tp4340388p4342002.html
Sent from the Solr - User mailing list archive at Nabble.com.

Re: Solr 6: how to get SortedSetDocValues from index by field name

Posted by Tomas Fernandez Lobbe <tf...@apple.com>.
Hi,
To respond your first question: “How do I get SortedSetDocValues from index by field name?”, DocValues.getSortedSet(LeafReader reader, String field) (which is what you want to use to assert the existence and type of the DV) will give you the dv instance for a single leaf reader. In general, a leaf reader is for a specific segment, so depending on what you want to do you may need to iterate through all the leaves (segments) if you want all values in the index (kind of what you’ll see in NumericFacets or IntervalFacets classes). 

SolrIndexSearcher.getSlowAtomicReader() will give you a view of all the segments as a single reader, that’s why in that case the code assumes there is only one reader that contains all the values. 

Whatever you do, make sure you test your code in cases with multiple segments (and with deletes), which is where bugs using this code are most likely to occur.

You won’t need the UninvertingReader if you plan to index docValues, that class is used to create a docValues-like view of a field that’s indexed=true & docValues=false.

Related note, the DocValues API changed from 6.x to 7 (master). See LUCENE-7407.

I hope that helps, 

Tomás

> On Jun 13, 2017, at 10:49 AM, SOLR4189 <Kl...@yandex.ru> wrote:
> 
> How do I get SortedSetDocValues from index by field name?
> 
> I try it and it works for me but I didn't understand why to use
> leaves.get(0)? What does it mean? (I saw such using in
> TestUninvertedReader.java of SOLR-6.5.1):
> 
> *Map<String, UninvertingReader.Type> mapping = new HashMap<>();
> mapping.put(fieldName, UninvertingReader.Type.SORTED);
> 
> SolrIndexSearcher searcher = req.getSearcher();
> 
> DirectoryReader dReader = searcher.getIndexReader();
> LeafReader reader = null;
> 
> if (!dReader.leaves.isEmpty()) {
>  reader = dReader.leaves().get(0).reader;
>  return null;
> }
> 
> SortedSetDocValues sourceIndex = reader.getSortedSetDocValues(fieldName);*
> 
> Maybe do I need to use SlowAtomicReader, like it:
> 
> *
> UninvertingReader reader = new
> UninvertingReader(searcher.getSlowAtomicReader(), mapping)*;
> 
> What is right way to get SortedSetDocValues and why?
> 
> 
> 
> --
> View this message in context: http://lucene.472066.n3.nabble.com/Solr-6-how-to-get-SortedSetDocValues-from-index-by-field-name-tp4340388.html
> Sent from the Solr - User mailing list archive at Nabble.com.