cancel
Showing results for 
Search instead for 
Did you mean: 

Lucene search in Java Backed Webscript

toze
Champ in-the-making
Champ in-the-making
Hi, im having some problems doing a simple search with Lucene in a Java Backed Webscript

im trying this

String query ="PATH:\"/app:company_home/cm:TestFolder//*\"";
StoreRef storeRef = new StoreRef(StoreRef.PROTOCOL_WORKSPACE,"SpacesStore");

ResultSet results = searchService.query(storeRef, SearchService.LANGUAGE_LUCENE, query);
   
   for (ResultSetRow row : results) {
      NodeRef currentNodeRef = row.getNodeRef();
      lista.add(currentNodeRef.toString());

   }

if i execute teh query in Alfresco Node Browser it works, so the query is good.
What im doing wrong?

Thanks in advanced
4 REPLIES 4

toze
Champ in-the-making
Champ in-the-making
Problem Solved

zaizi
Champ in-the-making
Champ in-the-making
For the benefit of others would be useful to post your solution.

Ainga

toze
Champ in-the-making
Champ in-the-making
SearchParameters sp = new SearchParameters();
StoreRef storeRef = new StoreRef(StoreRef.PROTOCOL_WORKSPACE,"SpacesStore");
sp.addStore(storeRef);
sp.setLanguage(SearchService.LANGUAGE_LUCENE);
sp.setQuery(query);
ResultSet results = null;
try {
   List<String> lista = new ArrayList<String>();
   results = serviceRegistry.getSearchService().query(sp);
   for (ResultSetRow row : results) {
      NodeRef currentNodeRef = row.getNodeRef();
      lista.add(currentNodeRef.toString());
      }
} finally {
      if (results != null) {
      results.close();
   }

here is the way i solved my problem

madnan
Champ in-the-making
Champ in-the-making
I am working on lucene using java code implementation. I have searched a phrase e.g. "Software Engineering, software development" using `ShingleFilter (TokenStream input, int minShingleSize, int maxShingleSize)` from Index directory. Its working well. Output is:
Phrase Searching:software engineering software
   Found 5 hits.
   1. Index Document ID:336 File Name: jucs_243.pdf.txt
   2. Index Document ID:506 File Name: jucs_4.pdf.txt
   3. Index Document ID:524 File Name: jucs_419.pdf.txt
   4. Index Document ID:276 File Name: jucs_189.pdf.txt
   5. Index Document ID:340 File Name: jucs_247.pdf.txt
Phrase Searching:software engineering software development
   Found 1 hits.
   1. Index Document ID:506 File Name: jucs_4.pdf.txt
Phrase Searching:engineering software development
   Found 1 hits.
   1. Index Document ID:506 File Name: jucs_4.pdf.txt
My question is: How many times a single file hits? Which method should I apply which manage the list of
(QueryPhrase:FileID:NoOfHits).
E.g. (software engineering software development: 506:3)
     (software engineering software development: 336:1)
     (software engineering software development: 524:1)
     (software engineering software development: 340:1)


My code is:

// display search results
TopDocs topDocs = searcher.search(query, LuceneConstants.MAX_SEARCH);
ScoreDoc[] hits = topDocs.scoreDocs;
System.out.println("Found " + hits.length + " hits.");
for(int i=0;i<hits.length;++i) {
      int docId = hits.doc; 
     // print some info about where the hit was found… 
      Document d = searcher.doc(docId); 
      System.out.println((i + 1) + ". " +"Index Document ID:"+ docId + "File Name:" + d.get(LuceneConstants.FILE_PATH)); 

}