Search in sources :

Example 6 with IndexedField

use of org.alfresco.solr.AlfrescoSolrDataModel.IndexedField in project SearchServices by Alfresco.

the class Solr4QueryParser method addContentAttributeQuery.

// TODO: correct field names
protected Query addContentAttributeQuery(PropertyDefinition pDef, String queryText, SubQuery subQueryBuilder, AnalysisMode analysisMode, LuceneFunction luceneFunction, String expandedFieldName, List<Locale> expandedLocales) throws ParseException {
    BooleanQuery.Builder booleanQuery = new BooleanQuery.Builder();
    for (Locale locale : expandedLocales) {
        if (locale.toString().length() == 0) {
            IndexedField indexedField = AlfrescoSolrDataModel.getInstance().getQueryableFields(pDef.getName(), null, FieldUse.FTS);
            for (FieldInstance field : indexedField.getFields()) {
                if (!field.isLocalised()) {
                    Query subQuery = subQueryBuilder.getQuery(field.getField(), queryText, analysisMode, luceneFunction);
                    if (subQuery != null) {
                        booleanQuery.add(subQuery, Occur.SHOULD);
                    }
                }
            }
        } else {
            StringBuilder builder = new StringBuilder(queryText.length() + 10);
            builder.append("\u0000").append(locale.toString()).append("\u0000").append(queryText);
            IndexedField indexedField = AlfrescoSolrDataModel.getInstance().getQueryableFields(pDef.getName(), null, FieldUse.FTS);
            for (FieldInstance field : indexedField.getFields()) {
                if (field.isLocalised()) {
                    Query subQuery = subQueryBuilder.getQuery(field.getField(), builder.toString(), analysisMode, luceneFunction);
                    if (subQuery != null) {
                        booleanQuery.add(subQuery, Occur.SHOULD);
                    }
                }
            }
        }
    }
    return getNonEmptyBooleanQuery(booleanQuery.build());
}
Also used : Locale(java.util.Locale) BooleanQuery(org.apache.lucene.search.BooleanQuery) Query(org.apache.lucene.search.Query) RegexpQuery(org.apache.lucene.search.RegexpQuery) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) ConstantScoreQuery(org.apache.lucene.search.ConstantScoreQuery) SpanNearQuery(org.apache.lucene.search.spans.SpanNearQuery) SpanOrQuery(org.apache.lucene.search.spans.SpanOrQuery) MultiTermQuery(org.apache.lucene.search.MultiTermQuery) SpanTermQuery(org.apache.lucene.search.spans.SpanTermQuery) SpanQuery(org.apache.lucene.search.spans.SpanQuery) TermQuery(org.apache.lucene.search.TermQuery) BooleanQuery(org.apache.lucene.search.BooleanQuery) TermRangeQuery(org.apache.lucene.search.TermRangeQuery) IndexedField(org.alfresco.solr.AlfrescoSolrDataModel.IndexedField) Builder(org.apache.lucene.search.BooleanQuery.Builder) FieldInstance(org.alfresco.solr.AlfrescoSolrDataModel.FieldInstance) Builder(org.apache.lucene.search.BooleanQuery.Builder)

Aggregations

FieldInstance (org.alfresco.solr.AlfrescoSolrDataModel.FieldInstance)6 IndexedField (org.alfresco.solr.AlfrescoSolrDataModel.IndexedField)6 SpanNearQuery (org.apache.lucene.search.spans.SpanNearQuery)5 SpanQuery (org.apache.lucene.search.spans.SpanQuery)5 Locale (java.util.Locale)4 BooleanQuery (org.apache.lucene.search.BooleanQuery)4 Builder (org.apache.lucene.search.BooleanQuery.Builder)4 IOException (java.io.IOException)3 ConstantScoreQuery (org.apache.lucene.search.ConstantScoreQuery)3 MatchAllDocsQuery (org.apache.lucene.search.MatchAllDocsQuery)3 MultiTermQuery (org.apache.lucene.search.MultiTermQuery)3 Query (org.apache.lucene.search.Query)3 RegexpQuery (org.apache.lucene.search.RegexpQuery)3 TermQuery (org.apache.lucene.search.TermQuery)3 TermRangeQuery (org.apache.lucene.search.TermRangeQuery)3 SpanOrQuery (org.apache.lucene.search.spans.SpanOrQuery)3 SpanTermQuery (org.apache.lucene.search.spans.SpanTermQuery)3 ArrayList (java.util.ArrayList)2 IndexTokenisationMode (org.alfresco.repo.dictionary.IndexTokenisationMode)2 PropertyDefinition (org.alfresco.service.cmr.dictionary.PropertyDefinition)2