File content search right after upload
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-23-2007 03:55 PM
I am working on a unit test (using web services api) where I :
1. Upload a file (say a copy of Alfresco-Tutorial.pdf and set its mimetype to application/pdf)
2. Search for a certain content that I know exists in the file
And it doesn't work…:?
Doing the same thing in the web client doesn't work either, I have to browse a little (to Company Home for example) for it to work.
After a while, it works using the ws api too.
What might cause this delay? (before the indexing of the file??)
Is there a way I could do something in my test that would trigger the change, some kind of refresh?
Anyone in the same situation?
Thanks!
1. Upload a file (say a copy of Alfresco-Tutorial.pdf and set its mimetype to application/pdf)
2. Search for a certain content that I know exists in the file
And it doesn't work…:?
Doing the same thing in the web client doesn't work either, I have to browse a little (to Company Home for example) for it to work.
After a while, it works using the ws api too.
What might cause this delay? (before the indexing of the file??)
Is there a way I could do something in my test that would trigger the change, some kind of refresh?
Anyone in the same situation?
Thanks!
Labels:
- Labels:
-
Archive
1 REPLY 1
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-23-2007 06:03 PM
I think it's the indexing time… it takes a minute or so to index Alfresco-Tutorial.pdf.
Here is the code I execute once. It prints the number of file containing the phrase "Alfresco Logo".
(I did not include the exists, delete, createContent, etc. methods in there)
The uploaded file doesn't exist in the result after the first execution.
(Let's say I get File Found : 1 because Alfresco-Tutorial.pdf already exists in Guest Home)
I comment out the clean and upload part and execute it a few more times, then after a while, it does count the uploaded file in the result. (File Found : 2)
Here is the code I execute once. It prints the number of file containing the phrase "Alfresco Logo".
(I did not include the exists, delete, createContent, etc. methods in there)
The uploaded file doesn't exist in the result after the first execution.
(Let's say I get File Found : 1 because Alfresco-Tutorial.pdf already exists in Guest Home)
I comment out the clean and upload part and execute it a few more times, then after a while, it does count the uploaded file in the result. (File Found : 2)
public class Test { /** * Store for all spaces */ private final static Store STORE = new Store(Constants.WORKSPACE_STORE, "SpacesStore"); private final static String username = "admin"; private final static String password = "admin"; public static void main(String[] args) { new Test(); } public Test() { String path = "/"; String file = "Alfresco-Tutorial.pdf"; String where = "/app:company_home"; String xPathFile = where + path + "cm:" + file; String mimetype = "application/pdf"; try { // Authentication AuthenticationUtils.startSession(username, password); // Clean if (exists(xPathFile)) { delete(xPathFile); } // Upload InputStream is = new FileInputStream(Test.class.getResource(path + file).getPath()); Reference contentRef = createContent(where, file); ContentFormat format = new ContentFormat(mimetype, "UTF-8"); setContent(contentRef, format, is); // Search for phrase "Alfresco Logo" which exists in Alfresco-Tutorial.pdf String statement = "TYPE:\"{http://www.alfresco.org/model/content/1.0}content\"" + " AND (@\\{http\\://www.alfresco.org/model/content/1.0\\}name:\'Alfresco Logo\"" + " TEXT:\"Alfresco Logo\"))"; // Search Query query = new Query(Constants.QUERY_LANG_LUCENE, statement); QueryResult results = WebServiceFactory.getRepositoryService().query(STORE, query, true); System.out.println("File found: " + results.getResultSet().getTotalRowCount()); } catch (Exception e) { e.printStackTrace(); } finally { AuthenticationUtils.endSession(); } }}
