Joshil,

Yes, the @total attribute will return the *estimated* total number of documents 
(or fragments) that match the query, not the number of matching terms in the 
document.  The @total is a quick estimate:  it can only give as much 
information as can be resolved directly from indexes.  In some circumstances, 
like yours, it won’t match the number of <result> elements that are actually 
returned, because there isn’t enough information in the index to make the 
estimate completely accurate.

In your case, the searchable expression is the equivalent of saying:  find me 
<title> elements that contain “wine”  (without the searchable expression, you’d 
be saying “find me documents that contain “wine”).   Your document is indexed 
at the <root> level, not the <title> level.  So from the indexes, the sever 
knows that the document contains *at least one* <title> element that contains 
“wine”; that’s the best estimate it can make.  To be more accurate, the server 
has to do some filtering to really resolve whether it’s one, or more than one.  
In this case, it’s 2.  So your results are accurate (they’ve been through the 
filter) but the @total is not (it was just a quick, unfiltered estimate).

This is a fairly complicated topic:  I recommend taking a look at the section 
on “Fast Pagination and Unfiltered Search” in this guide:  
http://developer.marklogic.com/pubs/4.1/books/performance.pdf  for some hints 
on how things work under the covers.

--Colleen

From: [email protected] 
[mailto:[email protected]] On Behalf Of Joshil Avikkal
Sent: Thursday, August 06, 2009 10:48 AM
To: Joshil Avikkal; General Mark Logic Developer Discussion
Subject: RE: [MarkLogic Dev General] pagination using new search API

I forgot to add this… when I searched for “wine”, the  search returned 2 result 
elements but total shows ‘1’.    I have “searchable-expression” option set to 
“//title”.

--Joshil
________________________________
From: Joshil Avikkal
Sent: Thursday, August 06, 2009 1:40 PM
To: 'General Mark Logic Developer Discussion'
Subject: RE: [MarkLogic Dev General] pagination using new search API


It appears that the total attribute always returns me the number of documents 
not the total number of search result.   When searched for “wine” in below 
example, I got total=”1” when I was expecting total=” 2”.

Am I missing something?

--Joshil

________________________________
From: [email protected] 
[mailto:[email protected]] On Behalf Of Colleen Whitney
Sent: Thursday, August 06, 2009 1:23 PM
To: General Mark Logic Developer Discussion
Subject: RE: [MarkLogic Dev General] pagination using new search API

The total attribute in response gives you the estimated total number of results 
for the search.  The number of results actually contained in the response 
wrapper is controlled by page-length, which can be passed as an option or as an 
argument to search:search.  (In other words, search:search() paginates results.)

--Colleen

From: [email protected] 
[mailto:[email protected]] On Behalf Of Joshil Avikkal
Sent: Thursday, August 06, 2009 10:11 AM
To: Joshil Avikkal; General Mark Logic Developer Discussion
Subject: RE: [MarkLogic Dev General] pagination using new search API


Thanks Colleen.  This answers most of my questions. Which element or attribute 
in <response> or its child nodes to point out total number of <result> elements 
returned by the search?

--Joshil

________________________________
From: [email protected] 
[mailto:[email protected]] On Behalf Of Colleen Whitney
Sent: Thursday, August 06, 2009 12:36 PM
To: General Mark Logic Developer Discussion
Subject: RE: [MarkLogic Dev General] pagination using new search API

Hi Joshil,

I’m not sure I completely understand what you want to do, but here are a couple 
of ideas:

Each <result> that comes back from search:search represents a document or 
fragment in your database.  So if you have one sample document in your database 
(and it isn’t fragmented), then search:search(“wine”) will return just one 
<result> element.  Using <max-matches> only controls the number of matching 
nodes returned as part of the snippet;  it won’t change the number of <result> 
elements that are returned.

In order to restrict the search to terms in the <title> element, you need to 
construct an options node that defines a word constraint on the title element; 
that will allow you to write a search like:  search:search(“title:wine”) and 
get documents that have “wine” only in the title element.

The result element includes a document URI and path, so that you can access the 
document and use xpath on it to get the value of the <title> tag, which you can 
then display along with the snippet.  There is currently no way to include the 
value of the <title> element with your snippet (there is an RFE on file for 
that).

I’d like to recommend that you try going through the following tutorial, which 
gives you a hands-on tour of the Search API, including how to set up 
constraints and use some of the other basic features.  
http://developer.marklogic.com/howto/tutorials/2009-07-search-api-walkthrough.xqy

I hope this helps!

Regards,

--Colleen Whitney

From: [email protected] 
[mailto:[email protected]] On Behalf Of Joshil Avikkal
Sent: Thursday, August 06, 2009 7:55 AM
To: General Mark Logic Developer Discussion
Subject: RE: [MarkLogic Dev General] pagination using new search API

Hi,

I have an xml like follows and my database contains just one document with 
similar tags.

<Root>
<title>cook1
<Category count =”1” >wine and beer, wine and water </category
<Category count =”2” >this is a sample document </category>
</title>
<title>cook2
<Category count =”1” >party and cocktail</category>
<title>
<title>cook3
<Category count =”1” >wine</category>
</title>
</root>

I would like to use “search: search” function and get following the string term 
“wine”.    .

1.  Total number of the matches found in number of <title> tags.
     In this example, although the “wine” appears twice in the <title> “Cook1”, 
it should be counted as 1 and it should return only two search:result nodes. I 
set <max-matches> to 1 control this.
     But I need to find out how many such matches exist in entire document.  Is 
there way to find this out without traversing through the entire search:result ?

2.  Along with the search:snippet   I always want to display the  value of the 
<title> tag  inside with search:result along with search:snippet.  How can I do 
this ?


Thank you,
--Joshil

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



This message, including any attachments, contains confidential information 
intended for a specific individual and purpose, and is intended for the 
addressee only. Any unauthorized disclosure, use, dissemination, copying, or 
distribution of this message or any of its attachments or the information 
contained in this e-mail, or the taking of any action based on it, is strictly 
prohibited. If you are not the intended recipient, please notify the sender 
immediately by return e-mail and delete this message.



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



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



This message, including any attachments, contains confidential information

intended for a specific individual and purpose, and is intended for the 
addressee only. Any unauthorized disclosure, use, dissemination, copying, or 
distribution of

this message or any of its attachments or the information contained in this 
e-mail, or the taking of any action based on it, is strictly prohibited. If you 
are not the intended recipient, please notify the sender immediately by return 
e-mail and delete this message.



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



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



This message, including any attachments, contains confidential information 
intended for a specific individual and purpose, and is intended for the 
addressee only. Any unauthorized disclosure, use, dissemination, copying, or 
distribution of this message or any of its attachments or the information 
contained in this e-mail, or the taking of any action based on it, is strictly 
prohibited. If you are not the intended recipient, please notify the sender 
immediately by return e-mail and delete this message.



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



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



This message, including any attachments, contains confidential information 
intended for a specific individual and purpose, and is intended for the 
addressee only. Any unauthorized disclosure, use, dissemination, copying, or 
distribution of this message or any of its attachments or the information 
contained in this e-mail, or the taking of any action based on it, is strictly 
prohibited. If you are not the intended recipient, please notify the sender 
immediately by return e-mail and delete this message.



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


_______________________________________________
General mailing list
[email protected]
http://xqzone.com/mailman/listinfo/general

Reply via email to