String queryOut="+ID:\""+ nodeRef.toString()+"\" ";
query = query + " TEXT:\"+"+chktg.trim()+"\" ";
inconvénient je recherche sur tous les nœuds du repository.
public static boolean searchInNodeRef(NodeRef nodeRef, String tags, NodeService nodeService, SearchService searchService ) {
boolean returned=false;
ContentData contentData = (ContentData) nodeService.getProperty(nodeRef,ContentModel.PROP_CONTENT);
Locale locale = contentData.getLocale();
SearchParameters searchParameters= new SearchParameters();
searchParameters.setLanguage(SearchService.LANGUAGE_LUCENE);
searchParameters.addStore(nodeRef.getStoreRef());
if (locale != null ) {
searchParameters.addLocale(locale);
}
String queryOut="+ID:\""+ nodeRef.toString()+"\" ";
String query="";
if (tags == null || tags.length() <= 0) {
return returned;
}
String tagsAnd = "";
String tagsOr = "";
StringTokenizer tokenizer = new StringTokenizer(tags, ",");
while (tokenizer.hasMoreTokens()) {
String chktg=tokenizer.nextToken();
if ( chktg.substring(0, 1).compareTo("+") == 0 ) {
tagsAnd = tagsAnd + chktg.substring(1, chktg.length()) + " ";
} else {
tagsOr = tagsOr + chktg + " ";
}
}
if ( tagsAnd.length() > 0 ) {
tokenizer = new StringTokenizer(tagsAnd, " ");
while (tokenizer.hasMoreTokens()) {
String chktg=tokenizer.nextToken();
query = query + " TEXT:\"+"+chktg.trim()+"\" ";
}
}
if ( tagsOr.length() > 0 ) {
query = query + " +( ";
tokenizer = new StringTokenizer(tagsOr, " ");
while (tokenizer.hasMoreTokens()) {
String chktg=tokenizer.nextToken();
query = query + " TEXT:\""+chktg.trim()+"\" ";
}
query = query + " )";
}
queryOut= queryOut + " " + query.trim();
searchParameters.setQuery( queryOut.trim() );
// Transform the results into a node list
ResultSet results = null;
try {
results = searchService.query(searchParameters);
for (ResultSetRow row : results) {
if (nodeRef.getId().compareTo(row.getNodeRef().getId()) == 0) {
returned = true;
}
}
}
finally {
if (results != null) {
results.close();
}
}
return returned;
}
@sys\:node-uuid:(fef01cce-7dbe-11dd-b66d-db7edbe1ff00)
Tu as essayé de tester ta requête combinant ID et TEXT directement dans le NodeBrowser ?oui mais je me suis apperçu que le document qui arrive dans un workflow n'est pas encore indexé … donc pas de recherche
Si ID ne marche pas comme attendu, tu peux toujours utiliser sys:node-uuid à la place :déja testé , même effet …@sys\:node-uuid:(fef01cce-7dbe-11dd-b66d-db7edbe1ff00)
oui mais je me suis apperçu que le document qui arrive dans un workflow n'est pas encore indexé … donc pas de recherche
import java.io.StringReader;
import java.util.StringTokenizer;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.search.Searcher;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.ScoreDoc;
import org.apache.lucene.search.TopDocCollector;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.RAMDirectory;
import org.apache.lucene.queryParser.QueryParser;
public class LuceneSearcher {
private String ID;
private Directory indexDirectory;
/**
*
* @param workingNode
* @throws Exception
*/
public LuceneSearcher(NodeRef workingNode ,ReaderString readerText ) throws Exception {
this.indexDirectory = new RAMDirectory();
IndexWriter writer = new IndexWriter(this.indexDirectory, getAnalyzer(), true);
Document doc = new Document();
Field idField = new Field("ID", workingNode.getId());
doc.add(idField);
this.ID=workingNode.getId();
Field textField = new Field("TEXT", readerText);
doc.add(textField);
writer.addDocument(doc);
writer.close();
}
protected Analyzer getAnalyzer() {
return new StandardAnalyzer();
}
public boolean searchInDocument(String values ) throws Exception {
IndexReader reader = IndexReader.open(this.indexDirectory);
TopDocCollector collector = new TopDocCollector(100);
Searcher searcher = new IndexSearcher(reader);
Analyzer analyzer = getAnalyzer();
String field = "ID";
QueryParser parser = new QueryParser(field, analyzer);
String queryValue="ID:\""+this.ID+"\";
queryValue=queryValue+" AND ";
queryValue=queryValue+" ( ";
queryValue=queryValue+" TEXT:"+values;
queryValue=queryValue+" ) ";
Query query = parser.parse(queryValue);
searcher.search(query, collector);
ScoreDoc[] hits = collector.topDocs().scoreDocs;
searcher.close();
if ( hits.length > 0 )
return true;
return false;
}
}
Content from pre 2016 and from language groups that have been closed.
Content is read-only.
By using this site, you are agreeing to allow us to collect and use cookies as outlined in Alfresco’s Cookie Statement and Terms of Use (and you have a legitimate interest in Alfresco and our products, authorizing us to contact you in such methods). If you are not ok with these terms, please do not use this website.