public int getNumberOfFields() throws IOException { IndexReader reader = getMainIndexReferenceCountingReadOnlyIndexReader(); try { return reader.getFieldNames(IndexReader.FieldOption.ALL).size(); } finally { reader.close(); } }
public int getNumberOfIndexedFields() throws IOException { IndexReader reader = getMainIndexReferenceCountingReadOnlyIndexReader(); try { return reader.getFieldNames(IndexReader.FieldOption.INDEXED).size(); } finally { reader.close(); } }
@Override public boolean sortFieldExists(String noLocalField) { for (Object current : lqp.getIndexReader().getFieldNames(FieldOption.INDEXED)) { String currentString = (String) current; if (currentString.equals(noLocalField)) { return true; } } return false; }
/** * Determine the index for the highest interval field within the Lucene index. * <br/>e.g. timeperiod.l.7 * <br/>If the the document with the most intervals has 7, then 7 is the max. * @throws DiscoveryException if there is a problem accessing the index */ private void determineMaxIntervalFieldName() throws DiscoveryException { IndexSearcher searcher = null; try { searcher = this.getQueryAdapter().getIndexAdapter().newSearcher(); IndexReader reader = searcher.getIndexReader(); Collection<String> names = reader.getFieldNames(FieldOption.ALL); String sPfx = this.baseFieldName.toLowerCase()+".l."; int nBeginSubstring = sPfx.length(); int nMax = -1; for (String name: names) { String lc = name.toLowerCase(); if (lc.startsWith(sPfx)) { LOGGER.finest("Found boundary field: "+name); String s = lc.substring(nBeginSubstring); try { int n = Integer.valueOf(s); if (n > nMax) { nMax = n; } } catch (NumberFormatException nfe) {} } } LOGGER.finest("MaxBndFieldIndex: "+nMax); this.maxIntervalFieldName = nMax; } catch (IOException e) { LOGGER.log(Level.SEVERE,"Index issue.",e); throw new DiscoveryException(e.toString(),e); } finally { this.getQueryAdapter().getIndexAdapter().closeSearcher(searcher); } }
protected String findSortField(SearchParameters searchParameters, ClosingIndexSearcher searcher, String field, Locale sortLocale) { // find best field match MLAnalysisMode analysisMode = getLuceneConfig().getDefaultMLSearchAnalysisMode(); HashSet<String> allowableLocales = new HashSet<String>(); for (Locale l : MLAnalysisMode.getLocales(analysisMode, sortLocale, false)) { allowableLocales.add(l.toString()); } String sortField = field; for (Object current : searcher.getReader().getFieldNames(FieldOption.INDEXED)) { String currentString = (String) current; if (currentString.startsWith(field) && currentString.endsWith(".sort")) { String fieldLocale = currentString.substring(field.length() + 1, currentString.length() - 5); if (allowableLocales.contains(fieldLocale)) { if (fieldLocale.equals(sortLocale.toString())) { sortField = currentString; break; } else if (sortLocale.toString().startsWith(fieldLocale)) { if (sortField.equals(field) || (currentString.length() < sortField.length())) { sortField = currentString; } } else if (fieldLocale.startsWith(sortLocale.toString())) { if (sortField.equals(field) || (currentString.length() < sortField.length())) { sortField = currentString; } } } } } return sortField; }
@Override public String getSortField(String field) throws ParseException { Locale sortLocale; List<Locale> locales = lqp.getSearchParameters().getLocales(); if (((locales == null) || (locales.size() == 0))) { locales = Collections.singletonList(I18NUtil.getLocale()); } if (locales.size() > 1) { throw new ParseException("Order on text/mltext properties with more than one locale is not curently supported"); } sortLocale = locales.get(0); // find best field match HashSet<String> allowableLocales = new HashSet<String>(); MLAnalysisMode analysisMode = lqp.getDefaultSearchMLAnalysisMode(); for (Locale l : MLAnalysisMode.getLocales(analysisMode, sortLocale, false)) { allowableLocales.add(l.toString()); } String sortField = field; for (Object current : lqp.getIndexReader().getFieldNames(FieldOption.INDEXED)) { String currentString = (String) current; if (currentString.startsWith(field) && currentString.endsWith(QueryConstants.FIELD_SORT_SUFFIX)) { String fieldLocale = currentString.substring(field.length() + 1, currentString.length() - QueryConstants.FIELD_SORT_SUFFIX.length()); if (allowableLocales.contains(fieldLocale)) { if (fieldLocale.equals(sortLocale.toString())) { sortField = currentString; break; } else if (sortLocale.toString().startsWith(fieldLocale)) { if (sortField.equals(field) || (currentString.length() < sortField.length())) { sortField = currentString; } } else if (fieldLocale.startsWith(sortLocale.toString())) { if (sortField.equals(field) || (currentString.length() < sortField.length())) { sortField = currentString; } } } } } field = sortField; return field; }