Salome HOME
Old knowledge lucene search has been removed.
authorrkv <rkv@opencascade.com>
Mon, 11 Mar 2013 07:18:52 +0000 (07:18 +0000)
committerrkv <rkv@opencascade.com>
Mon, 11 Mar 2013 07:18:52 +0000 (07:18 +0000)
Workspace/Siman-Common/src/org/splat/service/SearchService.java
Workspace/Siman-Common/src/org/splat/service/SearchServiceImpl.java
Workspace/Siman-Common/src/org/splat/service/dto/SearchFilterDTO.java
Workspace/Siman-Common/src/org/splat/service/dto/StudySearchFilterDTO.java
Workspace/Siman/src/org/splat/simer/admin/SimulationContextAction.java

index 3bd9edc939b26b87471eaf371194893315abcf7e..b644c5fb17274dd6b067b4b087eb4331515feec4 100644 (file)
@@ -11,7 +11,6 @@ package org.splat.service;
 
 import java.util.List;
 
-import org.splat.dal.bo.som.KnowledgeElement;
 import org.splat.dal.bo.som.Study;
 import org.splat.service.dto.ImportedStudyDTO;
 import org.splat.service.dto.KnowledgeSearchFilterDTO;
@@ -50,16 +49,6 @@ public interface SearchService {
        List<Proxy> selectKnowledgeElementsWhere(
                        final KnowledgeSearchFilterDTO filter);
 
-       /**
-        * Find knowledge elements with given properties.
-        * 
-        * @param kprop
-        *            search filter parameters
-        * @return the list of found knowledge elements as proxiy results of lucene search
-        */
-       List<Proxy> selectKnowledgeElementsWhere(
-                       KnowledgeElement.Properties... kprop);
-
        /**
         * Find studies with given properties.
         * 
index 34053560dacc1fe796de3d308da03b26b447cc10..eccbccca111591befb16658dc819c839a7f5deb6 100644 (file)
@@ -41,7 +41,6 @@ import org.hibernate.criterion.Restrictions;
 import org.hibernate.type.Type;
 import org.splat.dal.bo.kernel.User;
 import org.splat.dal.bo.som.KnowledgeElement;
-import org.splat.dal.bo.som.KnowledgeElementType;
 import org.splat.dal.bo.som.ProgressState;
 import org.splat.dal.bo.som.Scenario;
 import org.splat.dal.bo.som.SimulationContext;
@@ -233,134 +232,6 @@ public class SearchServiceImpl implements SearchService {
                }
        }
 
-       /**
-        * {@inheritDoc}
-        * 
-        * @see org.splat.service.SearchService#selectKnowledgeElementsWhere(org.splat.dal.bo.som.KnowledgeElement.Properties[])
-        */
-       @Deprecated
-       public List<Proxy> selectKnowledgeElementsWhere(
-                       final KnowledgeElement.Properties... kprop) {
-               List<Proxy> result = new ArrayList<Proxy>();
-               int hitsize = 20;
-               try {
-
-                       // Creation of the Lucene query
-                       File indir = getRepositoryService().getRepositoryIndexDirectory();
-                       Directory index = FSDirectory.open(indir);
-                       IndexSearcher searcher = new IndexSearcher(index, true);
-                       BooleanQuery fulquery = new BooleanQuery();
-
-                       for (int i = 0; i < kprop.length; i++) {
-                               BooleanQuery query = new BooleanQuery();
-                               Term input; // Supposed initialized below at least by the visibility
-
-                               Visibility area = kprop[i].getVisibility(); // Visibility
-                               if (area != null) {
-                                       input = new Term("area");
-                                       query.add(new TermQuery(input.createTerm(area.toString())),
-                                                       BooleanClause.Occur.MUST);
-                               }
-                               ProgressState state = kprop[i].getProgressState(); // State
-                               if (state != null) {
-                                       input = new Term("state");
-                                       query.add(
-                                                       new TermQuery(input.createTerm(state.toString())),
-                                                       BooleanClause.Occur.MUST);
-                               }
-                               String refid = kprop[i].getReference(); // Reference
-                               if (refid != null) {
-                                       input = new Term("ref");
-                                       query.add(new TermQuery(input.createTerm(refid)),
-                                                       BooleanClause.Occur.MUST);
-                               }
-                               KnowledgeElementType type = kprop[i].getType(); // Type
-                               if (type != null) {
-                                       input = new Term("type");
-                                       query.add(new TermQuery(input.createTerm(type.getName())),
-                                                       BooleanClause.Occur.MUST);
-                               }
-                               User manager = kprop[i].getAuthor(); // Author
-                               if (manager != null) {
-                                       input = new Term("author");
-                                       query.add(new TermQuery(input
-                                                       .createTerm(manager.toString())),
-                                                       BooleanClause.Occur.MUST);
-                               }
-                               User actor = kprop[i].getActor(); // Contributor, Reviewer or Approver of the owner study
-                               if (actor != null) {
-                                       input = new Term("actor");
-                                       query.add(
-                                                       new TermQuery(input.createTerm(actor.toString())),
-                                                       BooleanClause.Occur.MUST);
-                               }
-                               String title = kprop[i].getTitle(); // Title
-                               if (title != null) {
-                                       input = new Term("contents");
-                                       BooleanQuery critext = new BooleanQuery();
-                                       String operator = "AND"; // Future user input
-                                       BooleanClause.Occur clause = BooleanClause.Occur.MUST;
-                                       if (operator.equals("OR")) {
-                                               clause = BooleanClause.Occur.SHOULD;
-                                       }
-                                       String[] word = title.split(" ");
-                                       for (int j = 0; j < word.length; j++) {
-                                               critext.add(new TermQuery(input.createTerm(word[j])),
-                                                               clause);
-                                       }
-                                       query.add(critext, BooleanClause.Occur.MUST);
-                               }
-                               List<SimulationContext> context = kprop[i]
-                                               .getSimulationContexts();
-                               if (context != null && context.size() > 0) {
-                                       BooleanQuery critext = new BooleanQuery();
-                                       for (Iterator<SimulationContext> j = context.iterator(); j
-                                                       .hasNext();) {
-                                               SimulationContext seltext = j.next();
-                                               input = new Term(String.valueOf(seltext.getType()
-                                                               .getIndex()));
-                                               critext.add(new TermQuery(input.createTerm(seltext
-                                                               .getValue())), BooleanClause.Occur.MUST);
-                                       }
-                                       query.add(critext, BooleanClause.Occur.MUST);
-                               }
-                               fulquery.add(query, BooleanClause.Occur.SHOULD);
-                       }
-                       if (LOG.isInfoEnabled()) {
-                               LOG.info("Searching knowledges by Lucene query \""
-                                               + fulquery.toString());
-                       }
-                       // Creation of the knowledge filter
-                       BooleanFilter filter = new BooleanFilter();
-                       TermsFilter select = new TermsFilter();
-                       Term mytype = new Term("class");
-                       select.addTerm(mytype.createTerm("KnowledgeElement"));
-                       filter.add(new FilterClause(select, BooleanClause.Occur.SHOULD));
-
-                       // Creation of the sort criteria
-                       Sort sort = new Sort(new SortField("title", SortField.STRING));
-
-                       // Search
-                       TopFieldDocs found = searcher.search(fulquery, filter, hitsize,
-                                       sort);
-
-                       if (found.totalHits < 1) {
-                               return result; // No study found
-                       }
-
-                       // Construction of the result list
-                       ScoreDoc[] hits = found.scoreDocs;
-                       for (int i = 0; i < hits.length; i++) {
-                               result.add(new IndexServiceImpl.ObjectProxy(searcher
-                                               .doc(hits[i].doc)));
-                       }
-                       searcher.close();
-               } catch (Exception error) {
-                       LOG.error("Error during Lucene search, reason:", error);
-               }
-               return result;
-       }
-
        /**
         * {@inheritDoc}
         * 
@@ -433,7 +304,7 @@ public class SearchServiceImpl implements SearchService {
                } else { // OR
                        topJunction = Restrictions.disjunction();
                }
-               if (!StudySearchFilterDTO.ANY_STATE.equals(filter.getState())) {
+               if (!SearchFilterDTO.ANY_STATE.equals(filter.getState())) {
                        ProgressState state = ProgressState.valueOf(filter.getState()); // State
                        if (state != null) {
                                topJunction.add(Restrictions.eq("state", state));
@@ -444,7 +315,17 @@ public class SearchServiceImpl implements SearchService {
                        topJunction.add(Restrictions.eq("sid", refid));
                }
 
-               addDatesCriteria(topJunction, filter);
+               // Filter by creation date
+               addCreationDateCriteria(topJunction, filter, "credate");
+               // Filter by modification date
+               if (filter.getUpdatedAfter() != null) {
+                       topJunction.add(Restrictions
+                                       .gt("lasdate", filter.getUpdatedAfter()));
+               }
+               if (filter.getUpdatedBefore() != null) {
+                       topJunction.add(Restrictions.lt("lasdate", filter
+                                       .getUpdatedBefore()));
+               }
 
                // Filter by study author
                long authorId = Long.valueOf(filter.getAuthor());
@@ -476,6 +357,13 @@ public class SearchServiceImpl implements SearchService {
                        topJunction.add(Restrictions.eq("kelm.type.rid", ktypeId));
                }
 
+               if (!SearchFilterDTO.ANY_STATE.equals(filter.getState())) {
+                       ProgressState state = ProgressState.valueOf(filter.getState()); // State
+                       if (state != null) {
+                               topJunction.add(Restrictions.eq("kelm.state", state));
+                       }
+               }
+
                String refid = filter.getReference(); // Reference
                if (refid != null && !refid.isEmpty()) {
                        long id = Long.valueOf(refid.replaceAll("^KE(0)*", ""));
@@ -521,7 +409,12 @@ public class SearchServiceImpl implements SearchService {
                                                                        /* If the user is a validation cycle participant */
                                                                        Restrictions
                                                                                        .sqlRestriction(
-                                                                                                       "{alias}.rid in (select vcrel.owner from cycle_rel vcrel inner join cycle vc on vcrel.refer = vc.rid where {alias}.rid = vcrel.owner AND (vc.publisher = ? OR vc.reviewer = ? OR vc.approver = ? OR vc.signatory = ?) group by vcrel.owner)",
+                                                                                                       "{alias}.rid in ("
+                                                                                                                       + "select vcrel.owner from cycle_rel vcrel "
+                                                                                                                       + "inner join cycle vc on vcrel.refer = vc.rid "
+                                                                                                                       + "where {alias}.rid = vcrel.owner "
+                                                                                                                       + "AND (vc.publisher = ? OR vc.reviewer = ? OR vc.approver = ? OR vc.signatory = ?) "
+                                                                                                                       + "group by vcrel.owner)",
                                                                                                        new Object[] { actorId,
                                                                                                                        actorId, actorId,
                                                                                                                        actorId },
@@ -534,7 +427,9 @@ public class SearchServiceImpl implements SearchService {
                                                                        /* If the user is contributor */
                                                                        Restrictions
                                                                                        .sqlRestriction(
-                                                                                                       "{alias}.rid in (select rel.owner from contributor_rel rel where {alias}.rid = rel.owner AND rel.refer = ?)",
+                                                                                                       "{alias}.rid in ("
+                                                                                                                       + "select rel.owner from contributor_rel rel "
+                                                                                                                       + "where {alias}.rid = rel.owner AND rel.refer = ?)",
                                                                                                        actorId, Hibernate.LONG))
                                                        .add(
                                                        /* If the user is author */
@@ -557,41 +452,19 @@ public class SearchServiceImpl implements SearchService {
         *            the junction filter condition
         * @param filter
         *            search criteria
-        */
-       private void addDatesCriteria(final Junction topJunction,
-                       final StudySearchFilterDTO filter) {
-               // Filter by creation date
-               addCreationDateCriteria(topJunction, filter, "credate");
-               // Filter by modification date
-               if (filter.getUpdatedAfter() != null) {
-                       topJunction.add(Restrictions
-                                       .gt("lasdate", filter.getUpdatedAfter()));
-               }
-               if (filter.getUpdatedBefore() != null) {
-                       topJunction.add(Restrictions.lt("lasdate", filter
-                                       .getUpdatedBefore()));
-               }
-
-       }
-
-       /**
-        * Add search criteria by dates to the junction filter condition.
-        * 
-        * @param topJunction
-        *            the junction filter condition
-        * @param filter
-        *            search criteria
+        * @param propName
+        *            creation date property name
         */
        private void addCreationDateCriteria(final Junction topJunction,
                        final SearchFilterDTO filter, final String propName) {
                // Filter by creation date
                if (filter.getCreatedAfter() != null) {
-                       topJunction.add(Restrictions
-                                       .gt(propName, filter.getCreatedAfter()));
+                       topJunction
+                                       .add(Restrictions.gt(propName, filter.getCreatedAfter()));
                }
                if (filter.getCreatedBefore() != null) {
-                       topJunction.add(Restrictions.lt(propName, filter
-                                       .getCreatedBefore()));
+                       topJunction.add(Restrictions
+                                       .lt(propName, filter.getCreatedBefore()));
                }
        }
 
index 1fd296e5b5b84c9db84a44b2537aaf40a8f024fa..81cf39681b25214861fb14d8ab968e35d883b491 100644 (file)
@@ -14,6 +14,7 @@ import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
 
+import org.splat.dal.bo.som.ProgressState;
 import org.splat.dal.bo.som.SimulationContext;
 
 /**
@@ -31,6 +32,10 @@ public class SearchFilterDTO {
         * "any": match any criteria.
         */
        public final static String MATCH_ANY = "any";
+       /**
+        * "ANY": match any status.
+        */
+       public final static String ANY_STATE = "ANY";
        /**
         * Study author id to search.
         */
@@ -67,6 +72,10 @@ public class SearchFilterDTO {
         * Currently connected user id.
         */
        private long _connectedUserId = 0;
+       /**
+        * "In-Work", "In-Draft", "In-Check"...
+        */
+       private String _state = ANY_STATE;
 
        /**
         * Get author id of objects to find.
@@ -259,4 +268,37 @@ public class SearchFilterDTO {
        public void setConnectedUserId(final long connectedUserId) {
                _connectedUserId = connectedUserId;
        }
+
+       // ==============================================================================================================================
+       // Getters
+       // ==============================================================================================================================
+       
+       /**
+        * Get progress state criteria.
+        * 
+        * @return study progress state to search
+        */
+       public String getState() {
+               return _state;
+       }
+
+       /**
+        * Set progress state criteria.
+        * 
+        * @param value
+        *            the progress state to search
+        */
+       public void setState(final String value) {
+               this._state = value;
+       }
+       
+       /**
+        * Set progress state criteria.
+        * 
+        * @param value
+        *            the progress state to search
+        */
+       public void setState(final ProgressState value) {
+               this._state = value.toString();
+       }
 }
index f83c171823a00ce5179deb5e76d290aa9db6b71b..4ee3972c3dfcd9a51bf3682b76cd17651d5ddc36 100644 (file)
@@ -19,14 +19,6 @@ import java.util.Date;
  */
 public class StudySearchFilterDTO extends SearchFilterDTO {
 
-       /**
-        * "ANY": match any status.
-        */
-       public final static String ANY_STATE = "ANY";
-       /**
-        * "In-Work", "In-Draft", "In-Check"...
-        */
-       private String _state = ANY_STATE;
        /**
         * Search studies updated after this date.
         */
@@ -40,25 +32,6 @@ public class StudySearchFilterDTO extends SearchFilterDTO {
        // Getters
        // ==============================================================================================================================
        
-       /**
-        * Get progress state criteria.
-        * 
-        * @return study progress state to search
-        */
-       public String getState() {
-               return _state;
-       }
-
-       /**
-        * Set progress state criteria.
-        * 
-        * @param value
-        *            the progress state to search
-        */
-       public void setState(final String value) {
-               this._state = value;
-       }
-
        /**
         * Get the updatedAfter.
         * 
index d4cc3b99b0f9b572499050e47c2cae36b4831955..43cc310ed433d94ae8c9326d8779408de6426f77 100644 (file)
@@ -21,6 +21,7 @@ import org.splat.dal.dao.som.Database;
 import org.splat.service.KnowledgeElementService;
 import org.splat.service.SearchService;
 import org.splat.service.SimulationContextService;
+import org.splat.service.dto.KnowledgeSearchFilterDTO;
 import org.splat.service.dto.Proxy;
 import org.splat.service.dto.SimulationContextFacade;
 import org.splat.service.technical.ProjectSettingsService;
@@ -190,10 +191,15 @@ public class SimulationContextAction extends Action {
                                _tocheck.add(new SimulationContextFacade(next,
                                                getProjectSettings().getAllSteps()));
                        }
-                       KnowledgeElement.Properties kprop = new KnowledgeElement.Properties();
-                       List<Proxy> kelm = getSearchService().selectKnowledgeElementsWhere(
-                                       kprop.setSimulationContexts(selected).setState(
-                                                       ProgressState.inWORK));
+//                     KnowledgeElement.Properties kprop = new KnowledgeElement.Properties();
+//                     List<Proxy> kelm = getSearchService().selectKnowledgeElementsWhere(
+//                                     kprop.setSimulationContexts(selected).setState(
+//                                                     ProgressState.inWORK));
+                       KnowledgeSearchFilterDTO knowFilter = new KnowledgeSearchFilterDTO();
+                       knowFilter.setSimContexts(selected);
+                       knowFilter.setState(ProgressState.inWORK);
+                       List<Proxy> kelm = getSearchService().selectKnowledgeElementsWhere(knowFilter);
+                                       
 
                        _step = getSimulationContextService().getAttachedStep(
                                        _edition.getType());