Search in sources :

Example 11 with DefaultSortedSetDocValuesReaderState

use of org.apache.lucene.facet.sortedset.DefaultSortedSetDocValuesReaderState 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;
}
Also used : SortedSetDocValuesReaderState(org.apache.lucene.facet.sortedset.SortedSetDocValuesReaderState) DefaultSortedSetDocValuesReaderState(org.apache.lucene.facet.sortedset.DefaultSortedSetDocValuesReaderState) Facets(org.apache.lucene.facet.Facets) ArrayList(java.util.ArrayList) IOException(java.io.IOException) LabelAndValue(org.apache.lucene.facet.LabelAndValue) IOException(java.io.IOException) FacetsCollector(org.apache.lucene.facet.FacetsCollector) DefaultSortedSetDocValuesReaderState(org.apache.lucene.facet.sortedset.DefaultSortedSetDocValuesReaderState) SortedSetDocValuesFacetCounts(org.apache.lucene.facet.sortedset.SortedSetDocValuesFacetCounts) FacetResult(org.apache.lucene.facet.FacetResult)

Example 12 with DefaultSortedSetDocValuesReaderState

use of org.apache.lucene.facet.sortedset.DefaultSortedSetDocValuesReaderState in project searchcode-server by boyter.

the class TimeCodeSearcher method getDeletedFacetResults.

/**
 * Returns the matching revision facets for a given query
 */
private List<CodeFacetDeleted> getDeletedFacetResults(IndexSearcher searcher, IndexReader reader, Query query) {
    List<CodeFacetDeleted> deletedFacets = new ArrayList<>();
    try {
        SortedSetDocValuesReaderState state = new DefaultSortedSetDocValuesReaderState(reader, Values.DELETED);
        FacetsCollector fc = new FacetsCollector();
        FacetsCollector.search(searcher, query, 10, fc);
        Facets facets = new SortedSetDocValuesFacetCounts(state, fc);
        FacetResult result = facets.getTopChildren(200, Values.DELETED);
        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) {
                    deletedFacets.add(new CodeFacetDeleted(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 deletedFacets;
}
Also used : SortedSetDocValuesReaderState(org.apache.lucene.facet.sortedset.SortedSetDocValuesReaderState) DefaultSortedSetDocValuesReaderState(org.apache.lucene.facet.sortedset.DefaultSortedSetDocValuesReaderState) Facets(org.apache.lucene.facet.Facets) ArrayList(java.util.ArrayList) IOException(java.io.IOException) LabelAndValue(org.apache.lucene.facet.LabelAndValue) IOException(java.io.IOException) FacetsCollector(org.apache.lucene.facet.FacetsCollector) DefaultSortedSetDocValuesReaderState(org.apache.lucene.facet.sortedset.DefaultSortedSetDocValuesReaderState) SortedSetDocValuesFacetCounts(org.apache.lucene.facet.sortedset.SortedSetDocValuesFacetCounts) FacetResult(org.apache.lucene.facet.FacetResult)

Example 13 with DefaultSortedSetDocValuesReaderState

use of org.apache.lucene.facet.sortedset.DefaultSortedSetDocValuesReaderState 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;
}
Also used : SortedSetDocValuesReaderState(org.apache.lucene.facet.sortedset.SortedSetDocValuesReaderState) DefaultSortedSetDocValuesReaderState(org.apache.lucene.facet.sortedset.DefaultSortedSetDocValuesReaderState) Facets(org.apache.lucene.facet.Facets) ArrayList(java.util.ArrayList) IOException(java.io.IOException) LabelAndValue(org.apache.lucene.facet.LabelAndValue) IOException(java.io.IOException) FacetsCollector(org.apache.lucene.facet.FacetsCollector) DefaultSortedSetDocValuesReaderState(org.apache.lucene.facet.sortedset.DefaultSortedSetDocValuesReaderState) SortedSetDocValuesFacetCounts(org.apache.lucene.facet.sortedset.SortedSetDocValuesFacetCounts) FacetResult(org.apache.lucene.facet.FacetResult)

Example 14 with DefaultSortedSetDocValuesReaderState

use of org.apache.lucene.facet.sortedset.DefaultSortedSetDocValuesReaderState in project searchcode-server by boyter.

the class IndexService method getRepoFacetResults.

/**
 * Returns the matching repository facets for a given query
 */
private List<CodeFacetRepo> getRepoFacetResults(IndexSearcher searcher, IndexReader reader, Query query) {
    List<CodeFacetRepo> codeFacetRepo = new ArrayList<>();
    try {
        SortedSetDocValuesReaderState state = new DefaultSortedSetDocValuesReaderState(reader, Values.REPONAME);
        FacetsCollector fc = new FacetsCollector();
        FacetsCollector.search(searcher, query, 10, fc);
        Facets facets = new SortedSetDocValuesFacetCounts(state, fc);
        FacetResult result = facets.getTopChildren(this.CHILD_FACET_LIMIT, Values.REPONAME);
        if (result != null) {
            int stepThru = result.childCount > this.CHILD_FACET_LIMIT ? this.CHILD_FACET_LIMIT : result.childCount;
            for (int i = 0; i < stepThru; i++) {
                LabelAndValue lv = result.labelValues[i];
                if (lv != null && lv.value != null) {
                    codeFacetRepo.add(new CodeFacetRepo(lv.label, lv.value.intValue()));
                }
            }
        }
    } catch (Exception ignore) {
    }
    return codeFacetRepo;
}
Also used : SortedSetDocValuesReaderState(org.apache.lucene.facet.sortedset.SortedSetDocValuesReaderState) DefaultSortedSetDocValuesReaderState(org.apache.lucene.facet.sortedset.DefaultSortedSetDocValuesReaderState) DefaultSortedSetDocValuesReaderState(org.apache.lucene.facet.sortedset.DefaultSortedSetDocValuesReaderState) SortedSetDocValuesFacetCounts(org.apache.lucene.facet.sortedset.SortedSetDocValuesFacetCounts) ParseException(org.apache.lucene.queryparser.classic.ParseException) NoSuchFileException(java.nio.file.NoSuchFileException) IOException(java.io.IOException)

Example 15 with DefaultSortedSetDocValuesReaderState

use of org.apache.lucene.facet.sortedset.DefaultSortedSetDocValuesReaderState in project searchcode-server by boyter.

the class IndexService 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(this.CHILD_FACET_LIMIT, Values.CODEOWNER);
        if (result != null) {
            int stepThrough = result.childCount > this.CHILD_FACET_LIMIT ? this.CHILD_FACET_LIMIT : result.childCount;
            for (int i = 0; i < stepThrough; i++) {
                LabelAndValue lv = result.labelValues[i];
                if (lv != null && lv.value != null) {
                    codeFacetRepo.add(new CodeFacetOwner(lv.label, lv.value.intValue()));
                }
            }
        }
    } catch (Exception ignore) {
    }
    return codeFacetRepo;
}
Also used : SortedSetDocValuesReaderState(org.apache.lucene.facet.sortedset.SortedSetDocValuesReaderState) DefaultSortedSetDocValuesReaderState(org.apache.lucene.facet.sortedset.DefaultSortedSetDocValuesReaderState) DefaultSortedSetDocValuesReaderState(org.apache.lucene.facet.sortedset.DefaultSortedSetDocValuesReaderState) SortedSetDocValuesFacetCounts(org.apache.lucene.facet.sortedset.SortedSetDocValuesFacetCounts) ParseException(org.apache.lucene.queryparser.classic.ParseException) NoSuchFileException(java.nio.file.NoSuchFileException) IOException(java.io.IOException)

Aggregations

DefaultSortedSetDocValuesReaderState (org.apache.lucene.facet.sortedset.DefaultSortedSetDocValuesReaderState)19 SortedSetDocValuesFacetCounts (org.apache.lucene.facet.sortedset.SortedSetDocValuesFacetCounts)18 SortedSetDocValuesReaderState (org.apache.lucene.facet.sortedset.SortedSetDocValuesReaderState)18 IOException (java.io.IOException)16 Facets (org.apache.lucene.facet.Facets)14 FacetsCollector (org.apache.lucene.facet.FacetsCollector)14 FacetResult (org.apache.lucene.facet.FacetResult)13 LabelAndValue (org.apache.lucene.facet.LabelAndValue)11 ArrayList (java.util.ArrayList)10 NoSuchFileException (java.nio.file.NoSuchFileException)4 ParseException (org.apache.lucene.queryparser.classic.ParseException)4 IndexSearcher (org.apache.lucene.search.IndexSearcher)3 HashMap (java.util.HashMap)2 DirectoryReader (org.apache.lucene.index.DirectoryReader)2 MatchAllDocsQuery (org.apache.lucene.search.MatchAllDocsQuery)2 HashSet (java.util.HashSet)1 List (java.util.List)1 MockAnalyzer (org.apache.lucene.analysis.MockAnalyzer)1 Document (org.apache.lucene.document.Document)1 SortedDocValuesField (org.apache.lucene.document.SortedDocValuesField)1