Author: kmorin Date: 2009-11-10 17:31:10 +0100 (Tue, 10 Nov 2009) New Revision: 318 Modified: wikengo_core-wikitty/wikengo_core-wikitty-solr-impl/core-wikitty-solr-impl.iml wikengo_core-wikitty/wikengo_core-wikitty-solr-impl/pom.xml wikengo_core-wikitty/wikengo_core-wikitty-solr-impl/src/main/java/org/sharengo/wikitty/solr/Restriction2Solr.java wikengo_core-wikitty/wikengo_core-wikitty-solr-impl/src/main/java/org/sharengo/wikitty/solr/WikittyQueryParser.java wikengo_core-wikitty/wikengo_core-wikitty-solr-impl/src/main/java/org/sharengo/wikitty/solr/WikittySearchEngineSolr.java wikengo_core-wikitty/wikengo_core-wikitty-solr-impl/src/main/resources/schema.xml wikengo_core-wikitty/wikengo_core-wikitty-solr-impl/src/test/resources/log4j.properties Log: config solr Modified: wikengo_core-wikitty/wikengo_core-wikitty-solr-impl/core-wikitty-solr-impl.iml =================================================================== --- wikengo_core-wikitty/wikengo_core-wikitty-solr-impl/core-wikitty-solr-impl.iml 2009-11-10 16:30:58 UTC (rev 317) +++ wikengo_core-wikitty/wikengo_core-wikitty-solr-impl/core-wikitty-solr-impl.iml 2009-11-10 16:31:10 UTC (rev 318) @@ -36,6 +36,11 @@ <orderEntry type="library" exported="" name="Maven: woodstox:wstx-asl:3.2.7" level="project" /> <orderEntry type="library" exported="" name="Maven: org.apache.geronimo.specs:geronimo-stax-api_1.0_spec:1.0.1" level="project" /> <orderEntry type="library" exported="" scope="RUNTIME" name="Maven: javax.servlet:servlet-api:2.5" level="project" /> + <orderEntry type="library" exported="" name="Maven: org.nuiton:nuiton-utils:1.1.1" level="project" /> + <orderEntry type="library" exported="" name="Maven: commons-primitives:commons-primitives:1.0" level="project" /> + <orderEntry type="library" exported="" name="Maven: commons-collections:commons-collections:3.2.1" level="project" /> + <orderEntry type="library" exported="" name="Maven: commons-beanutils:commons-beanutils:1.8.0" level="project" /> + <orderEntry type="library" exported="" name="Maven: org.nuiton.i18n:nuiton-i18n-api:1.0.1" level="project" /> </component> </module> Modified: wikengo_core-wikitty/wikengo_core-wikitty-solr-impl/pom.xml =================================================================== --- wikengo_core-wikitty/wikengo_core-wikitty-solr-impl/pom.xml 2009-11-10 16:30:58 UTC (rev 317) +++ wikengo_core-wikitty/wikengo_core-wikitty-solr-impl/pom.xml 2009-11-10 16:31:10 UTC (rev 318) @@ -42,7 +42,14 @@ <groupId>commons-logging</groupId> <artifactId>commons-logging</artifactId> </dependency> + <dependency> + <groupId>org.nuiton</groupId> + <artifactId>nuiton-utils</artifactId> + <version>1.1.1</version> + </dependency> + + <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> </dependency> Modified: wikengo_core-wikitty/wikengo_core-wikitty-solr-impl/src/main/java/org/sharengo/wikitty/solr/Restriction2Solr.java =================================================================== --- wikengo_core-wikitty/wikengo_core-wikitty-solr-impl/src/main/java/org/sharengo/wikitty/solr/Restriction2Solr.java 2009-11-10 16:30:58 UTC (rev 317) +++ wikengo_core-wikitty/wikengo_core-wikitty-solr-impl/src/main/java/org/sharengo/wikitty/solr/Restriction2Solr.java 2009-11-10 16:31:10 UTC (rev 318) @@ -146,7 +146,7 @@ private String associated2solr(AssociatedRestriction associated, SolrServer solr) throws WikittyException { String subQuery = toSolr( associated.getRestriction() ); - SolrQuery query = new SolrQuery(subQuery); + SolrQuery query = new SolrQuery(WikittySearchEngineSolr.SOLR_QUERY_PARSER + subQuery); query.setRows(MAX_SUBQUERY_RESULT); QueryResponse resp = null; try { @@ -162,11 +162,11 @@ throw new WikittyException("Associated " + associated.getElement().getName() + " do not retrieved any result"); } if ( size == 1 ) { - generatedRestriction = RestrictionHelper.eq( associated.getElement(), (String) solrResults.get(0).getFieldValue("id") ); + generatedRestriction = RestrictionHelper.eq( associated.getElement(), (String) solrResults.get(0).getFieldValue(WikittySearchEngineSolr.SOLR_ID) ); } else { List<String> ids = new ArrayList<String>(solrResults.size()); for (SolrDocument doc : solrResults) { - String id = (String) doc.getFieldValue("id"); // FIXME : set a constant field reference + String id = (String) doc.getFieldValue(WikittySearchEngineSolr.SOLR_ID); ids.add(id); } generatedRestriction = new In(associated.getElement(), ids); @@ -236,8 +236,8 @@ private String neq2solr(NotEquals neq) throws WikittyException { - return "( *:* - " + element2solr(neq.getElement()) + ":" - + value2solr(neq.getValue()) + " )"; + return "-" + element2solr(neq.getElement()) + ":" + + value2solr(neq.getValue()); } private String less2solr(Less less) throws WikittyException { @@ -290,27 +290,18 @@ if (contains.getValue().size() < 1) { throw new WikittyException("CONTAINS is an operator that handle 1 operand at least"); } - boolean first = true; + + String operand = ""; StringBuffer result = new StringBuffer(); + result.append("("); for (String value : contains.getValue()) { - if (first) { - result.append("( "); - first = false; - } else { - result.append(" AND "); - } - result.append("( "); + result.append(operand); result.append(element2solr(contains.getElement())) .append(":").append(value2solr(value)); - result.append(" OR "); - result.append(element2solr(contains.getElement())) - .append(":").append(value2solr(value)); - result.append(" OR "); - result.append(element2solr(contains.getElement())) - .append(":").append(value2solr(value)); - result.append(" )"); + operand = " OR "; } - return result.append(" )").toString(); + result.append(")"); + return result.toString(); } private String start2solr(StartsWith start) @@ -351,7 +342,6 @@ result = Restriction2Solr.escapeValue(reverse(value)); } else { result = Restriction2Solr.escapeValue(value); - // result = value; } } else { result = ""; @@ -379,9 +369,8 @@ } private static String escapeValue(String value) { - final String LUCENE_REPLACE_PATTERN = "\\+" + "|-" + "|&&" + "|\\|\\|" - + "|!" + "|\\(|\\)" + "|\\[|\\]" + "|\\{|\\}" + "|\\^" + "|\"" - + "|\\~" + "|\\*" + "|\\?" + "|:" + "|\\\\"; + final String LUCENE_REPLACE_PATTERN = "\\+" + "|-" + "|&&" + "|\\|" + + "|!" + "|\\(|\\)" + "|\\[|\\]" + "|\\{|\\}" + "|\"" + "|:"; return value.replaceAll(LUCENE_REPLACE_PATTERN, "\\\\$0"); } @@ -389,8 +378,9 @@ int i, len = source.length(); StringBuffer dest = new StringBuffer(len); - for (i = (len - 1); i >= 0; i--) + for (i = (len - 1); i >= 0; i--) { dest.append(source.charAt(i)); + } return dest.toString(); } } Modified: wikengo_core-wikitty/wikengo_core-wikitty-solr-impl/src/main/java/org/sharengo/wikitty/solr/WikittyQueryParser.java =================================================================== --- wikengo_core-wikitty/wikengo_core-wikitty-solr-impl/src/main/java/org/sharengo/wikitty/solr/WikittyQueryParser.java 2009-11-10 16:30:58 UTC (rev 317) +++ wikengo_core-wikitty/wikengo_core-wikitty-solr-impl/src/main/java/org/sharengo/wikitty/solr/WikittyQueryParser.java 2009-11-10 16:31:10 UTC (rev 318) @@ -17,7 +17,6 @@ /** * Add allow leading wildcard * setAllowLeadingWildcard(true); - * setLowercaseExpandedTerms(true); * <br>Example: <code>{!wikitty q.op=AND df=text sort='price asc'}myfield:foo +bar -baz</code> * More information @see LuceneQParserPlugin */ @@ -49,9 +48,12 @@ public Query parse() throws ParseException { String defaultField = getParam(CommonParams.DF); + if(defaultField == null) { + defaultField = "text"; + } + lparser = new SolrQueryParser(this, defaultField); lparser.setAllowLeadingWildcard(true); - lparser.setLowercaseExpandedTerms(true); String opParam = getParam(QueryParsing.OP); if (opParam != null) { Modified: wikengo_core-wikitty/wikengo_core-wikitty-solr-impl/src/main/java/org/sharengo/wikitty/solr/WikittySearchEngineSolr.java =================================================================== --- wikengo_core-wikitty/wikengo_core-wikitty-solr-impl/src/main/java/org/sharengo/wikitty/solr/WikittySearchEngineSolr.java 2009-11-10 16:30:58 UTC (rev 317) +++ wikengo_core-wikitty/wikengo_core-wikitty-solr-impl/src/main/java/org/sharengo/wikitty/solr/WikittySearchEngineSolr.java 2009-11-10 16:31:10 UTC (rev 318) @@ -18,14 +18,17 @@ package org.sharengo.wikitty.solr; +import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; +import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.Set; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.solr.client.solrj.SolrQuery; @@ -38,7 +41,7 @@ import org.apache.solr.common.SolrDocumentList; import org.apache.solr.common.SolrInputDocument; import org.apache.solr.core.CoreContainer; -import org.apache.solr.core.SolrCore; +import org.nuiton.util.FileUtil; import org.sharengo.wikitty.Criteria; import org.sharengo.wikitty.FacetTopic; import org.sharengo.wikitty.FieldType; @@ -50,7 +53,7 @@ import org.sharengo.wikitty.WikittyException; import org.sharengo.wikitty.WikittyExtension; import org.sharengo.wikitty.WikittyExtensionStorage; -import org.sharengo.wikitty.WikittySearchEngin; +import org.sharengo.wikitty.WikittySearchEngine; import org.sharengo.wikitty.WikittyTransaction; import org.sharengo.wikitty.search.Search; @@ -62,7 +65,7 @@ * Last update: $Date$ * by : $Author$ */ -public class WikittySearchEngineSolr implements WikittySearchEngin { +public class WikittySearchEngineSolr implements WikittySearchEngine { /** to use log facility, just put in your code: log.info(\"...\"); */ static private Log log = LogFactory.getLog(WikittySearchEngineSolr.class); @@ -84,6 +87,7 @@ static final public String TREENODE_CHILD = TREENODE_PREFIX + "wikittyId"; static final public String TREENODE_EMPTY = TREENODE_PREFIX + "empty"; static final public String TREENODE_ROOT = TREENODE_PREFIX + "root"; + static final public String TREENODE_PATH = TREENODE_PREFIX + "path"; static protected class CommandSolr implements Command { /** if is store command toStore is true, if is delete toStore is false */ @@ -158,15 +162,26 @@ } - /** + protected static class ReindexChildTreeNode extends HashSet<String> { + public static ReindexChildTreeNode getReindexChildTreeNode(WikittyTransaction transaction) { + ReindexChildTreeNode value = (ReindexChildTreeNode) transaction.getTagValue(ReindexChildTreeNode.class); + if(value == null) { + value = new ReindexChildTreeNode(); + transaction.setTagValue(ReindexChildTreeNode.class, value); + } + return value; + } + } + + /** * Store parent for each node and search in index if not known parent */ protected static class ParentMap extends HashMap<String, String> { - protected WikittySearchEngineSolr searchEngineSolr; + protected WikittySearchEngineSolr searchEnginSolr; - public ParentMap(WikittySearchEngineSolr searchEngineSolr) { - this.searchEngineSolr = searchEngineSolr; + public ParentMap(WikittySearchEngineSolr searchEnginSolr) { + this.searchEnginSolr = searchEnginSolr; } @Override @@ -176,7 +191,7 @@ // If not found in map, search in index if(parent == null) { - SolrDocument doc = searchEngineSolr.findById(id); + SolrDocument doc = searchEnginSolr.findById(id); if(doc == null) { // is root return null; @@ -191,11 +206,11 @@ * Add parent map in transaction if is not exists and return it */ public static ParentMap getParentMap( - WikittySearchEngineSolr searchEngineSolr, + WikittySearchEngineSolr searchEnginSolr, WikittyTransaction transaction) { ParentMap value = (ParentMap) transaction.getTagValue(ParentMap.class); if(value == null) { - value = new ParentMap(searchEngineSolr); + value = new ParentMap(searchEnginSolr); transaction.setTagValue(ParentMap.class, value); } return value; @@ -203,7 +218,7 @@ } /** solr server */ - protected SolrServer solrServer; + protected SolrServer solrServer; /** Criteria transformer to solr */ protected Restriction2Solr restriction2Solr; /** Field modifier use to transform to solr format */ @@ -215,6 +230,7 @@ CoreContainer.Initializer initializer = new CoreContainer.Initializer(); CoreContainer coreContainer = initializer.initialize(); solrServer = new EmbeddedSolrServer(coreContainer, ""); + fieldModifier = new TypeFieldModifer(extensionStorage); restriction2Solr = new Restriction2Solr(fieldModifier); @@ -232,18 +248,46 @@ } } + public void changeDataDir(String newDataDir, String oldDataDir) { + try { + if(oldDataDir != null) { + File newFile = new File(newDataDir); + File oldFile = new File(oldDataDir); + FileUtil.copyRecursively(oldFile, newFile); + } + CoreContainer.Initializer initializer = new CoreContainer.Initializer(); + initializer.setSolrConfigFilename(newDataDir); + CoreContainer coreContainer = initializer.initialize(); + solrServer = new EmbeddedSolrServer(coreContainer, ""); + } catch (Exception eee) { + throw new WikittyException(eee); + } + } + public List<Command> prepare(WikittyTransaction transaction, Collection<Wikitty> wikitties) { List<Command> result = new ArrayList<Command>(wikitties.size()); + ReindexChildTreeNode reindexChildTreeNode = ReindexChildTreeNode.getReindexChildTreeNode(transaction); + for (Wikitty w : wikitties) { - // Store known parent in transaction if(w.hasExtension(TreeNode.EXT_TREENODE)) { - ParentMap parentMap = ParentMap.getParentMap(this, transaction); - String wikittyId = w.getId(); - String parentId = w.getFieldAsWikitty( - TreeNode.EXT_TREENODE, TreeNode.FIELD_PARENT); - parentMap.put(wikittyId, parentId); + Set<String> children = w.getFieldAsSet(TreeNode.EXT_TREENODE, TreeNode.FIELD_CHILDREN, String.class); + if(children != null) { + reindexChildTreeNode.addAll(children); + } + + // Search deleted children + String treeNodeId = w.getId(); + SolrDocument treeNodeDoc = findById(treeNodeId); + if(treeNodeDoc != null) { + Collection oldChildren = treeNodeDoc. + getFieldValues(TreeNode.FQ_FIELD_CHILDREN + "_t"); + if(oldChildren != null) { + reindexChildTreeNode.addAll(oldChildren); + } + } + } result.add(new CommandSolr(w)); @@ -251,30 +295,59 @@ return result; } + public List<Command> delete(WikittyTransaction transaction, + List<String> idList) throws WikittyException { + List<Command> result = new ArrayList<Command>(idList.size()); + ReindexChildTreeNode reindexChildTreeNode = ReindexChildTreeNode.getReindexChildTreeNode(transaction); + + try { + for (String id : idList) { + SolrQuery query = new SolrQuery(SOLR_QUERY_PARSER + TREENODE_PREFIX + id + ":*"); + QueryResponse response = solrServer.query(query); + SolrDocumentList updateDocs = response.getResults(); + + for (Iterator<SolrDocument> iterator = updateDocs.iterator(); + iterator.hasNext();) { + SolrDocument solrDocument = iterator.next(); + String childId = (String) solrDocument.getFieldValue(TREENODE_CHILD); + reindexChildTreeNode.add(childId); + } + + result.add(new CommandSolr(id)); + } + } catch (Exception eee) { + throw new WikittyException(eee); + } + + return result; + } + public UpdateResponse commit(WikittyTransaction transaction, List<Command> wikittyIndexationCommandList) { try { + for (Command c : wikittyIndexationCommandList) { CommandSolr cs = (CommandSolr) c; if (cs.toStore) { SolrInputDocument doc = createIndexDocument(cs.wikitty); solrServer.add(doc); - - Collection<SolrInputDocument> docs = createTreeNodeIndex(transaction, cs.wikitty); - if(!docs.isEmpty()) { - solrServer.add(docs); - } - } else { // Delete all reference on tree - solrServer.deleteByQuery(TREENODE_CHILD + ":" + cs.id); - // FIXME: jru 20091027 delete node in middle in tree - solrServer.deleteByQuery(TREENODE_PREFIX + cs.id + ":" + TREENODE_EMPTY); + solrServer.deleteById(TREENODE_PREFIX + cs.id); solrServer.deleteById(cs.id); } } solrServer.commit(); + + // Reindex child in tree node + ParentMap parentMap = ParentMap.getParentMap(this, transaction); + ReindexChildTreeNode reindexChildTreeNode = ReindexChildTreeNode.getReindexChildTreeNode(transaction); + for (String childId : reindexChildTreeNode) { + SolrInputDocument doc = createTreeNodeDocument(parentMap, childId); + solrServer.add(doc); + } + solrServer.commit(); // no specific result needed UpdateResponse result = new UpdateResponse(); @@ -284,15 +357,6 @@ } } - public List<Command> delete(WikittyTransaction transaction, - List<String> idList) throws WikittyException { - List<Command> result = new ArrayList<Command>(idList.size()); - for (String id : idList) { - result.add(new CommandSolr(id)); - } - return result; - } - public PagedResult<String> findAllByCriteria(Criteria criteria) { try { @@ -333,6 +397,7 @@ // Add faceting List<String> facetField = criteria.getFacetField(); + log.debug("facetField : " + facetField); List<Criteria> facetCriteria = criteria.getFacetCriteria(); // use to map query string to criteria facet name @@ -462,14 +527,15 @@ /** * Create all index document to used to modify indexation. * this method don't modify index - * @param w wikitty object to index + * @param wikitties all wikitties object to index * @return list of SolrInputDocument used to modify index */ protected SolrInputDocument createIndexDocument(Wikitty w) { log.debug("index wikitty " + w.getId()); SolrInputDocument doc = new SolrInputDocument(); - doc.addField(SOLR_ID, w.getId()); + String id = w.getId(); + doc.addField(SOLR_ID,id); for (String name : w.getExtensionNames()) { doc.addField(SOLR_EXTENSIONS, name); @@ -507,103 +573,97 @@ } } } - return doc; } /** - * Create a doc for each child for a tree node, his contains the path for - * the child. Update old doc when the node is moved and child is deleted. + * Create a doc between nodes and child */ - protected Collection<SolrInputDocument> createTreeNodeIndex( - WikittyTransaction transaction, Wikitty w) - throws IOException, SolrServerException { - - Collection<SolrInputDocument> result = new ArrayList<SolrInputDocument>(); - if(w.hasExtension(TreeNode.EXT_TREENODE)) { - String treeNodeId = w.getId(); - ParentMap parentMap = (ParentMap) transaction.getTagValue(ParentMap.class); + public SolrInputDocument createTreeNodeDocument(ParentMap parentMap, String childId) throws IOException, SolrServerException { + SolrInputDocument doc = new SolrInputDocument(); + doc.setField(SOLR_ID, TREENODE_PREFIX + childId); + doc.setField(TREENODE_CHILD, childId); - // Init new children with all children in node - List<String> children = w.getFieldAsList(TreeNode.EXT_TREENODE, - TreeNode.FIELD_CHILDREN, String.class); - List<String> newChildren = new ArrayList<String>(); - if(children != null) { - newChildren.addAll(children); - } + // Find all node contain child + SolrQuery query = new SolrQuery(SOLR_QUERY_PARSER + TreeNode.FQ_FIELD_CHILDREN + "_t:" + childId); + QueryResponse response = solrServer.query(query); + SolrDocumentList updateDocs = response.getResults(); - // Find old document to do diff - SolrDocument treeNodeDoc = findById(treeNodeId); - if(treeNodeDoc != null) { - Collection oldChildren = treeNodeDoc. - getFieldValues(TreeNode.FQ_FIELD_CHILDREN + "_t"); + List<String> paths = new ArrayList<String>(); + for (Iterator<SolrDocument> iterator = updateDocs.iterator(); + iterator.hasNext();) { + SolrDocument solrDocument = iterator.next(); - // Remove old children not in current node - List<String> removeChildren = new ArrayList<String>(); - if(oldChildren != null) { - removeChildren.addAll(oldChildren); - removeChildren.removeAll(children); - for (String removeChild : removeChildren) { - solrServer.deleteByQuery(TREENODE_CHILD + ":" + removeChild); - } + String treeNodeId = (String) solrDocument.getFieldValue(SOLR_ID); + doc.addField(TREENODE_PREFIX + treeNodeId, TREENODE_EMPTY); - // Remove old child in new children - newChildren.removeAll(oldChildren); + // Add path + String childParent = treeNodeId; + String parent = parentMap.get(childParent); + while (parent != null) { + if(!paths.contains(parent)) { + doc.addField(TREENODE_PREFIX + parent, childParent); + paths.add(parent); } - // Update path other node refer to current node - // FIXME jru 20091926 test change path - SolrQuery query = new SolrQuery(SOLR_QUERY_PARSER + TREENODE_PREFIX + treeNodeId + ":*"); - QueryResponse response = solrServer.query(query); - SolrDocumentList updateDocs = response.getResults(); - for (Iterator<SolrDocument> iterator = updateDocs.iterator(); iterator.hasNext();) { - SolrDocument solrDocument = iterator.next(); - String child = (String) solrDocument.getFieldValue(TreeNode.EXT_TREENODE + ".wikittyId"); - // Child is not deleted - if(!removeChildren.contains(child)) { - SolrInputDocument doc = createTreeNodeDocument(treeNodeId, child, parentMap); + childParent = parent; + parent = parentMap.get(childParent); + } + doc.addField(TREENODE_ROOT, childParent); + } + + return doc; + } - // Copy other field after node - String parent = TREENODE_PREFIX + treeNodeId; - String childParent = (String) solrDocument.getFieldValue(parent); - while (childParent != null) { - doc.setField(parent, childParent); - parent = TREENODE_PREFIX + childParent; - childParent = (String) solrDocument.getFieldValue(parent); - } - result.add(doc); - } + /** + * Update all document depend a deleted node in tree + */ + public void updateTreeNodeDocument(Map<String, SolrInputDocument> documents, String nodeId) throws SolrServerException { + SolrQuery query = new SolrQuery(SOLR_QUERY_PARSER + TREENODE_PREFIX + nodeId + ":*"); + QueryResponse response = solrServer.query(query); + SolrDocumentList updateDocs = response.getResults(); + + for (Iterator<SolrDocument> iterator = updateDocs.iterator(); iterator.hasNext();) { + SolrDocument solrDocument = iterator.next(); + + String documentId = (String) solrDocument.getFieldValue(SOLR_ID); + SolrInputDocument alreadyDone = documents.get(documentId); + + if (alreadyDone == null) { + SolrInputDocument doc = updateTreeNodeDocument(solrDocument, nodeId); + documents.put(documentId, doc); + } else { + // Copy other field after node + String parent = (String) alreadyDone.getFieldValue(TREENODE_PREFIX + nodeId); + if (parent != null) { + // Recreate doc a sub node is deleted + SolrInputDocument doc = updateTreeNodeDocument(solrDocument, nodeId); + documents.put(documentId, doc); } } - - // New children - for (String newChild : newChildren) { - SolrInputDocument doc = createTreeNodeDocument(treeNodeId, newChild, parentMap); - result.add(doc); - } - } - return result; } /** - * Create a doc between node and child + * Re-create a new document without node deleted, from age document */ - public SolrInputDocument createTreeNodeDocument(String treeNodeId, String child, ParentMap parentMap) { + public SolrInputDocument updateTreeNodeDocument(SolrDocument solrDocument, String nodeId) { + String documentId = (String) solrDocument.getFieldValue(SOLR_ID); + SolrInputDocument doc = new SolrInputDocument(); - doc.setField(SOLR_ID, TreeNode.EXT_TREENODE + "-" + treeNodeId + "-" + child); - doc.setField(TREENODE_CHILD, child); - doc.setField(TREENODE_PREFIX + treeNodeId, TREENODE_EMPTY); - - // Add path - String childParent = treeNodeId; - String parent = parentMap.get(childParent); - while (parent != null) { - doc.setField(TREENODE_PREFIX + parent, childParent); - childParent = parent; - parent = parentMap.get(childParent); + doc.setField(SOLR_ID, documentId); + doc.setField(TREENODE_CHILD, solrDocument.getFieldValue(TREENODE_CHILD)); + + // Copy other field after node + String parent = (String) solrDocument.getFieldValue(TREENODE_PREFIX + nodeId); + if (parent != null) { + String childParent = (String) solrDocument.getFieldValue(parent); + while (childParent != null) { + doc.setField(parent, childParent); + parent = TREENODE_PREFIX + childParent; + childParent = (String) solrDocument.getFieldValue(parent); + } } - doc.setField(TREENODE_ROOT, childParent); return doc; } Modified: wikengo_core-wikitty/wikengo_core-wikitty-solr-impl/src/main/resources/schema.xml =================================================================== --- wikengo_core-wikitty/wikengo_core-wikitty-solr-impl/src/main/resources/schema.xml 2009-11-10 16:30:58 UTC (rev 317) +++ wikengo_core-wikitty/wikengo_core-wikitty-solr-impl/src/main/resources/schema.xml 2009-11-10 16:31:10 UTC (rev 318) @@ -16,10 +16,10 @@ limitations under the License. --> -<!-- +<!-- This is the Solr schema file. This file should be named "schema.xml" and should be in the conf directory under the solr home - (i.e. ./solr/conf/schema.xml by default) + (i.e. ./solr/conf/schema.xml by default) or located where the classloader for the Solr webapp can find it. This example schema is the recommended starting point for users. @@ -46,7 +46,7 @@ org.apache.solr.analysis package. --> - <!-- The StrField type is not analyzed, but indexed/stored verbatim. + <!-- The StrField type is not analyzed, but indexed/stored verbatim. - StrField and TextField support an optional compressThreshold which limits compression (if enabled in the derived fields) to values which exceed a certain size (in characters). @@ -67,7 +67,7 @@ - If sortMissingLast="false" and sortMissingFirst="false" (the default), then default lucene sorting will be used which places docs without the field first in an ascending sort and last in a descending sort. - --> + --> <!-- numeric field types that store and index the text @@ -91,7 +91,7 @@ <!-- The format for this date field is of the form 1995-12-31T23:59:59Z, and is a more restricted form of the canonical representation of dateTime - http://www.w3.org/TR/xmlschema-2/#dateTime + http://www.w3.org/TR/xmlschema-2/#dateTime The trailing "Z" designates UTC time and is mandatory. Optional fractional seconds are allowed: 1995-12-31T23:59:59.999Z All other components are mandatory. @@ -106,7 +106,7 @@ NOW/DAY+6MONTHS+3DAYS ... 6 months and 3 days in the future from the start of the current day - + Consult the DateField javadocs for more information. --> <fieldType name="date" class="solr.DateField" sortMissingLast="true" omitNorms="true"/> @@ -114,11 +114,11 @@ <!-- The "RandomSortField" is not used to store or search any data. You can declare fields of this type it in your schema - to generate psuedo-random orderings of your docs for sorting - purposes. The ordering is generated based on the field name + to generate psuedo-random orderings of your docs for sorting + purposes. The ordering is generated based on the field name and the version of the index, As long as the index version remains unchanged, and the same field name is reused, - the ordering of the docs will be consistent. + the ordering of the docs will be consistent. If you want differend psuedo-random orderings of documents, for the same version of the index, use a dynamicField and change the name @@ -188,7 +188,7 @@ <filter class="solr.RemoveDuplicatesTokenFilterFactory"/> </analyzer> </fieldType> - + <fieldType name="text_core" class="solr.TextField" positionIncrementGap="100"> <analyzer> <tokenizer class="solr.WhitespaceTokenizerFactory" /> @@ -244,13 +244,13 @@ <filter class="solr.TrimFilterFactory" /> <!-- The PatternReplaceFilter gives you the flexibility to use Java Regular expression to replace any sequence of characters - matching a pattern with an arbitrary replacement string, + matching a pattern with an arbitrary replacement string, which may include back refrences to portions of the orriginal string matched by the pattern. - + See the Java Regular Expression documentation for more infomation on pattern and replacement string syntax. - + http://java.sun.com/j2se/1.5.0/docs/api/java/util/regex/package-summary.html --> <filter class="solr.PatternReplaceFilterFactory" @@ -259,50 +259,56 @@ </analyzer> </fieldType> - <!-- since fields of this type are by default not stored or indexed, any data added to - them will be ignored outright - --> - <fieldtype name="ignored" stored="false" indexed="false" class="solr.StrField" /> + <!-- since fields of this type are by default not stored or indexed, any data added to + them will be ignored outright + --> + <fieldtype name="ignored" stored="false" indexed="false" class="solr.StrField" /> </types> <fields> - <field name="id" type="string" indexed="true" stored="true" required="true" /> + <field name="id" type="string" indexed="true" stored="true" required="true" /> <field name="extensions" type="string" indexed="true" stored="false" multiValued="true"/> <!-- catchall field, containing all other searchable text fields (implemented via copyField further on in this schema --> <field name="text" type="text" indexed="true" stored="false" multiValued="true"/> + <copyField source="*_i" dest="text"/> + <copyField source="*_s" dest="text"/> + <copyField source="*_l" dest="text"/> + <copyField source="*_t" dest="text"/> + <copyField source="*_b" dest="text"/> + <copyField source="*_f" dest="text"/> + <copyField source="*_d" dest="text"/> + <copyField source="*_dt" dest="text"/> - <dynamicField name="Label.label*" type="text" indexed="true" stored="true" multiValued="true"/> - <dynamicField name="*_i" type="sint" indexed="true" stored="true" multiValued="true"/> - <dynamicField name="*_s" type="string" indexed="true" stored="true" multiValued="true"/> + <dynamicField name="*_s" type="text" indexed="true" stored="true" multiValued="true"/> <dynamicField name="*_l" type="slong" indexed="true" stored="true" multiValued="true"/> - <dynamicField name="*_t" type="string" indexed="true" stored="true" multiValued="true"/> + <dynamicField name="*_t" type="text" indexed="true" stored="true" multiValued="true"/> <dynamicField name="*_b" type="boolean" indexed="true" stored="true" multiValued="true"/> <dynamicField name="*_f" type="sfloat" indexed="true" stored="true" multiValued="true"/> <dynamicField name="*_d" type="sdouble" indexed="true" stored="true" multiValued="true"/> <dynamicField name="*_dt" type="date" indexed="true" stored="true" multiValued="true"/> <!-- all wikitty field --> - <dynamicField name="*" type="string" indexed="true" stored="true" multiValued="true"/> + <dynamicField name="*" type="text" indexed="true" stored="true" multiValued="true"/> <!-- copy fields for optimisation --> - <dynamicField name="_*" type="string" indexed="true" stored="true" multiValued="true"/> + <dynamicField name="_*" type="text" indexed="true" stored="true" multiValued="true"/> </fields> - <!-- Field to use to determine and enforce document uniqueness. + <!-- Field to use to determine and enforce document uniqueness. Unless this field is marked with required="false", it will be a required field --> <uniqueKey>id</uniqueKey> <!-- field for the QueryParser to use when an explicit fieldname is absent --> - <defaultSearchField>id</defaultSearchField> + <defaultSearchField>text</defaultSearchField> <!-- SolrQueryParser configuration: defaultOperator="AND|OR" --> - <solrQueryParser defaultOperator="OR"/> + <solrQueryParser defaultOperator="AND"/> -</schema> +</schema> \ No newline at end of file Modified: wikengo_core-wikitty/wikengo_core-wikitty-solr-impl/src/test/resources/log4j.properties =================================================================== --- wikengo_core-wikitty/wikengo_core-wikitty-solr-impl/src/test/resources/log4j.properties 2009-11-10 16:30:58 UTC (rev 317) +++ wikengo_core-wikitty/wikengo_core-wikitty-solr-impl/src/test/resources/log4j.properties 2009-11-10 16:31:10 UTC (rev 318) @@ -6,4 +6,4 @@ # Configuration by components log4j.rootLogger=ERROR, logConsole log4j.category.org.sharengo.wikitty=DEBUG -#log4j.category.org.apache.solr=DEBUG +log4j.category.org.apache.solr=DEBUG
participants (1)
-
kmorin@users.nuiton.org