Two different documents in my database (with default index setup) contains title like below
first document:-
<title>Reconceptualizing Subject</title>
second document:-
<title>Reconceptualizing Subject (LP)</title>
I have created word constraint on title for search in the title
<constraint name="title">
<word>
<element ns="" name="title"/>
<term-option>case-insensitive</term-option>
</word>
</constraint>
so if I query search:search("title:Reconceptualizing Subject") then I am getting both document as a result from database but if I query search:search("title:Reconceptualizing Subject (LP)") it gives me only single document result.
How can I achieve exact search (single document) when I query "title:Reconceptualizing Subject" ?
Change your search constraint to:
<constraint name="title">
<value>
<element ns="" name="title"/>
<term-option>case-insensitive</term-option>
</value>
</constraint>
And then double-quote your search string:
search:search(' title:"Reconceptualizing Subject" ')
HTH!
Related
Use version:4.5.0
db/system/config/db/test/collection.xconf The code is as follows:
<range>
<create qname="item">
<condition attribute="name" value="number"/>
<field name="number" match="#value" type="xs:decimal"/>
</create>
<create qname="item">
<condition attribute="name" value="acreage"/>
<field name="acreage" match="#value" type="xs:decimal"/>
</create>
<create qname="item">
<condition attribute="name" value="radii"/>
<field name="radii" match="#value" type="xs:decimal"/>
</create>
<create qname="item">
<condition attribute="name" value="diameter"/>
<field name="diameter" match="#value" type="xs:decimal"/>
</create>
</range>
Browse Indexes
db/test The code of an XML file is as follows:
<root>
<item name="number" value="4"/>
<item name="acreage" value="5"/>
<item name="radii" value="6"/>
<item name="diameter" value="7"/> </root>
Query statement:
//item[#name='radii'][#value>5.0]
Query Profiling
No result
In theory, the XML file can be found, but the result can not be found for what? Can you help me? Thank you!
Based on the documentation for eXist's Conditional Combined Indexes feature you are trying to use here, it appears to me that this feature only support string comparisons (with an optional "numeric" mode). See https://exist-db.org/exist/apps/doc/newrangeindex#D3.21.18. In other words, your #type="xs:decimal" is not resulting in your attributes' values being cast to xs:decimal; effectively, instead, they are being indexed as xs:string.
Thus, for your query to work with the given data, change the predicate to [#value gt "5"].
Or, to force numeric comparisons, add numeric="yes" to the <field> element in your index definitions, and then change your predicate to [#value gt "5.0"].
<record>
<field>
<fieldName>employee id</fieldName>
<fieldValue>2000001</fieldValue>
</field>
<field>
<fieldName>employee name</fieldName>
<fieldValue>pankaj kumar</fieldValue>
</field>
</record>
The data extracted should be like this:
employee id | employee name
2000001 | pankaj kumar
CREATE TABLE houses(
HOUSE_ID NUMBER(4),
house_add XMLTYPE,
HOUSE_NAME VARCHAR2(35)
);
Inserting the value in the table;
INSERT INTO houses VALUES
(100, XMLType('<house whNo="100">
<Building>Owned</Building>
</house>'), 'housename1');
To fech :-
SELECT house_add FROM HOUSES W;
o/p:-<house whNo="100"> <BUILDING>OWNED</BUILDING> </house>
To fetch Building detail:-
SELECT
w.house_add.extract('/house/Building/text()').getStringVal() "Building"
FROM HOUSES W;
o/p:-Owned
For your case:-
WITH T AS
(select xmltype('<?xml version = "1.0"?>
<record>
<FIELD>
<Field Name="employee id" fieldValue="2000001"/>
</FIELD>
<FIELD>
<Field Name="employee name" fieldValue="pankajkumar"/>
</FIELD>
</record>
') XML FROM DUAL
)
SELECT Y.NAME, Y.VALUE
FROM T ,
XMLTABLE('/record/FIELD/Field'
PASSING T.XML
COLUMNS NAME VARCHAR2(20) PATH '#Name',
VALUE VARCHAR2(20) PATH '#fieldValue'
)Y
output:-
NAme Value
employee id 2000001
employee name pankajkumar
This will help you !!
For my model with the following fields:
name = fields.Char()
date = fields.Date()
value1 = fields.Float()
value2 = fields.Float()
I am trying to show multiple lines in the same graph this way:
<graph string="Results" type="line">
<field name="date" type="row" interval="day"/>
<field name="value1" type="measure" operator="+"/>
<field name="value2" type="measure" operator="+"/>
</graph>
But it shows only one line. Every time I have to select the measure I want to see and deselect the other, while I need to see both at the same time.
The only way I was able to show the two values separately at the same time, is through a bar graph grouped by name field, but it is not what I need (I still had to show only one measure but at least I could achieve to have different colors for each group).
Any ideas?
I did it:
<graph string="Results" type="line">
<field name="date" type="row" interval="day"/>
<field name="name" type="col"/>
<field name="value1" type="measure" operator="+"/>
</graph>
I just need to put all values into value1 and separate them by using name, obtaining different lines with same name
Say, I have 5 documents that belong to either of different collections such as:
Biography, Fiction, Humour, Adventure
For instance, document 1 is in Adventure Collection:
<Book>
<title>Harry Potter and the Deathly Hallows</title>
<Author>J.K.Rowling</Author>
<year>2007</year>
</Book>
document 2, is in Biography Collection:
<Book>
<title>Steve Jobs</title>
<Author>Walter Issacson</Author>
<year>2011</year>
</Book>
Now I want to apply suggest on year element. I want to apply this on collections i.e. for example-suggest on Biography collections
I have defined element range index on year and ingested sample documents using application loader and configured collections for documents in document settings.
Follwing is my XQUERY code:
xquery version "1.0-ml";
import module namespace search = "http://marklogic.com/appservices/search"
at "/MarkLogic/appservices/search/search.xqy";
let $options :=
<options xmlns="http://marklogic.com/appservices/search">
<constraint name="Group">
<collection prefix="Biography/"/>
</constraint>
<suggestion-source ref="Group">
<range collation="http://marklogic.com/collation/"
type="xs:string" >
<element name="year"/>
</range>
</suggestion-source>
</options>
return
search:suggest("Group:20", $options)
On running this query I am getting suggestions for both 2011 and 2007 which is not what I am expecting.
Expected suggestion is 2011 (as only Biography collection should be searched).
I have refered this doc on search:suggest but I am not able to find out what exactly is the mistake.
Where am I doing wrong?
Shrey:
The values from the suggestion source are substituted for the values from the referenced constraint. In other words, the options say that input qualified by the group constraint should come from the year range index, which is what you're seeing. For more detail, please see:
http://docs.marklogic.com/guide/search-dev/search-api#id_40748
To filter a set of suggestions, you can call search:suggest() with two string queries. The first provides the input for the suggestions. The second provides the filtering constraint. In the case above, the filtering constraint would be the Biography collection. For more detail, please see:
http://docs.marklogic.com/guide/search-dev/search-api#id_91911
Hoping that helps
However, I am able to achieve the required output using additional-query in options as follows:
xquery version "1.0-ml";
import module namespace search = "http://marklogic.com/appservices/search"
at "/MarkLogic/appservices/search/search.xqy";
let $options :=
<options xmlns="http://marklogic.com/appservices/search">
<additional-query>{cts:collection-query("Biography")}
</additional-query>
<constraint name="Search_Element">
<range collation="http://marklogic.com/collation/"
type="xs:string" >
<element name="year"/>
</range>
</constraint>
<suggestion-source ref="Search_Element">
<range collation="http://marklogic.com/collation/"
type="xs:string" >
<element name="year"/>
</range>
</suggestion-source>
</options>
return
search:suggest("Search_Element:20", $options)
Still, I was wondering how could it be done without using additional-query paramater because it would be more optimized to use collection constraint for above.
I was trying to read data of concerned columns from XML given below and load into database.
My XML is like below:
<questions>
<question>
<Field name="id">12</Field>
<Field name="lid">10</Field>
<Field name="text">Hello</Field>
</question>
</questions>
I have table with columns id,lid and text , i want to load data from above xml into database. Try to use OpenXML but in vain.not able to read attribute.
I was using below query.
DECLARE #doc AS INT
EXEC Sp_xml_preparedocument
#doc OUTPUT,
#queueData
INSERT INTO dbo.Questions
([Id],[Lid],[Text])
SELECT * FROM OPENXML(#doc, '/questions/question/Field', 1)
WITH ( id VARCHAR(20),
lid VARCHAR(20) ,
text VARCHAR(MAX))
i want to load data from above xml into database. Try to use OpenXML but in vain.not able to read attribute.
ANY Help appreciated!!
Thank you!!
Try this.
declare #xml xml = '
<questions>
<question>
<Field name="id">12</Field>
<Field name="lid">10</Field>
<Field name="text">Hello</Field>
</question>
</questions>
'
select N.value('(Field[#name="id"])[1]', 'varchar(20)'),
N.value('(Field[#name="lid"])[1]', 'varchar(20)'),
N.value('(Field[#name="text"])[1]', 'varchar(max)')
from #xml.nodes('/questions/question') as T(N)
Read more about it here: http://msdn.microsoft.com/en-us/library/ms190798.aspx