I am trying to understand what is the best way to design my Solr Schema. and if there is a possibility to do it in a less complex way using solrJ.
I am currently working with solr's example server so i can understand how solr works.
if i understood correctly so far, the way to define the following schema:
Book= { title: String,
year: Int }
Author = { name: String,
books: [book] } <-- list/array of book objects
is to use CopyFields:
<fields>
<field name="name" type="string" indexed="true" stored="true" multiValued="false"/>
<field name="books" type="string" indexed="true" stored="false" multiValued="false"/>
<!-- books will contain: -->
<field name="title" type="string" indexed="true" stored="true" multiValued="true"/>
<field name="year" type="int" indexed="true" stored="true"/>
</fields>
<copyField source="title" dest="books"/>
<copyField source="year" dest="books"/>
was i correct?
if so, how do i upload a new author to my database?
i tried to upload form my node.js server using solr-client:
function ADDONE(){
var docs = [];
//generate 4 docs.
for(var i = 0; i <= 4 ; i++){
var doc = {
id : 20 + i ,
name : "Author"+i ,
books: [{title: "firstBook" , year: 1900+i} ,
{title: "SecondBook" , year: 1901+i} ]
}
docs.push(doc);
}
// Add documents to Solr
client.add(docs,function(err,obj){
if(err){
console.log(err);
}else{
console.log(obj);
}
});
}
ADDONE();
But this won't work. what is the correct way to define each document? am i even close?
the example i gave was written for node.js solr-client, but i prefer to use Java and it's solr Client (solrJ?).
I would also like to know how a contract a query for books form the years 1900 to 1910.
Thanks.
you can also use the dynamics fields
<fields>
<field name="name" type="string" indexed="true" stored="true" multiValued="false"/>
<field name="books" type="string" indexed="true" stored="false" multiValued="false"/>
<dynamicField name="books_year_*" type="string" indexed="true" stored="true" multiValued="false"/>
<dynamicField name="books_title_*" type="string" indexed="true" stored="true" multiValued="false"/>
<field name="book_title" type="string" indexed="true" stored="true" multiValued="true"/>
<copyField source="books_title_*" dest="book_title"/>
<field name="book_year" type="string" indexed="true" stored="true" multiValued="true"/>
<copyField source="books_year_*" dest="book_year"/>
</fields>
and with your method,
books: [{title: "firstBook" , year: 1900+i} =>
"books_title_"+i : firstBook
"books_year_"+i : 1900+i
Query:
select?q=book_year:"1970"
solr does not allow for structured objects.
If you want to do this, you must define entities.
For example, passing with Data Import Request Handler
http://wiki.apache.org/solr/DataImportHandler#Full_Import_Example
So you can have one entity for book and one entity for author
Related
I am odor newer.
I want to use the sale.order field and value to create a custom report by select some specific
field from sale.order.
I have created a custom model to inherit sale.order model.
And create a view to inherit view of sale.order.
Here is my code:
class SaleOrder(models.Model):
_inherit = 'sale.order'
<field name="name">Custom Sale Report</field>
<field name="res_model">sale.order</field>
<field name="view_mode">tree,form</field>
<field name="name">sale.order.inherited</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_tree" />
<field name="mode">primary</field>
<field name="arch" type="xml">
<xpath expr="//field[#name='name']" position="attributes">
<attribute name="invisible">1</attribute>
</xpath> </field> </record>
But I don't know why the invisible attribute is not working.
Please Help. Thanks.
Try this.
<field name="name">sale.order.inherited</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_tree" />
<field name="arch" type="xml">
<xpath expr="//field[#name='name']" position="replace">
<field name="name" optional="hide"/>
</xpath>
</field>
</record>
I'm trying to implement search over all fields on Solr. Exhttp://localhost:8983/solr/sample-items/select?q=oscar
but no result returns. However, If I specify the field it works fine Ex http://localhost:8983/solr/sample-items/select?q=name:oscar
I try to use copyField like following but not working:
on managed-schema file
<field name="Designation" type="text_general" stored="true"/>
<field name="Location" type="text_general" stored="true"/>
<field name="_root_" type="string" docValues="false" indexed="true" stored="true"/>
<field name="_version_" type="plong" indexed="false" stored="true"/>
<field name="age" type="plongs" stored="true"/>
<field name="id" type="string" multiValued="false" indexed="true" required="true" stored="true"/>
<field name="name" type="text_general" stored="true"/>
<field
name="_text_"
type="text_general"
indexed="true"
stored="true"
multiValued="true"
/>
.
.
.
<fields>
<copyField source="Designation" dest="_text_" maxChars="256"/>
<copyField source="name" dest="_text_" maxChars="256"/>
<copyField source="Location" dest="_text_" maxChars="256"/>
</fields>
on solrconfig.xml
file
<lst name="defaults">
<str name="echoParams">explicit</str>
<int name="rows">10</int>
</lst>
<initParams path="/update/**,/query,/select,/tvrh,/elevate,/spell,/browse">
<lst name="defaults">
<str name="df">_text_</str>
</lst>
</initParams>
Any advice?
To be able to search from >1 fields (or over all fields) by default , you need to perform following two configurations.
In schema file (e.g. managed_schema) create copy field and copy other field's data into this copy field. Example is as follows.
...
<field name="_text_" type="text_general" multiValued="true" indexed="true" stored="false"/>
...
<copyField source="directed_by" dest="_text_" maxChars="256"/>
<copyField source="genre" dest="_text_" maxChars="256"/>
...
In solrconfig.xml , update initiParam tag to make above created copy field as default search field for search handlers. Example is as follows.
<initParams path="/update/**,/query,/select,/tvrh,/elevate,/spell,/browse">
<lst name="defaults">
<str name="df">_text_</str>
</lst>
</initParams>
Sample Query and output :
ShubhangiP:~ spardeshi$ curl -XGET http://localhost:8983/solr/films/select?q=Gary
{
"responseHeader":{
"status":0,
"QTime":0,
"params":{
"q":"Gary"}},
"response":{"numFound":1,"start":0,"docs":[
{
"id":"/en/45_2006",
"directed_by":["Gary Lennon"],
"initial_release_date":"2006-11-30T00:00:00Z",
"genre":["Black comedy",
"Thriller",
"Psychological thriller",
"Indie film",
"Action Film",
"Crime Thriller",
"Crime Fiction",
"Drama"],
"name":".45",
"_version_":1645282402834055168}]
}}
From details provided in question, in managed_schema file collector field is used as copy field for three other fields named Designation , Name and Location.
But not sure if you made collector field as default search field.
You can also think of using the edismax query parser. Here the link for the same. the edismax query parser .Here you can provide the qf parameter. It provides you to boost hits in each field differently. For example qf=field1^4 field2 will give hits in the field1 field four times more weight than hits in the field2 field.
Search across multiple fields, specifying (via boosts) how important each field is relative each other:
http://localhost:8983/solr/techproducts/select?q=video&defType=edismax&qf=features^20.0+text^0.3
You can boost results that have a field that matches a specific value:
http://localhost:8983/solr/techproducts/select?q=video&defType=edismax&qf=features^20.0+text^0.3&bq=cat:electronics^5.0
After creating a Solr core named "test", I loaded in an XML file using the following:
bin\solr.cmd create -c test
java -jar -Dc=test -Dauto example\exampledocs\post.jar C:\Example\data.xml
Here are the contents of the file, data.xml.
data.xml
<add>
<doc>
<field name="field_name_1">Value One</field>
<field name="field_name_2">Value Two</field>
<field name="field_name_3">Value Three</field>
</doc>
<doc>
<field name="field_name_1">Value Four</field>
<field name="field_name_2">Value Five</field>
<field name="field_name_3">Value Six</field>
</doc>
<doc>
<field name="field_name_1">Value Seven</field>
<field name="field_name_2">Value Eight</field>
<field name="field_name_3">Value Nine</field>
</doc>
</add>
The following query does not return a result. Why is Solr not returning anything for this query?
http://localhost:8983/solr/test/select?q=Value
Result:
{
"responseHeader":{
"status":0,
"QTime":0,
"params":{
"q":"Value"}},
"response":{"numFound":0,"start":0,"docs":[]
}}
I have a problem querying an XML structure.
This is the document:
<?xml version="1.0" encoding="UTF-8"?>
<document>
<LangSet id="1031">
<field id="Language">1031</field>
<field id="PrimaryLanguage">7</field>
<Term id="18">
<field id="CreatedBy">dot_Termservice</field>
<field id="CreatedOn">20060905T170414Z</field>
<field id="CreatedOnUTC">20060905T150414Z</field>
<field id="CreatedOrUpdatedBy">dot_Termservice</field>
<field id="CreatedOrUpdatedOn">20080107T141350Z</field>
<field id="CreatedOrUpdatedOnUTC">20080107T121350Z</field>
<field id="Status">Negativterm.Kunden-orientiert;Negativterm.Technik-orientiert</field>
<field id="Term">Innenpersenning</field>
<field id="TermType">MainTerm</field>
<field id="UpdatedBy">dot_Termservice</field>
<field id="UpdatedOn">20080107T141350Z</field>
<field id="UpdatedOnUTC">20080107T121350Z</field>
<field id="UserId">11817</field>
</Term>
<Term id="19">
<field id="CreatedBy">dot_Termservice</field>
<field id="CreatedOn">20020626T120555Z</field>
<field id="CreatedOnUTC">20020626T100555Z</field>
<field id="CreatedOrUpdatedBy">dot_Termservice</field>
<field id="CreatedOrUpdatedOn">20020626T120555Z</field>
<field id="CreatedOrUpdatedOnUTC">20020626T100555Z</field>
<field id="Status">Vorzugsterm.Kunden-orientiert;Vorzugsterm.Technik-orientiert</field>
<field id="Term">Persenning</field>
<field id="TermType">MainTerm</field>
<field id="UserId">18088</field>
</Term>
<Term id="20">
<field id="CreatedBy">dot_Termservice</field>
<field id="CreatedOn">20011105T140407Z</field>
<field id="CreatedOnUTC">20011105T120407Z</field>
<field id="CreatedOrUpdatedBy">dot_Termservice</field>
<field id="CreatedOrUpdatedOn">20080107T141350Z</field>
<field id="CreatedOrUpdatedOnUTC">20080107T121350Z</field>
<field id="Status">Negativterm.Kunden-orientiert;Negativterm.Technik-orientiert</field>
<field id="Term">Verdeckabdeckung</field>
<field id="TermType">MainTerm</field>
<field id="UpdatedBy">dot_Termservice</field>
<field id="UpdatedOn">20080107T141350Z</field>
<field id="UpdatedOnUTC">20080107T121350Z</field>
<field id="UserId">32287</field>
</Term>
</LangSet>
<LangSet id="1031">
<field id="Language">1031</field>
<field id="PrimaryLanguage">7</field>
<Term id="8">
<field id="CreatedBy">dot_Termservice</field>
<field id="CreatedOn">20060905T170414Z</field>
<field id="CreatedOnUTC">20060905T150414Z</field>
<field id="CreatedOrUpdatedBy">dot_Termservice</field>
<field id="CreatedOrUpdatedOn">20070711T153241Z</field>
<field id="CreatedOrUpdatedOnUTC">20070711T133241Z</field>
<field id="Status">Vorzugsterm.Kunden-orientiert;Vorzugsterm.Technik-orientiert</field>
<field id="Term">Innenrad</field>
<field id="TermType">MainTerm</field>
<field id="UpdatedBy">dot_Termservice</field>
<field id="UpdatedOn">20070711T153241Z</field>
<field id="UpdatedOnUTC">20070711T133241Z</field>
<field id="UserId">11818</field>
</Term>
</LangSet>
</document>
All I want to do is to get all the Textvalues of the field elements with the attribute id=Term and return them in a LangSet as showned below:
<LangSet> <field id="Term">Innenpersenning</field> <field
id="Term">Persenning</field> <field id="Term">Verdeckabdeckung</field>
</LangSet>
<LangSet>
<field id="Term">Innenrad</field>
</LangSet>
<LangSet>
<field id="Term">Raumakustik</field>
</LangSet>
<LangSet>
<field id="Term">Fahrgastraumbeleuchtung</field> <field
id="Term">IB</field> <field id="Term">Innenbeleuchtung</field> <field
id="Term">Innenraumbeleuchtung</field>
</LangSet>
I'm getting the right values but unfortunatley not in a Langset node:
xquery version "1.0";
declare boundary-space strip;
declare namespace xs="http://www.w3.org/2001/XMLSchema";
for $x in doc("Sample.xml")/Document/Database/Dictionary/Concept/LangSet/Term//field
where $x/#id="Term"
return $x
I'm sure that it isn't that difficult but I'm stuck in documentation and I can't find the solution which works for me.
Thank you for any suggestions!
If you decide to return <LangSet> elements from your document, which contain appropriate <field> descendant elements, they will also contain all their other descendants.
If I understand what you want, you need to create on-the-fly some semi-clone elements reflecting partially your input document filtered and return them.
Scan LangSet-s and test each of them for desired descendants. If found, create appropriate output elements:
let $doc := doc("Sample.xml")
for $langset in $doc/document/LangSet
let $fields := $langset/descendant::field[#id = 'Term']
where exists($fields)
return
<LangSet>
{
for $field in $fields return
<field id='Term'>{string($field)}</field>
}
</LangSet>
You can solve this with an top-down approach like CiaPan's answer is or an bottom-up approach.
Based on the xml example you gave solutions could be:
Top-down
let $document := doc("langset.xml")/*
for $langset in $document/LangSet
let $fields := $langset//field[#id = 'Term']
return
<LangSet>
{ $fields }
</LangSet>
Bottom-up
let $document := doc("langset.xml")/*
for $field in $document//field[#id = 'Term']
group by $langset := $field/ancestor::LangSet
order by $langset descending
return
<LangSet>
{ $field }
</LangSet>
I want to add a cron job that runs at a specific time.
I have added the cron in xml but it has interval_number and interval_type. How to make it run at a specific time of day?
<record id="ir_cron_module_get_active_sr" model="ir.cron">
<field name="name">Get Active Srs</field>
<field eval="True" name="get_active_srs" />
<!--<field name="user_id" ref="base.user_root" />-->
<field name="interval_number">1</field>
<field name="interval_type">days</field>
<field name="numbercall">-1</field>
<field eval="False" name="doall" />
<field eval="'hr.attendance'" name="model" />
<field eval="'get_active_srs'" name="function" />
<field eval="'(None,)'" name="args" />
<field name="priority">1000</field>
</record>
try
<record id="ir_cron_module_get_active_sr" model="ir.cron">
<field name="name">Get Active Srs</field>
<field eval="True" name="get_active_srs" />
<!--<field name="user_id" ref="base.user_root" />-->
<field name="interval_number">1</field>
<field name="nextcall" eval="(DateTime.now() + timedelta(days=1)).strftime('%Y-%m-%d 12:00:00')" />
<field name="interval_type">days</field>
<field name="numbercall">-1</field>
<field eval="False" name="doall" />
<field eval="'hr.attendance'" name="model" />
<field eval="'get_active_srs'" name="function" />
<field eval="'(None,)'" name="args" />
<field name="priority">1000</field>
</record>