Project

General

Profile

« Previous | Next » 

Revision b2639c6c

Added by Andreas Müller over 8 years ago

Fix all compile errors from services to remote (some only preliminary)
#4716

View differences:

cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/config/Configuration.java
32 32
     *
33 33
     */
34 34
    @Deprecated // so we now it is not 100% save to use this
35
    public static Version luceneVersion = Version.LUCENE_36;
35
    public static Version luceneVersion = Version.LUCENE_4_10_4;
36 36

  
37 37
    /**
38 38
     * Login name for the first user 'admin'
cdmlib-services/pom.xml
73 73
       <groupId>org.apache.lucene</groupId>
74 74
       <artifactId>lucene-join</artifactId>
75 75
    </dependency>
76
    <!--  OLD concept, not under development anymore,
77
     to be removed as soon as CdmMassIndexer is updated -->
78
    <dependency>
79
        <groupId>org.apache.lucene</groupId>
80
        <artifactId>lucene-spellchecker</artifactId>
81
    </dependency>
82
    
76 83
    <dependency>
77 84
      <groupId>org.unitils</groupId>
78 85
      <artifactId>unitils-dbunit</artifactId>
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/search/CdmMassIndexer.java
33 33
import org.hibernate.Session;
34 34
import org.hibernate.search.FullTextSession;
35 35
import org.hibernate.search.Search;
36
import org.hibernate.search.engine.spi.SearchFactoryImplementor;
37
import org.hibernate.search.indexes.impl.DirectoryBasedIndexManager;
36
import org.hibernate.search.SearchFactory;
37
import org.hibernate.search.indexes.spi.DirectoryBasedIndexManager;
38 38
import org.hibernate.search.indexes.spi.IndexManager;
39 39
import org.springframework.beans.factory.annotation.Autowired;
40 40
import org.springframework.orm.hibernate4.HibernateTransactionManager;
......
151 151
            //TODO:give some indication that this class is infact not indexed
152 152
            return;
153 153
        }
154
        SearchFactoryImplementor searchFactory = (SearchFactoryImplementor)Search.getFullTextSession(getSession()).getSearchFactory();
155
        IndexManager indexManager = searchFactory.getAllIndexesManager().getIndexManager(indexName);
154
        SearchFactory searchFactory = Search.getFullTextSession(getSession()).getSearchFactory();
155
        IndexManager indexManager = makeIndexManager(searchFactory, indexName);
156

  
156 157
        IndexReader indexReader = searchFactory.getIndexReaderAccessor().open(type);
157 158
        List<String> idFields = getIndexedDeclaredFields(type);
158 159

  
......
200 201
        subMonitor.done();
201 202
    }
202 203

  
204
    private IndexManager makeIndexManager(SearchFactory searchFactory, String indexName){
205
        //FIXME #4716 SearchFactoryImplementor not available in hibernate-search anymore
206
//        SearchFactoryImplementor searchFactory = (SearchFactoryImplementor)searchFactory;
207
//        IndexManager indexManager = searchFactory.getAllIndexesManager().getIndexManager(indexName);
208
//        return indexManager;
209
        return null;
210
    }
211

  
203 212
    /**
204 213
     * @param countResult
205 214
     * @return
......
232 241
        boolean doSpellIndex = false;
233 242

  
234 243
        if(doSpellIndex){
235
            SearchFactoryImplementor searchFactory = (SearchFactoryImplementor)fullTextSession.getSearchFactory();
236
            IndexManager indexManager = searchFactory.getAllIndexesManager().getIndexManager(type.getName());
244
            SearchFactory searchFactory = fullTextSession.getSearchFactory();
245
            IndexManager indexManager = makeIndexManager(searchFactory, type.getName());
237 246
            if(indexManager == null){
238 247
                logger.info("No IndexManager found for " + type.getName() + ", thus nothing to purge");
239 248
                return;
......
262 271
        }
263 272
    }
264 273

  
265

  
266
    /* (non-Javadoc)
267
     * @see eu.etaxonomy.cdm.database.IMassIndexer#reindex()
268
     */
269 274
    @Override
270 275
    public void reindex(Collection<Class<? extends CdmBase>> types, IProgressMonitor monitor){
271 276

  
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/search/LuceneSearch.java
29 29
import org.apache.lucene.search.grouping.term.TermAllGroupsCollector;
30 30
import org.apache.lucene.search.grouping.term.TermFirstPassGroupingCollector;
31 31
import org.apache.lucene.search.grouping.term.TermSecondPassGroupingCollector;
32
import org.apache.lucene.util.BytesRef;
32 33

  
33 34
import eu.etaxonomy.cdm.model.common.CdmBase;
34 35
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
......
280 281
                groupByField, groupSort, limit);
281 282

  
282 283
        getSearcher().search(fullQuery, filter , firstPassCollector);
283
        Collection<SearchGroup<String>> topGroups = firstPassCollector.getTopGroups(0, true); // no offset here since we need the first item for the max score
284
        Collection<SearchGroup<BytesRef>> topGroups = firstPassCollector.getTopGroups(0, true); // no offset here since we need the first item for the max score
284 285

  
285 286
        if (topGroups == null) {
286 287
              return null;
......
301 302
                );
302 303
        getSearcher().search(fullQuery, filter, MultiCollector.wrap(secondPassCollector, allGroupsCollector));
303 304

  
304
        TopGroups<String> groupsResult = secondPassCollector.getTopGroups(0); // no offset here since we need the first item for the max score
305
        TopGroups<BytesRef> groupsResult = secondPassCollector.getTopGroups(0); // no offset here since we need the first item for the max score
305 306

  
306 307
        // get max score from very first result
307 308
        float maxScore = groupsResult.groups[0].maxScore;
......
367 368
     *
368 369
     */
369 370
    public class TopGroupsWithMaxScore{
370
        public TopGroups<String> topGroups;
371
        public TopGroups<BytesRef> topGroups;
371 372
        public float maxScore = Float.NaN;
372 373

  
373
        TopGroupsWithMaxScore(TopGroups<String> topGroups, int offset, int totalGroupCount, float maxScore){
374
        TopGroupsWithMaxScore(TopGroups<BytesRef> topGroups, int offset, int totalGroupCount, float maxScore){
374 375
            this.maxScore = maxScore;
375
            TopGroups<String> newTopGroups;
376
            TopGroups<BytesRef> newTopGroups;
376 377
            if(offset > 0){
377
                GroupDocs<String>[] newGroupDocs = new GroupDocs[topGroups.groups.length - offset];
378
                GroupDocs<BytesRef>[] newGroupDocs = new GroupDocs[topGroups.groups.length - offset];
378 379
                for(int i = offset; i < topGroups.groups.length; i++){
379 380
                    newGroupDocs[i - offset] = topGroups.groups[i];
380 381
                }
381
                newTopGroups = new TopGroups<String>(
382
                newTopGroups = new TopGroups<BytesRef>(
382 383
                            topGroups.groupSort,
383 384
                            topGroups.withinGroupSort,
384 385
                            topGroups.totalHitCount,
385 386
                            topGroups.totalGroupedHitCount,
386
                            newGroupDocs);
387
                            newGroupDocs,
388
                            maxScore);
387 389
            } else {
388 390
                newTopGroups = topGroups;
389 391
            }
390
            this.topGroups = new TopGroups<String>(newTopGroups, totalGroupCount);
392
            this.topGroups = new TopGroups<BytesRef>(newTopGroups, totalGroupCount);
391 393
        }
392 394

  
393 395
    }
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/search/QueryFactory.java
34 34
import org.apache.lucene.search.TermQuery;
35 35
import org.apache.lucene.search.WildcardQuery;
36 36
import org.apache.lucene.search.join.JoinUtil;
37
import org.apache.lucene.search.join.ScoreMode;
37 38
import org.hibernate.search.engine.ProjectionConstants;
38 39
import org.hibernate.search.spatial.impl.Point;
39 40
import org.hibernate.search.spatial.impl.Rectangle;
......
335 336
     */
336 337
    public Query newJoinQuery(String fromField, String toField, Query joinFromQuery,
337 338
            Class<? extends CdmBase> fromType) throws IOException {
338
            return JoinUtil.createJoinQuery(fromField, toField, joinFromQuery, indexSearcherFor(fromType));
339
            boolean multipleValuesPerDocument = true;
340
            ScoreMode scoreMode = ScoreMode.Max;
341
            return JoinUtil.createJoinQuery(fromField, multipleValuesPerDocument, toField,
342
                    joinFromQuery, indexSearcherFor(fromType), scoreMode);
339 343
    }
340 344

  
341 345
    /**
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/search/SearchResultHighligther.java
20 20
import org.apache.lucene.analysis.TokenStream;
21 21
import org.apache.lucene.document.Document;
22 22
import org.apache.lucene.index.CorruptIndexException;
23
//import org.apache.lucene.index.DocsAndPositionsEnum;
24 23
import org.apache.lucene.search.Query;
25 24
import org.apache.lucene.search.highlight.Fragmenter;
26 25
import org.apache.lucene.search.highlight.Highlighter;
......
88 87
    }
89 88

  
90 89

  
91
    /**
92
     * Generates contextual fragments.
93
     * @param termPosVector - Term Position Vector for fieldName
94
     * @param query - query object created from user's input
95
     * @param fieldName - name of the field containing the text to be fragmented
96
     * @param fieldContents - contents of fieldName
97
     * @param fragmentNumber - max number of sentence fragments to return
98
     * @param fragmentSize - the max number of characters for each fragment
99
     * @return
100
     * @return
101
     * @throws IOException
102
     */
103
    public String[] getFragmentsWithHighlightedTerms(TermPositionVector termPosVector, Query query,
104
                    String fieldName, String fieldContents, int fragmentNumber, int fragmentSize) throws IOException  {
105

  
106
            TokenStream stream = TokenSources.getTokenStream(termPosVector);
107
            String[] fragments = getFragmentsWithHighlightedTerms(stream, query, fieldName, fieldContents, fragmentNumber, fragmentSize);
108

  
109
            return fragments;
110
    }
90
//    /**
91
//     * Generates contextual fragments.
92
//     * @param termPosVector - Term Position Vector for fieldName
93
//     * @param query - query object created from user's input
94
//     * @param fieldName - name of the field containing the text to be fragmented
95
//     * @param fieldContents - contents of fieldName
96
//     * @param fragmentNumber - max number of sentence fragments to return
97
//     * @param fragmentSize - the max number of characters for each fragment
98
//     * @return
99
//     * @return
100
//     * @throws IOException
101
//     */
102
//    public String[] getFragmentsWithHighlightedTerms(TermPositionVector termPosVector, Query query,
103
//                    String fieldName, String fieldContents, int fragmentNumber, int fragmentSize) throws IOException  {
104
//
105
//            TokenStream stream = TokenSources.getTokenStream(termPosVector);
106
//            String[] fragments = getFragmentsWithHighlightedTerms(stream, query, fieldName, fieldContents, fragmentNumber, fragmentSize);
107
//
108
//            return fragments;
109
//    }
111 110

  
112 111
    /**
113 112
     * @param stream
pom.xml
1022 1022
        <artifactId>lucene-core</artifactId>
1023 1023
        <version>${lucene.version}</version>
1024 1024
      </dependency>
1025
	  <!--  OLD concept, not under development anymore,
1026
     to be removed as soon as CdmMassIndexer is updated -->
1025 1027
      <dependency>
1026 1028
        <groupId>org.apache.lucene</groupId>
1027 1029
        <artifactId>lucene-spellchecker</artifactId>
1028
        <version>${lucene.version}</version>
1030
        <version>3.6.2</version>
1029 1031
      </dependency>
1030 1032
      <dependency>
1031 1033
        <groupId>org.apache.lucene</groupId>

Also available in: Unified diff