Search over all fields on Solr - search

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

Related

Why my code doesn't work to changing attributes on button odoo 15

i'm using odoo 15, and i want to change attributes button on stock.quant tree view editable. for code like this:
<xpath expr="//button[#name='action_apply_inventory']" position="attributes">
<attribute name="attrs">{'invisible': ['|', ('inventory_quantity_set', '=', False), ('is_approved', '=', False)]}</attribute>
<attribute name="groups">base.group_system,pitik_base_farm.group_finance_head</attribute>
<attribute name="string">Submit</attribute>
</xpath>
But this code doesn't work, not effect on view.
enter image description here
enter image description here
You are using is_approved field in domain of the invisible attrs but this field does not exist in the view. You need to add it to the view to be able to use it in the domain.
<record id="view_stock_quant_tree_inventory_editable_inherit_custom" model="ir.ui.view">
<field name="name">stock.quant.inventory.tree.editable.inherit.custom</field>
<field name="model">stock.quant</field>
<field name="inherit_id" ref="stock.view_stock_quant_tree_inventory_editable"/>
<field name="arch" type="xml">
<xpath expr="//field[#name='inventory_quantity_set']" position="after">
<field name="is_approved" invisible="1"/>
</xpath>
<xpath expr="//button[#name='action_apply_inventory']" position="attributes">
<attribute name="attrs">{'invisible': ['|', ('inventory_quantity_set', '=', False), ('is_approved', '=',
False)]}
</attribute>
<attribute name="groups">base.group_system,pitik_base_farm.group_finance_head</attribute>
<attribute name="string">Submit</attribute>
</xpath>
</field>
</record>

How to change string of Purchase Status(purchase_state) that is in Purchase Request? (ODOO)

So I want to change the string of "Purchase Order" inside Purchase Status(Inside Purchase Request) to something like "PO Created" when the purchase_state is in [purchase] but I don't know how I can do it. I want to create fresh module as well.
Here' s what I tried so far. I've created an XML and inherit the view.
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="purchase_request_form_inherit" model="ir.ui.view">
<field name="name">purchase.request.inherit</field>
<field name="model">purchase.request</field>
<field name="inherit_id" ref="purchase_request.view_purchase_request_form"/>
<field name="arch" type="xml">
<field name="purchase_state" position="attributes">
<attribute name="attrs" string="PO Created" attrs="{'readonly': [('po_line.state','=', 'purchase')]}"/>
</field>
</field>
</record>
</odoo>
I prefer use xpath:
<record id="purchase_request_form_inherit" model="ir.ui.view">
<field name="name">purchase.request.inherit</field>
<field name="model">purchase.request</field>
<field name="inherit_id" ref="purchase_request.view_purchase_request_form"/>
<field name="arch" type="xml">
<field expr="field[#name='purchase_state']" position="attributes">
<!-- To change the String -->
<attribute name="string">PO Created</attribute>
<!-- To change the attrs -->
<attribute name="attrs">{'readonly': [('po_line.state','=', 'purchase')]}</attribute>
</field>
</field>
</record>
I hope this answer could be helpful for you.

Odoo Inherit view can't set invisible attribute

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>

Why is Apache Solr not Returning any Results?

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":[]
}}

How to approach Solr schema for the first time

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

Resources