use of org.apache.lucene.facet.LabelAndValue in project lucene-solr by apache.
the class TestTaxonomyFacetCounts method testManyFacetsInOneDocument.
// LUCENE-4583: make sure if we require > 32 KB for one
// document, we don't hit exc when using Facet42DocValuesFormat
public void testManyFacetsInOneDocument() throws Exception {
assumeTrue("default Codec doesn't support huge BinaryDocValues", TestUtil.fieldSupportsHugeBinaryDocValues(FacetsConfig.DEFAULT_INDEX_FIELD_NAME));
Directory dir = newDirectory();
Directory taxoDir = newDirectory();
IndexWriterConfig iwc = newIndexWriterConfig(new MockAnalyzer(random()));
RandomIndexWriter writer = new RandomIndexWriter(random(), dir, iwc);
DirectoryTaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir, IndexWriterConfig.OpenMode.CREATE);
FacetsConfig config = new FacetsConfig();
config.setMultiValued("dim", true);
int numLabels = TestUtil.nextInt(random(), 40000, 100000);
Document doc = new Document();
doc.add(newTextField("field", "text", Field.Store.NO));
for (int i = 0; i < numLabels; i++) {
doc.add(new FacetField("dim", "" + i));
}
writer.addDocument(config.build(taxoWriter, doc));
// NRT open
IndexSearcher searcher = newSearcher(writer.getReader());
// NRT open
TaxonomyReader taxoReader = new DirectoryTaxonomyReader(taxoWriter);
Facets facets = getAllFacets(FacetsConfig.DEFAULT_INDEX_FIELD_NAME, searcher, taxoReader, config);
FacetResult result = facets.getTopChildren(Integer.MAX_VALUE, "dim");
assertEquals(numLabels, result.labelValues.length);
Set<String> allLabels = new HashSet<>();
for (LabelAndValue labelValue : result.labelValues) {
allLabels.add(labelValue.label);
assertEquals(1, labelValue.value.intValue());
}
assertEquals(numLabels, allLabels.size());
writer.close();
IOUtils.close(searcher.getIndexReader(), taxoWriter, taxoReader, dir, taxoDir);
}
use of org.apache.lucene.facet.LabelAndValue in project searchcode-server by boyter.
the class TimeCodeSearcher method getOwnerFacetResults.
/**
* Returns the matching owner facets for a given query
*/
private List<CodeFacetOwner> getOwnerFacetResults(IndexSearcher searcher, IndexReader reader, Query query) {
List<CodeFacetOwner> codeFacetRepo = new ArrayList<>();
try {
SortedSetDocValuesReaderState state = new DefaultSortedSetDocValuesReaderState(reader, Values.CODEOWNER);
FacetsCollector fc = new FacetsCollector();
FacetsCollector.search(searcher, query, 10, fc);
Facets facets = new SortedSetDocValuesFacetCounts(state, fc);
FacetResult result = facets.getTopChildren(200, Values.CODEOWNER);
if (result != null) {
int stepThru = result.childCount > 200 ? 200 : result.childCount;
for (int i = 0; i < stepThru; i++) {
LabelAndValue lv = result.labelValues[i];
if (lv != null && lv.value != null) {
codeFacetRepo.add(new CodeFacetOwner(lv.label, lv.value.intValue()));
}
}
}
} catch (IOException ex) {
LOGGER.warning(" caught a " + ex.getClass() + "\n with message: " + ex.getMessage());
} catch (Exception ex) {
LOGGER.warning(" caught a " + ex.getClass() + "\n with message: " + ex.getMessage());
}
return codeFacetRepo;
}
use of org.apache.lucene.facet.LabelAndValue in project searchcode-server by boyter.
the class TimeCodeSearcher method getRevisionFacetResults.
/**
* Returns the matching revision facets for a given query
*/
private List<CodeFacetRevision> getRevisionFacetResults(IndexSearcher searcher, IndexReader reader, Query query) {
List<CodeFacetRevision> revisionFacets = new ArrayList<>();
try {
SortedSetDocValuesReaderState state = new DefaultSortedSetDocValuesReaderState(reader, Values.REVISION);
FacetsCollector fc = new FacetsCollector();
FacetsCollector.search(searcher, query, 10, fc);
Facets facets = new SortedSetDocValuesFacetCounts(state, fc);
FacetResult result = facets.getTopChildren(200, Values.REVISION);
if (result != null) {
int stepThru = result.childCount > 200 ? 200 : result.childCount;
for (int i = 0; i < stepThru; i++) {
LabelAndValue lv = result.labelValues[i];
if (lv != null && lv.value != null) {
revisionFacets.add(new CodeFacetRevision(lv.label, lv.value.intValue()));
}
}
}
} catch (IOException ex) {
LOGGER.warning(" caught a " + ex.getClass() + "\n with message: " + ex.getMessage());
} catch (Exception ex) {
LOGGER.warning(" caught a " + ex.getClass() + "\n with message: " + ex.getMessage());
}
return revisionFacets;
}
use of org.apache.lucene.facet.LabelAndValue in project searchcode-server by boyter.
the class TimeCodeSearcher method getYearFacetResults.
/**
* Returns the matching yearmonth facets for a given query
*/
private List<CodeFacetYear> getYearFacetResults(IndexSearcher searcher, IndexReader reader, Query query) {
List<CodeFacetYear> codeFacetYear = new ArrayList<>();
try {
SortedSetDocValuesReaderState state = new DefaultSortedSetDocValuesReaderState(reader, Values.DATEYEAR);
FacetsCollector fc = new FacetsCollector();
FacetsCollector.search(searcher, query, 10, fc);
Facets facets = new SortedSetDocValuesFacetCounts(state, fc);
FacetResult result = facets.getTopChildren(200, Values.DATEYEAR);
if (result != null) {
int stepThru = result.childCount > 200 ? 200 : result.childCount;
for (int i = 0; i < stepThru; i++) {
LabelAndValue lv = result.labelValues[i];
if (lv != null && lv.value != null) {
codeFacetYear.add(new CodeFacetYear(lv.label, lv.value.intValue()));
}
}
}
} catch (IOException ex) {
LOGGER.warning(" caught a " + ex.getClass() + "\n with message: " + ex.getMessage());
} catch (Exception ex) {
LOGGER.warning(" caught a " + ex.getClass() + "\n with message: " + ex.getMessage());
}
return codeFacetYear;
}
use of org.apache.lucene.facet.LabelAndValue in project searchcode-server by boyter.
the class TimeCodeSearcher method getLanguageFacetResults.
/**
* Returns the matching language facets for a given query
*/
private List<CodeFacetLanguage> getLanguageFacetResults(IndexSearcher searcher, IndexReader reader, Query query) {
List<CodeFacetLanguage> codeFacetLanguages = new ArrayList<>();
try {
SortedSetDocValuesReaderState state = new DefaultSortedSetDocValuesReaderState(reader, Values.LANGUAGENAME);
FacetsCollector fc = new FacetsCollector();
FacetsCollector.search(searcher, query, 10, fc);
Facets facets = new SortedSetDocValuesFacetCounts(state, fc);
FacetResult result = facets.getTopChildren(200, Values.LANGUAGENAME);
if (result != null) {
int stepThru = result.childCount > 200 ? 200 : result.childCount;
for (int i = 0; i < stepThru; i++) {
LabelAndValue lv = result.labelValues[i];
if (lv != null && lv.value != null) {
codeFacetLanguages.add(new CodeFacetLanguage(lv.label, lv.value.intValue()));
}
}
}
} catch (IOException ex) {
LOGGER.warning(" caught a " + ex.getClass() + "\n with message: " + ex.getMessage());
} catch (Exception ex) {
LOGGER.warning(" caught a " + ex.getClass() + "\n with message: " + ex.getMessage());
}
return codeFacetLanguages;
}
Aggregations