cancel
Showing results for 
Search instead for 
Did you mean: 

Lucene Search for the exact file

junieboy
Champ in-the-making
Champ in-the-making
Hi,

I'm having a problem with using the Lucene search. Assuming I am searching for a file named alfresco-test.txt, all other files such as
alfresco–test.txt
alfresco test.txt

are also in the result.

queryString: +@cm\:name:"alfresco-test.txt" +PATH:"/app:company_home/st:sites/cm:ERIS/cm:documentLibrary/cm:roopesh/cm:kumar/cm:kunchala/*"

Assuming
String fileName = "alfresco-test.txt";
String xpath = "/app:company_home/st:sites/cm:ERIS/cm:documentLibrary/cm:roopesh/cm:kumar/cm:kunchala";

I'd like to get only alfresco-test.txt as the result of my query. What needs to change in my query?

I've learned from the wiki http://wiki.alfresco.com/wiki/Search

To find all nodes with the cm:name property containing the word banana:

@cm\:name:"banana"

But what if I want to search for the file with the exact cm:name property with the value banana only? How do I do this?


Below is my code for the Alfresco Search
   public Reference searchByPathAndFileName(String xpath, String filename) throws Exception{       log.info("start call to AlfrescoSearch.searchByPathAndFileName");      Reference ref = null;            if(!xpath.endsWith("/")) {         xpath = xpath.concat("/");      }      String queryString = "+@cm\\:name:\"" + filename + "\" +PATH:\""+ xpath +  "*\"";      log.info("queryString: " + queryString);      getQueryResults(queryString);            Query query = new Query(Constants.QUERY_LANG_LUCENE, queryString);            /* Execute the query */      QueryResult queryResult = WebServiceFactory.getRepositoryService().query(getStoreRef(), query, false);              /* Display the results */        ResultSet resultSet = queryResult.getResultSet();        ResultSetRow[] rows = resultSet.getRows();                if (rows != null) {            /* Get the infomation from the result set */                      Map<String, String> namedValuesMap = null;            for(ResultSetRow row : rows) {                String nodeId = row.getNode().getId();                log.info("nodeId of the file found: " + nodeId);                ref = new Reference(getStoreRef(), nodeId, null);//                ContentResult contentResult = new ContentResult(nodeId);                            NamedValue[] namedValues = row.getColumns();                log.info("number of properties: " + namedValues.length);                                namedValuesMap = new HashMap<String, String>();                // iterate through the columns of the result set to extract specific named values                                for (NamedValue namedValue : namedValues) {                   log.debug("named value property: " + namedValue.getName());                   log.debug("named value value: " + namedValue.getValue());                    namedValuesMap.put(namedValue.getName(), namedValue.getValue());                }            } //next row                        String name = namedValuesMap.get("{http://www.alfresco.org/model/content/1.0}name");            log.info("Got file name: " + name);                        String uuid = namedValuesMap.get("{http://www.alfresco.org/model/system/1.0}node-uuid");            log.info("Got file uuid: " + uuid);                        String versionable = namedValuesMap.get("{http://www.alfresco.org/model/content/1.0}versionable");            log.info("Got versionable: " + versionable);                    } // end if        log.info("done call to AlfrescoSearch.searchByPathAndFileName");        return ref;   }      public Reference searchByPath(String xpath) throws Exception {      Reference ref = null;            if(!xpath.endsWith("/")){         xpath = xpath.concat("/");      }            String queryString = "+PATH:\"/app:company_home/st:sites/cm:CostAllocation/cm:documentLibrary/*\"";      Query query = new Query(Constants.QUERY_LANG_LUCENE, queryString);            /* Execute the query */      QueryResult queryResult = WebServiceFactory.getRepositoryService().query(getStoreRef(), query, false);              /* Display the results */        ResultSet resultSet = queryResult.getResultSet();        ResultSetRow[] rows = resultSet.getRows();                if (rows != null) {            /* Get the infomation from the result set */                      Map<String, String> namedValuesMap = null;            for(ResultSetRow row : rows) {                String nodeId = row.getNode().getId();                ref = new Reference(getStoreRef(), nodeId, null);                NamedValue[] namedValues = row.getColumns();                                namedValuesMap = new HashMap<String, String>();                // iterate through the columns of the result set to extract specific named values                                for (NamedValue namedValue : namedValues) {                    namedValuesMap.put(namedValue.getName(), namedValue.getValue());                }                String path = namedValuesMap.get("{http://www.alfresco.org/model/content/1.0}path");                path = path.replace("/{http://www.alfresco.org/model/application/1.0}", "/app:");                path = path.replace("/{http://www.alfresco.org/model/site/1.0}", "/st:");                path = path.replace("/{http://www.alfresco.org/model/content/1.0}", "/cm:");                log.info("path: " + path);                            } //next row                    } // end if                return ref;   }       private List<ContentResult> getQueryResults(String queryString) throws Exception {       log.info("Query:" + queryString);               List<ContentResult> results = new ArrayList<ContentResult>();                Query query = new Query(Constants.QUERY_LANG_LUCENE, queryString);        // Execute the query        QueryResult queryResult = WebServiceFactory.getRepositoryService().query(getStoreRef(), query, false);                // Display the results        ResultSet resultSet = queryResult.getResultSet();        ResultSetRow[] rows = resultSet.getRows();                if (rows != null) {            // Get the infomation from the result set            for(ResultSetRow row : rows) {                String nodeId = row.getNode().getId();                ContentResult contentResult = new ContentResult(nodeId);                            NamedValue[] namedValues = row.getColumns();                log.info("number of properties: " + namedValues.length);                                Map<String, String> namedValuesMap = new HashMap<String, String>();                // iterate through the columns of the result set to extract specific named values                                for (NamedValue namedValue : namedValues) {                   log.debug("named value property: " + namedValue.getName());                    namedValuesMap.put(namedValue.getName(), namedValue.getValue());                }                                String uuid = namedValuesMap.get("{http://www.alfresco.org/model/system/1.0}node-uuid");                log.info("Got file uuid: " + uuid);                if(uuid != null){                                   }                                                // Use the content service to figure out the URL                Content[] readResult = WebServiceFactory.getContentService().read(new Predicate(new Reference[]{new Reference(getStoreRef(), nodeId, null)}, getStoreRef(), null), Constants.PROP_CONTENT);                Content content = readResult[0];                contentResult.setUrl(content.getUrl());                  results.add(contentResult);            } //next row        } // end if                return results;    }        public Store getStoreRef() {       Store storeRef = new Store(Constants.WORKSPACE_STORE, "SpacesStore");       return storeRef;    }‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
1 REPLY 1

sanket
Champ on-the-rise
Champ on-the-rise