I'm using Lucene to search an index and it works fine. My only issue is that I only need one particular field of what is being returned. Can you specify to Lucene to only return a certain field in the results and not the entire document?
This is why FieldSelector class exists.
You can implement a class like this
class MyFieldSelector : FieldSelector
{
public FieldSelectorResult Accept(string fieldName)
{
if (fieldName == "field1") return FieldSelectorResult.LOAD_AND_BREAK;
return FieldSelectorResult.NO_LOAD;
}
}
and use it as indexReader.Document(docid,new MyFieldSelector());
If you are interested in loading a small field, this will prevent to load large fields which, in turn, means a speed-up in loading documents. I think you can find much more detailed info by some googling.
What do you mean "return certain fields"? The Document.get() function returns just the field you request.
Yes, you can definitely do what you are asking. All you have to do is include the field name (case-sensitive) in the document.get() method.
string fieldNameText = doc.Get("fieldName");
FYI, it's usually a good idea to include some code in your questions. It makes it easier to provide a good answer.
Related
Hy guys, i'm working on a IDEA plugin and custom references. I have many references working, but i'm stuck with a difficult one.
I'd like to detect patterns in groovy such as this one :
result = run service: 'createAgreementItem', with: createAgreementItemInMap
In the above line, i'd like to get the createAgreementItem element to match.
run is defined in a groovy base script
package org.apache.ofbiz.service.engine
abstract class GroovyBaseScript extends Script {
//...
Map run(Map args) throws ExecutionServiceException {
return runService((String)args.get('service'), (Map)args.get('with', new HashMap()))
}
//...
The problem is, what i'm trying to get isn't technically a parameter, it's a value from a map with the key equals to service.
So this won't work :
GroovyPatterns.groovyLiteralExpression()
.methodCallParameter(0,
GroovyPatterns.psiMethod().withName("run")
.definedInClass("org.apache.ofbiz.service.engine.GroovyBaseScript"))
Do you have any ideas or any help ? Thanks in advance !
EDIT :
Actually, i'm looking for a doc or an example for any use of the org.jetbrains.plugins.groovy.lang.psi.patterns.GroovyPatterns
library.
I don't get it, maybe i'm not familiar enough with groovy though i used it a bit.
Any help welcome on this.
The problem is, what i'm trying to get isn't technically a parameter,
it's a value from a map with the key equals to "service"
If all you want to do is retrieve the service value from the Map then instead of args.get('with', new HashMap()) you could do args.with.service. If you wanted null safety, you could do args?.with?.service.
I know pxformula could do it, but pxformula only accepts two argument parameters. how can i add (sum) multiple fields of the same DAC? can i nest it?
thanks. some working examples would be appreciated, some other methods would also be appreciated.
As suggested in another answer, PXFormula can be used to perform a multi field calculation. However, PXFormula always assigns calculated value to the field it decorates.
PXUnboundFormulaAttribute might be a better approach in case you don't need to store calculated value in any field:
[PXUnboundFormulaAttribute(typeof(Switch<Case<Where<GLTranDoc.debitAccountID, IsNotNull>, GLTranDoc.curyTranTotal>, Sub<GLTranDoc.curyTaxAmt, GLTranDoc.curyInclTaxAmt>>),
typeof(SumCalc<GLDocBatch.curyDebitTotal>))]
For additional examples on the PXUnboundFormulaAttribute, please check Example 7.3: Adding Conditional Calculation of Aggregated Values in the T200 developer class guide at Acumatica University or Acumatica Open University
I know this post is old, but I have been stuck on this for a while. I finally found a simple solution using [PXFormula] by nesting ADD's.
I had made a new grid screen and I wanted the final column to total all the other columns.
MY DAC’s :
one,two,three,four,five,six,seven,eight,nine,ten,eleven,twelve
The solution:
[PXFormula(typeof(Add<Add<Add<Add<Add<Add<one, two>,
Add<three, four>>, Add<five, six>>, Add<seven, eight>>,
Add<nine, ten>>, Add < eleven, twelve >>), typeof(SumCalc<total>))]
[PXDBDecimal()]
[PXUIField(DisplayName = "Total", Enabled = false)]
public virtual Decimal? Total { get; set; }
public abstract class total : PX.Data.BQL.BqlDecimal.Field<total> { }
If you do a code search on PXFormula you should find many examples. I usually search the code found in your site/App_data/CpdeRepository directory if you have access to a local site.
If you are looking to perform a multi field calculations, you nest your Add, Sub, Mult, Div, etc. calls.
Here are some examples from my search on "PXFormula" or "Mult<" or "Add<":
Found in ARTranRUTROT.CuryRUTROTTotal, this example will subtrack curyExtPrice from curyDiscAmt and add curyRUTROTTaxAmountDeductible (unless null use zero)
[PXFormula(typeof(Add<Sub<ARTran.curyExtPrice, ARTran.curyDiscAmt>,
IsNull<curyRUTROTTaxAmountDeductible, decimal0>>))]
Found in GLTaxTran.CuryExpenseAmt. This example again uses multiple fields in the calculation all nested.
[PXFormula(typeof(Mult<Mult<GLTaxTran.curyTaxableAmt,
Div<GLTaxTran.taxRate, decimal100>>, Sub<decimal1,
Div<GLTaxTran.nonDeductibleTaxRate, decimal100>>>), null)]
I need to perform a search on several entities with the same string then order the results.
I've heard/read a little about FOSElasticaBundle, would this bundle be able to do it? It seems (to me) to have almost to much features for this purpose and I'm not sure it could run on a shared server (hostgator).
The other solution I can think of at the moment is doing the search "manually" (by using join and union) but I'm wondering where should I put such a function: in an existing controller, a new one, a new bundle or somewhere else?
I'm worried as well that this manual solution could come to a cost, especially on some non-indexable fields.
You would do custom entity repositories. Check out the docs. Basically this extends the default FindAll, FindOneBy, etc.
You would have a function like so:
class MyEntityRepository extends Doctrine\ORM\EntityRepository {
public function findByCustomRule(){
//this is mapped to your entity (automatically adds the select)
$queryBuilder = $this->createQueryBuilder('someAlias');
$queryBuilder->orderBy('...');
//this is mapped to any entity
$queryBuilder = $this->getEntityManager()->createQueryBuilder();
$queryBuilder->select('...');
//result
$result = $queryBuilder->getQuery()->getResult();
}
}
This class is defined in the doctrine mapping and lives inside the Entity folder.. Check the docs out and you should get a basic idea.
I'm using db4o with groovy (actually griffon). I'm saving dozen of objects into db4o objectSet and see that .yarv file size is about 11Mb. I've checked its content and found that it stores metaClass with all nested fields into every object. It's a waste of space.
Looking for the way to avoid storing of metaClass and therefore reduce the size of result .yarv file, since I'm going to use db4o to store millions of entities.
Should I try callConstructors(true) db4o configuration? Think it would help?
Any help would be highly appreciated.
As an alternative you can just store 'Groovy'-beans instances. Those are compiled down to regular Java-ish classes with no special Groovy specific code attached to them.
Just like this:
class Customer {
// properties
Integer id
String name
Address address
}
class Address{
String street;
}
def customer = new Customer(id:1, name:"Gromit", address:new Address(street:"Fun"))
I don't know groovy but based on your description every groovy object carries metadata and you want to skip storing these objects.
If that is the case installing a "null translator" (TNull class) will cause the "translated" objects to not be stored.
PS: Call Constructor configuration has no effect on what gets stored in the db; it only affects how objects are instantiated when reading from db.
Hope this helps
I need to query a table using FreeTextTable (because I need ranking), with SubSonic. AFAIK, Subsonic doesn't support FullText, so I ended up creating a simple UDF function (Table Function) which takes 2 params (keywords to search and max number of results).
Now, how can I inner join the main table with this FreeTextTable?
InlineQuery is not an option.
Example:
table ARTICLE with fields Id, ArticleName, Author, ArticleStatus.
The search can be done by one of more of the following fields: ArticleName (fulltext), Author (another FullText but with different search keywords), ArticleStatus (an int).
Actually the query is far more complex and has other joins (depending on user choice).
If SubSonic cannot handle this situation, probably the best solution is good old plain sql (so there would be no need to create an UDF, too).
Thanks for your help
ps: will SubSonic 3.0 handle this situation?
3.0 can do this for you but you'd need to make a template for it since we don't handle functions (yet) out of the box. I'll be working on this in the coming weeks - for now I don't think 2.2 will do this for you.
I realize your question is more complex than this, but you can get results from a table valued function via SubSonic 2.2 with a little massaging.
Copy the .cs file from one of your generated views into a safe folder, and then change all the properties to match the columns returned by your UDF.
Then, on your collection, add a constructor method with your parameters and have it execute an InlineQuery.
public partial class UDFSearchCollection
{
public UDFSearchCollection(){}
public UDFSearchCollection(string keyword, int maxResults)
{
UDFSearchCollection coll = new InlineQuery().ExecuteAsCollection<UDFSearchCollection>("select resultID, resultColumn from dbo.udfSearch(#keyword, #maxResults)",keyword,maxResults);
coll.CopyTo(this);
coll = null;
}
}
public partial class UDFSearch : ReadOnlyRecord<UDFSearch>, IReadOnlyRecord
{
//all the methods for read only record go here
...
}
An inner join would be a little more difficult because the table object doesn't have it's own parameters collection. But it could...