dbTalk Databases Forums  

How to search the Indexing substring?

comp.databases.berkeley-db comp.databases.berkeley-db


Discuss How to search the Indexing substring? in the comp.databases.berkeley-db forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
hyungjun25@cnu.ac.kr
 
Posts: n/a

Default How to search the Indexing substring? - 01-21-2007 , 02:46 PM






Hi, I'm Studying Berkeley DB XML now.

I am trying to load 5000 xml docs of appr. All the same dtd.
system: 3GHz; 1.5 Gig memory.

Index Strategy is "node-element-substring-string"

----------------------------------------------------------------------------------------------------------------------------------

xml docment example>
<?xml version="1.0" encoding="utf-8" ?>

<dic>
<word>a</word>
<word>aaron</word>
<word>aback</word>
<word>abaissiez</word>
<word>abandon</word>
<word>abandoned</word>
<word>abase</word>
<word>abash</word>
<word>abashed</word>
<word>abate</word>
<word>abated</word>
<word>abatement</word>
<word>abatements</word>
<word>abates</word>
<word>abattement</word>
<word>abbe</word>
<word>abbess</word>
<word>abbey</word>
<word>abbeys</word>
<word>abbominable</word>
<word>abbot</word>
<word>abbots</word>
</dic>

----------------------------------------------------------------------------------------------------------------------------------

CreateContainer.java

// Example BDB XML Container Create

import com.sleepycat.db.*;
import com.sleepycat.dbxml.*;

public class CreateContainer
{
public static void main ( String[] args )
throws Exception {
XmlManager xmlManager = null;
XmlContainer xmlContainer = null;

try {
xmlManager = new XmlManager();
// set Container type
xmlManager.setDefaultContainerType(XmlContainer.No deContainer);
XmlContainerConfig containerConfig = new XmlContainerConfig();

containerConfig.setNodeContainer(true);
containerConfig.setIndexNodes(true);

xmlContainer =
xmlManager.createContainer("D:/Database/testBDBXML/BDBXMLContainerNode.dbxml",
containerConfig);

containerConfig = xmlContainer.getContainerConfig();

if(containerConfig.getNodeContainer()) System.out.println("Set Node
Container");
if(containerConfig.getIndexNodes()) System.out.println("Set Index
Node");

if(xmlManager.getDefaultContainerType() == 1)
System.out.println("This Container Type is Node Container");
}
finally {
try {
if ( xmlContainer != null ) xmlContainer.close();
if ( xmlManager != null ) xmlManager.close();
} catch ( XmlException ce ) {
// Exception handling
}
}
}
}

----------------------------------------------------------------------------------------------------------------------------------

AddIndex.java

import com.sleepycat.dbxml.*;

public class AddIndex {
public static void main (String[] args)
throws Exception
{
XmlManager xmlManager = null;
XmlContainer xmlContainer = null;

try {
xmlManager = new XmlManager();
xmlContainer =
xmlManager.openContainer("/Database/testBDBXML/BDBXMLContainerNode.dbxml");

XmlIndexSpecification indexSpec =
xmlContainer.getIndexSpecification();

/* int indexType = XmlIndexSpecification.UNIQUE_OFF |
XmlIndexSpecification.PATH_NODE |
XmlIndexSpecification.NODE_ELEMENT |
XmlIndexSpecification.KEY_SUBSTRING;
*/
int syntaxType = XmlValue.STRING;

indexSpec.addIndex("", "word", "node-element-substring-string");
// indexSpec.addIndex("", "word", indexType, syntaxType);

XmlUpdateContext uContext = xmlManager.createUpdateContext();
xmlContainer.setIndexSpecification(indexSpec, uContext);

System.out.println(xmlContainer.getIndexNodes());

} catch(XmlException e) {
e.printStackTrace();
// Error Handling
} finally {
try {
if(xmlContainer != null) {
xmlContainer.close();
}
if(xmlManager != null) {
xmlManager.close();
}
} catch(XmlException ce) {
// Exception handling
}
}
}
}

----------------------------------------------------------------------------------------------------------------------------------

IndexLooup.java

import com.sleepycat.dbxml.*;

public class IndexLookup {
public static void main (String[] args)
throws Exception
{
XmlManager xmlManager = null;
XmlContainer xmlContainer = null;

try {
xmlManager = new XmlManager();
xmlContainer =
xmlManager.openContainer("/Database/testBDBXML/BDBXMLContainerNode.dbxml");
XmlIndexSpecification is = xmlContainer.getIndexSpecification();
XmlIndexDeclaration idxDecl =null;
int count=0;
while((idxDecl =(is.next())) !=null){
System.out.println("For node '" + idxDecl.name + "', found index:
'" + idxDecl.index + "'.");
count++;
}
System.out.println(count+ " indices found.");

XmlQueryContext qContext = xmlManager.createQueryContext();


XmlIndexLookup xmlIndexLookup = null;
String idxStrategy = "node-element-substring-string";

XmlValue xValue = new XmlValue(XmlValue.STRING, "a");
int op = XmlIndexLookup.EQ;

xmlIndexLookup = xmlManager.createIndexLookup(xmlContainer, "",
"word", idxStrategy/* , xValue, op*/);
System.out.println(xmlIndexLookup.getIndex());

XmlResults res = xmlIndexLookup.execute(qContext);

XmlDocument theDoc = xmlManager.createDocument();

while(res.next(theDoc)) {
System.out.println(theDoc.getContentAsString());
}
} catch(XmlException e) {
e.printStackTrace();
// Error Handling
} finally {
try {
if(xmlContainer != null) {
xmlContainer.close();
}
if(xmlManager != null) {
xmlManager.close();
}
} catch(XmlException ce) {
// Exception handling
}
}
}
}

----------------------------------------------------------------------------------------------------------------------------------

XQuerytest1.java

// Example XQuery

import com.sleepycat.db.*;
import com.sleepycat.dbxml.*;

public class XQueryTest1
{
public static void main ( String[] args )
throws Exception
{
XmlManager xmlManager = null;
XmlContainer xmlContainer = null;

try {
xmlManager = new XmlManager();

// ÄÁÅ×ÀÌ³Ê ¿*±â
xmlContainer =
xmlManager.openContainer("/Database/testBDBXML/BDBXMLContainerNode.dbxml");

// Äõ¸®ÄÁÅØ½ºÆ® »ý¼º
XmlQueryContext context = xmlManager.createQueryContext();

// Äõ¸®¹®
String query = null;

//query = "for $x in
collection('/Database/testBDBXML/BDBXMLContainerNode.dbxml')/dic/word\n";
query = "for $x in
dbxml:lookup-index('/Database/testBDBXML/BDBXMLContainerNode.dbxml',
'word')";

query += "where $x/contains($x, 'able')";
//query += "where $x/starts-with($x, 'a')";
//query += "where matches($x, 'a')";
query += "return $x";

// XQuery Áغñ
XmlQueryExpression qe = xmlManager.prepare(query, context);

long a = java.lang.System.currentTimeMillis();

// XQuery ½ÇÇà ¹× °á°ú ¹Þ¾Æ¿À±â
XmlResults results = qe.execute(context);
// System.out.println(results.size());
long b = java.lang.System.currentTimeMillis();
System.out.println("Elapsed time is : " + (b-a));
//°á°ú¿¡¼* °ª ¾ò¾î¿À±â
XmlValue value = null;

/* while(results.hasNext()) {
System.out.println(results.peek().asString());
value = results.next();
}
*/
}
finally {
try {
if ( xmlContainer != null )
xmlContainer.close();
if ( xmlManager != null )
xmlManager.close();
} catch ( XmlException ce ) {
// Exception handling
}
}
}
}

----------------------------------------------------------------------------------------------------------------------------------

after "java IndexLookup" is no results.
why?

I am trying to do substring indexing. My listIndex looks like this:
"node-element-substring-string"

However, when I do a lookup on dbxml shell, I dun get any answer. I am
putting the node name also in my search
lookupIndex node-element-substring-string "" "word" "" "" "a"

However, it gives me no result. But, there is an entry which has the
text "a*".
Any ideas why isn't it working and how to make it work.

I don't have idea.
please help me.


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.