private XFacetedQuery XML2Query(Document doc) { try { Node node = null; NamedNodeMap map = null; node = doc.getElementsByTagName("action").item(0); map = node.getAttributes(); // create XFacetedQuery node = doc.getElementsByTagName("targetNode").item(0); map = node.getAttributes(); int target = new Integer(map.getNamedItem("index").getNodeValue()).intValue(); CatRelGraph graph = schemaFactory.createCatRelGraph(); node = doc.getElementsByTagName("queryNode").item(0); graph.add(createGeneralCategory(node)); // System.out.println("name="+node.getNodeName()); addRelations(graph, 0, node.getChildNodes()); System.out.println(graph); System.out.println("target=" + target); XFacetedQuery query = searchFactory.createXFacetedQuery(); query.setSearchTarget(target); query.setQueryConstraint(graph); query.setResultSpec(searchFactory.createXFacetedResultSpec()); return query; } catch (Exception ex) { ex.printStackTrace(); } return null; }
protected SchemaObjectInfo getInfo(IndexReader indexReader, int docID) throws IOException { FieldType[] fields = new FieldType[] { FieldType.ID, FieldType.URI, FieldType.LABEL, FieldType.SUMMARY, FieldType.TEXT }; String[] values = indexReader.getFieldValues(docID, fields); return schemaFactory.createSchemaObjectInfo( Long.valueOf(values[0]), values[1], values[2], values[3], values[4]); }
private GeneralCategory createGeneralCategory(Node node) throws NoSuchAlgorithmException, DOMException { NamedNodeMap map = node.getAttributes(); CompoundCategory cat = schemaFactory.createCompoundCategory(CompoundCategory.TYPE_AND); Node n = map.getNamedItem("instanceConstraint"); if (n != null && !n.getNodeValue().equals("")) { cat.addComponentCategory( schemaFactory .createEnumerationCategory() .addInstanceElement(schemaFactory.createInstance(n.getNodeValue()))); return cat; } n = map.getNamedItem("conceptConstraint"); if (n != null && !n.getNodeValue().equals("")) { cat.addComponentCategory(schemaFactory.createCategory(n.getNodeValue())); } n = map.getNamedItem("keyword"); if (n != null && !n.getNodeValue().equals("")) { cat.addComponentCategory(schemaFactory.createKeywordCategory(n.getNodeValue())); } return cat; }
private void addRelations(CatRelGraph graph, int fromNodeIndex, NodeList nodes) throws NoSuchAlgorithmException, DOMException { if (nodes == null) return; for (int i = 0; i < nodes.getLength(); i++) { Node node = nodes.item(i); if (node.getNodeName().equals("#text")) continue; // System.out.println("name="+node.getNodeName()); graph.add(createGeneralCategory(node)); int toNodeIndex = graph.numOfNodes() - 1; NamedNodeMap map = node.getAttributes(); if (map.getNamedItem("inverse").getNodeValue().equals("0")) { graph.add( schemaFactory.createRelation(map.getNamedItem("relation").getNodeValue()), fromNodeIndex, toNodeIndex); } else { graph.add( schemaFactory.createRelation(map.getNamedItem("relation").getNodeValue()), toNodeIndex, fromNodeIndex); } addRelations(graph, toNodeIndex, node.getChildNodes()); } }