cancel
Showing results for 
Search instead for 
Did you mean: 

2.9B Lucene search implementation question

fhomasp
Champ in-the-making
Champ in-the-making
Hey,

Somehow there is something wrong when I use the Lucene search implemented in the SDK and it does work differently compared to the one used by the web client.

Its behaviour is really strange and produces different results when running the same query multiple times.
I just changed the search string in one of the webservice examples to test for content I added.  Sometimes it produces absolutely nothing, then running the search again does produce the required result.  I have no idea what's causing this.
And something else…  I do need to use more than a certain number of characters to search on.  If I use a search string of for ex. 4 characters the resultset is always empty.  So obviously a minimum required character count is implemented.
How do I change this?  As this clearly isn't the case when using the advanced or simple search in the web client.

Thanks
1 REPLY 1

fhomasp
Champ in-the-making
Champ in-the-making
So in order to search for existing files I need to use the "*" to find all files from a given dir in alfresco and then compare it to the file I need.
This is rather important as certain files(types) are set for versioning enabled while others are not.  I need to do this for getting content from the repo as well as writing content to the repo. 
Eventhough this is a Thesis assignment I would like to get the better performing solution.

Here are my methods for getting content as well as writing/updating.
Never mind some of the comments as I tested and played with it for some time Smiley Happy
Also never mind the getSerializedData method name.  I used to just use serialization but now I stepped away from that approach and write the classes as XML converted files in a central repo location, hidden from non-admin users.

public static boolean writeXML(OutputStream os, String firstName, String lastName ) throws Exception
       {
        // Start the session
         try{  AuthenticationUtils.startSession(USERNAME, PASSWORD);
        
         } catch(AuthenticationFault af)
         {
            System.out.println("authentication failed!");
         }
           List<GenericData> lijst;
         //filename for the document
           String filename = lastName+"_"+firstName+".xml";
          
           // what kind of file is it?
           String filetype = "text/xml";
                
             try {
               
              
                // get classification Service
                ClassificationServiceSoapBindingStub classificationService = WebServiceFactory.getClassificationService();
                ContentServiceSoapBindingStub contentService =WebServiceFactory.getContentService();
    
                //create the parentReference
                ParentReference parentReference = new ParentReference(STORE, null, xmlLocation ,ASSOC_CONTAINS, ASSOC_CONTAINS);
               
               
                       
               
                NamedValue[] properties = new NamedValue[1];
                NamedValue contentName = Utils.createNamedValue(Constants.PROP_NAME,lastName+"_"+firstName+".xml" );
                properties[0] = contentName;
              
                CMLCreate create = new CMLCreate("1", parentReference, null, null, null, Constants.TYPE_CONTENT, properties);
                CML cml = new CML();
                cml.setCreate(new CMLCreate[]{create});
               
                Predicate predicate = new Predicate(new Reference[]{parentReference}, null, null);
        
                UpdateResult[] result;
            
              
              
              RepositoryServiceSoapBindingStub repositoryService =WebServiceFactory.getRepositoryService();
              
              Query query = new Query();
              query.setLanguage("lucene");
   /*The referenced Query statement is using "*" for finding all files.  This is because I couldn't seem to get correct results by using the Lucene
search implemented by the SDK while searching for a specific file.  This might be a bug because even copy-pasting it from the Nodebrowser wouldn't do the trick in every
situation */
              query.setStatement("PATH:\""+parentReference.getPath()+"/*"+"\"");
              
              System.out.println(query.getStatement());
              
              
              ResultSet rs = repositoryService.query(STORE, query, true).getResultSet();
              Reference queryRef;
              if(rs.getTotalRowCount()> 0 )
              {
                 ResultSetRow [] rows = rs.getRows();
                 for(ResultSetRow rowke : rows)
                 {
                    int q = 0;
                    for(int i = 0;i<rowke.getColumns().length;i++)
                    {
                       System.out.println(rowke.getColumns(i).getValue());
                       if(rowke.getColumns(i).getValue().equalsIgnoreCase(filename))
                       {
                          queryRef = new Reference(STORE, rowke.getNode().getId(), null);
                          System.out.println("Ik ben hier geraakt dus ik heb het fileke gevonden!");
                          cml = new CML();
                          Predicate queryPredicate = new Predicate(new Reference[]{queryRef},null,null);
                          CMLUpdate cmlupdate = new CMLUpdate(properties,queryPredicate, null);
                          cml.setUpdate(new CMLUpdate[]{cmlupdate});
                          //deleteRepoFile(queryRef);
                       }
                    }
                    q++;
                    
                 }
              }
              
                result = WebServiceFactory.getRepositoryService().update(cml);
               
                int i = 0;
                Reference testRef;
             
              
                         
                // Get the created node and create the format
                Reference newContentNode = result[0].getDestination();
                           
               
                             
                ContentFormat format = new ContentFormat(filetype, "UTF-8"); 
                ByteArrayOutputStream bao = (ByteArrayOutputStream)os;
           
               
                byte[] bytes = bao.toByteArray();
                
                
                // Write the content
                WebServiceFactory.getContentService().write(newContentNode, Constants.PROP_CONTENT, bytes, format);
                
              
               // Predicate predicate = new Predicate("rls:city",titledProps,new Reference[]{newContentNode}, "1");
              
           
                
                  } catch (Exception e) {
              e.printStackTrace();
              return false;
           } finally {
              AuthenticationUtils.endSession();
            
              return true;
           }
       
      }
   
    public static InputStream getSerializedData(String firstName,String lastName)
    {
      
      
       ObjectInputStream ois = null;
       try {
          AuthenticationUtils.startSession(USERNAME, PASSWORD);
       }catch(AuthenticationFault af)
       {
          System.out.println("Invalid Credentials");
       }
      
       Content [] content=null;
       ParentReference parentReference = new ParentReference(STORE, null, WriteFileWS.xmlLocation ,ASSOC_CONTAINS, ASSOC_CONTAINS);
       Reference queryRef=null;
       if(WriteFileWS.testHomeExists(parentReference))
       {
          Query query = new Query();
          query.setLanguage("lucene");
          query.setStatement("PATH:\""+parentReference.getPath()+"/*"+"\"");
          //werkt echt ni! –>query.setStatement("PATH:\""+parentReference.getPath()+"/{http://www.alfresco.org/model/content/1.0}name'\''Change_x0020_CV'+'\"");
          System.out.println(query.getStatement());
        
        
        
          RepositoryServiceSoapBindingStub repositoryService =WebServiceFactory.getRepositoryService();
          ResultSet rs=null;
          try {
                 rs = repositoryService.query(STORE, query, true).getResultSet();
          }catch (RepositoryFault rf)
          {
            
          }catch(RemoteException re)
          {
            
          }
         
         
          if(rs.getTotalRowCount()> 0 )
          {
             boolean beenhere = false;
             ResultSetRow [] rows = rs.getRows();
             for(ResultSetRow rowke : rows)
             {
                int q = 0;
               
                for(int i = 0;i<rowke.getColumns().length;i++)
                {
                   System.out.println(rowke.getColumns(i).getValue()+"\t"+q+"\t"+i);
                   if(rowke.getColumns(i).getValue().equals(lastName+"_"+firstName+".xml"))
                   {
                      queryRef = new Reference(STORE, rowke.getNode().getId(), null);
                      System.out.println("Ik ben hier geraakt dus ik heb het fileke gevonden!");
                      beenhere=true;
                     // break;   //TODO comment the break statement if situation got worse!
                    
                   }
                   else if(beenhere==false)
                   {
                      queryRef = null;
                   }
                }
                q++;
              
             }
          }
       } else
       {
          System.out.println("User Home Does not Exist!");
          //TODO Misschien deze <h:message> returnen naar de bean met getFacesContext() implementatie?
          return null;
       }
      
       if(queryRef!=null)
       {
          Predicate predicate = new Predicate(new Reference[]{queryRef}, STORE, null);
      
          try {
                content = WebServiceFactory.getContentService().read(predicate, Constants.PROP_CONTENT);
          }catch(ContentFault cf)
          {
             //no stacktrace or action required.
          }catch(RemoteException re)
          {
             //no stacktrace or action required.
          }
         
          System.out.println(content[0].getLength());
         
           return ContentUtils.getContentAsInputStream(content[0]);
       }
       System.out.println("No matching file found!");
       return null;
    }