2014-03-25 66 views
1

我是MarkLogic的新手,我試圖使用搜索API從文檔中提取信息。我的文檔格式如下。Marklogic REST API - 從文檔中提取數據

<nitf> 
<head> 
<title>ABC</title> 
</head> 
... 
... 
</nitf> 

我想只顯示在結果匹配搜索查詢的文檔的標題,即搜索API必須只返回匹配文檔的標題。我已經通過文檔並嘗試了一些不同的東西,比如@ehennum建議的查詢選項,但沒有任何效果。任何對此的幫助都會很大。謝謝!

回答

4

克里希納,這聽起來像你不想片段可言,所以你應該turn off snippeting

<search:transform-results apply="empty-snippet"/> 

然後拿到冠軍,用extract-metadata

<search:extract-metadata> 
    <search:qname elem-ns="" elem-name="title"/> 
</search:extract-metadata> 
+0

感謝戴夫的回答。這適用於我! –

2

作爲腳註戴夫的建議很好,MarkLogic 7提供了Query By Example作爲簡單的搜索界面。請參閱:

http://docs.marklogic.com/REST/POST/v1/qbe

http://docs.marklogic.com/guide/search-dev/qbe#id_54044

的特定查詢看起來像以下:

<q:qbe xmlns:q="http://marklogic.com/appservices/querybyexample"> 
    <q:query> 
    ... your query by example ... 
    </q:query> 
    <q:response> 
    <q:snippet><q:none/></q:snippet> 
    <q:extract><title/></q:extract> 
    </q:response> 
</q:qbe> 

如果我沒有記錯,NITF不使用名稱空間,但如果它確實,你必須用前綴限定標題。

+0

謝謝埃裏克。我現在正在探索QBE界面。 –

0

要在精細答案擴大自@戴夫 - 卡塞爾,因爲MarkLogic版本8中,<search:extract-metadata>選項已被廢棄,你應該使用search:extract-document-data替代 - 直接從API文檔解禁:

<search:extract-document-data selected="include"> 
    <search:extract-path xmlns="">/userName</search:extract-path> 
</search:extract-document-data> 

更多: https://docs.marklogic.com/search:search#opt-extract-document-data